]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.8.3-201303142235.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.3-201303142235.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index b89a739..b47493f 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,12 @@ series
176 setup
177 setup.bin
178 setup.elf
179 +signing_key*
180 +size_overflow_hash.h
181 sImage
182 +slabinfo
183 sm_tbl*
184 +sortextable
185 split-include
186 syscalltab.h
187 tables.c
188 @@ -224,6 +253,7 @@ tftpboot.img
189 timeconst.h
190 times.h*
191 trix_boot.h
192 +user_constants.h
193 utsrelease.h*
194 vdso-syms.lds
195 vdso.lds
196 @@ -235,13 +265,17 @@ vdso32.lds
197 vdso32.so.dbg
198 vdso64.lds
199 vdso64.so.dbg
200 +vdsox32.lds
201 +vdsox32-syms.lds
202 version.h*
203 vmImage
204 vmlinux
205 vmlinux-*
206 vmlinux.aout
207 vmlinux.bin.all
208 +vmlinux.bin.bz2
209 vmlinux.lds
210 +vmlinux.relocs
211 vmlinuz
212 voffset.h
213 vsyscall.lds
214 @@ -249,9 +283,12 @@ vsyscall_32.lds
215 wanxlfw.inc
216 uImage
217 unifdef
218 +utsrelease.h
219 wakeup.bin
220 wakeup.elf
221 wakeup.lds
222 +x509*
223 zImage*
224 zconf.hash.c
225 +zconf.lex.c
226 zoffset.h
227 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
228 index 986614d..e8bfedc 100644
229 --- a/Documentation/kernel-parameters.txt
230 +++ b/Documentation/kernel-parameters.txt
231 @@ -922,6 +922,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
232 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
233 Default: 1024
234
235 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
236 + ignore grsecurity's /proc restrictions
237 +
238 +
239 hashdist= [KNL,NUMA] Large hashes allocated during boot
240 are distributed across NUMA nodes. Defaults on
241 for 64-bit NUMA, off otherwise.
242 @@ -2121,6 +2125,18 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
243 the specified number of seconds. This is to be used if
244 your oopses keep scrolling off the screen.
245
246 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
247 + virtualization environments that don't cope well with the
248 + expand down segment used by UDEREF on X86-32 or the frequent
249 + page table updates on X86-64.
250 +
251 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
252 +
253 + pax_extra_latent_entropy
254 + Enable a very simple form of latent entropy extraction
255 + from the first 4GB of memory as the bootmem allocator
256 + passes the memory pages to the buddy allocator.
257 +
258 pcbit= [HW,ISDN]
259
260 pcd. [PARIDE]
261 diff --git a/Makefile b/Makefile
262 index 8c49fc9b..9a2af09 100644
263 --- a/Makefile
264 +++ b/Makefile
265 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
266
267 HOSTCC = gcc
268 HOSTCXX = g++
269 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
270 -HOSTCXXFLAGS = -O2
271 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
272 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
273 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
274
275 # Decide whether to build built-in, modular, or both.
276 # Normally, just do built-in.
277 @@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
278 # Rules shared between *config targets and build targets
279
280 # Basic helpers built in scripts/
281 -PHONY += scripts_basic
282 -scripts_basic:
283 +PHONY += scripts_basic gcc-plugins
284 +scripts_basic: gcc-plugins
285 $(Q)$(MAKE) $(build)=scripts/basic
286 $(Q)rm -f .tmp_quiet_recordmcount
287
288 @@ -575,6 +576,62 @@ else
289 KBUILD_CFLAGS += -O2
290 endif
291
292 +ifndef DISABLE_PAX_PLUGINS
293 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
294 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
295 +else
296 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
297 +endif
298 +ifneq ($(PLUGINCC),)
299 +ifndef CONFIG_UML
300 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
301 +endif
302 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
303 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
304 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
305 +endif
306 +ifdef CONFIG_KALLOCSTAT_PLUGIN
307 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
308 +endif
309 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
310 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
311 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
312 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
313 +endif
314 +ifdef CONFIG_CHECKER_PLUGIN
315 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
316 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
317 +endif
318 +endif
319 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
320 +ifdef CONFIG_PAX_SIZE_OVERFLOW
321 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
322 +endif
323 +ifdef CONFIG_PAX_LATENT_ENTROPY
324 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
325 +endif
326 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
327 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
328 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
329 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
330 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
331 +ifeq ($(KBUILD_EXTMOD),)
332 +gcc-plugins:
333 + $(Q)$(MAKE) $(build)=tools/gcc
334 +else
335 +gcc-plugins: ;
336 +endif
337 +else
338 +gcc-plugins:
339 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
340 + $(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.))
341 +else
342 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
343 +endif
344 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
345 +endif
346 +endif
347 +
348 include $(srctree)/arch/$(SRCARCH)/Makefile
349
350 ifdef CONFIG_READABLE_ASM
351 @@ -731,7 +788,7 @@ export mod_sign_cmd
352
353
354 ifeq ($(KBUILD_EXTMOD),)
355 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
356 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
357
358 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
359 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
360 @@ -778,6 +835,8 @@ endif
361
362 # The actual objects are generated when descending,
363 # make sure no implicit rule kicks in
364 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
365 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
366 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
367
368 # Handle descending into subdirectories listed in $(vmlinux-dirs)
369 @@ -787,7 +846,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
370 # Error messages still appears in the original language
371
372 PHONY += $(vmlinux-dirs)
373 -$(vmlinux-dirs): prepare scripts
374 +$(vmlinux-dirs): gcc-plugins prepare scripts
375 $(Q)$(MAKE) $(build)=$@
376
377 # Store (new) KERNELRELASE string in include/config/kernel.release
378 @@ -831,6 +890,7 @@ prepare0: archprepare FORCE
379 $(Q)$(MAKE) $(build)=.
380
381 # All the preparing..
382 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
383 prepare: prepare0
384
385 # Generate some files
386 @@ -938,6 +998,8 @@ all: modules
387 # using awk while concatenating to the final file.
388
389 PHONY += modules
390 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
391 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
392 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
393 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
394 @$(kecho) ' Building modules, stage 2.';
395 @@ -953,7 +1015,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
396
397 # Target to prepare building external modules
398 PHONY += modules_prepare
399 -modules_prepare: prepare scripts
400 +modules_prepare: gcc-plugins prepare scripts
401
402 # Target to install modules
403 PHONY += modules_install
404 @@ -1019,7 +1081,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
405 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
406 signing_key.priv signing_key.x509 x509.genkey \
407 extra_certificates signing_key.x509.keyid \
408 - signing_key.x509.signer
409 + signing_key.x509.signer tools/gcc/size_overflow_hash.h
410
411 # clean - Delete most, but leave enough to build external modules
412 #
413 @@ -1059,6 +1121,7 @@ distclean: mrproper
414 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
415 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
416 -o -name '.*.rej' \
417 + -o -name '.*.rej' -o -name '*.so' \
418 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
419 -type f -print | xargs rm -f
420
421 @@ -1219,6 +1282,8 @@ PHONY += $(module-dirs) modules
422 $(module-dirs): crmodverdir $(objtree)/Module.symvers
423 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
424
425 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 modules: $(module-dirs)
428 @$(kecho) ' Building modules, stage 2.';
429 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
430 @@ -1355,17 +1420,21 @@ else
431 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
432 endif
433
434 -%.s: %.c prepare scripts FORCE
435 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
436 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
437 +%.s: %.c gcc-plugins prepare scripts FORCE
438 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
439 %.i: %.c prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 -%.o: %.c prepare scripts FORCE
442 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
443 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
444 +%.o: %.c gcc-plugins prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 %.lst: %.c prepare scripts FORCE
447 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
448 -%.s: %.S prepare scripts FORCE
449 +%.s: %.S gcc-plugins prepare scripts FORCE
450 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
451 -%.o: %.S prepare scripts FORCE
452 +%.o: %.S gcc-plugins prepare scripts FORCE
453 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
454 %.symtypes: %.c prepare scripts FORCE
455 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
456 @@ -1375,11 +1444,15 @@ endif
457 $(cmd_crmodverdir)
458 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
459 $(build)=$(build-dir)
460 -%/: prepare scripts FORCE
461 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
462 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
463 +%/: gcc-plugins prepare scripts FORCE
464 $(cmd_crmodverdir)
465 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
466 $(build)=$(build-dir)
467 -%.ko: prepare scripts FORCE
468 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
469 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
470 +%.ko: gcc-plugins prepare scripts FORCE
471 $(cmd_crmodverdir)
472 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
473 $(build)=$(build-dir) $(@:.ko=.o)
474 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
475 index c2cbe4f..f7264b4 100644
476 --- a/arch/alpha/include/asm/atomic.h
477 +++ b/arch/alpha/include/asm/atomic.h
478 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
479 #define atomic_dec(v) atomic_sub(1,(v))
480 #define atomic64_dec(v) atomic64_sub(1,(v))
481
482 +#define atomic64_read_unchecked(v) atomic64_read(v)
483 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
484 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
485 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
486 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
487 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
488 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
489 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
490 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
491 +
492 #define smp_mb__before_atomic_dec() smp_mb()
493 #define smp_mb__after_atomic_dec() smp_mb()
494 #define smp_mb__before_atomic_inc() smp_mb()
495 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
496 index ad368a9..fbe0f25 100644
497 --- a/arch/alpha/include/asm/cache.h
498 +++ b/arch/alpha/include/asm/cache.h
499 @@ -4,19 +4,19 @@
500 #ifndef __ARCH_ALPHA_CACHE_H
501 #define __ARCH_ALPHA_CACHE_H
502
503 +#include <linux/const.h>
504
505 /* Bytes per L1 (data) cache line. */
506 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
507 -# define L1_CACHE_BYTES 64
508 # define L1_CACHE_SHIFT 6
509 #else
510 /* Both EV4 and EV5 are write-through, read-allocate,
511 direct-mapped, physical.
512 */
513 -# define L1_CACHE_BYTES 32
514 # define L1_CACHE_SHIFT 5
515 #endif
516
517 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
518 #define SMP_CACHE_BYTES L1_CACHE_BYTES
519
520 #endif
521 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
522 index 968d999..d36b2df 100644
523 --- a/arch/alpha/include/asm/elf.h
524 +++ b/arch/alpha/include/asm/elf.h
525 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
526
527 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
528
529 +#ifdef CONFIG_PAX_ASLR
530 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
531 +
532 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
533 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
534 +#endif
535 +
536 /* $0 is set by ld.so to a pointer to a function which might be
537 registered using atexit. This provides a mean for the dynamic
538 linker to call DT_FINI functions for shared libraries that have
539 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
540 index bc2a0da..8ad11ee 100644
541 --- a/arch/alpha/include/asm/pgalloc.h
542 +++ b/arch/alpha/include/asm/pgalloc.h
543 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
544 pgd_set(pgd, pmd);
545 }
546
547 +static inline void
548 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
549 +{
550 + pgd_populate(mm, pgd, pmd);
551 +}
552 +
553 extern pgd_t *pgd_alloc(struct mm_struct *mm);
554
555 static inline void
556 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
557 index 81a4342..348b927 100644
558 --- a/arch/alpha/include/asm/pgtable.h
559 +++ b/arch/alpha/include/asm/pgtable.h
560 @@ -102,6 +102,17 @@ struct vm_area_struct;
561 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
562 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
563 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
564 +
565 +#ifdef CONFIG_PAX_PAGEEXEC
566 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
567 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
568 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
569 +#else
570 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
571 +# define PAGE_COPY_NOEXEC PAGE_COPY
572 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
573 +#endif
574 +
575 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
576
577 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
578 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
579 index 2fd00b7..cfd5069 100644
580 --- a/arch/alpha/kernel/module.c
581 +++ b/arch/alpha/kernel/module.c
582 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
583
584 /* The small sections were sorted to the end of the segment.
585 The following should definitely cover them. */
586 - gp = (u64)me->module_core + me->core_size - 0x8000;
587 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
588 got = sechdrs[me->arch.gotsecindex].sh_addr;
589
590 for (i = 0; i < n; i++) {
591 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
592 index 14db93e..47bed62 100644
593 --- a/arch/alpha/kernel/osf_sys.c
594 +++ b/arch/alpha/kernel/osf_sys.c
595 @@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
596 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
597
598 static unsigned long
599 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
600 - unsigned long limit)
601 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
602 + unsigned long limit, unsigned long flags)
603 {
604 struct vm_area_struct *vma = find_vma(current->mm, addr);
605 -
606 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
607 while (1) {
608 /* At this point: (!vma || addr < vma->vm_end). */
609 if (limit - len < addr)
610 return -ENOMEM;
611 - if (!vma || addr + len <= vma->vm_start)
612 + if (check_heap_stack_gap(vma, addr, len, offset))
613 return addr;
614 addr = vma->vm_end;
615 vma = vma->vm_next;
616 @@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
617 merely specific addresses, but regions of memory -- perhaps
618 this feature should be incorporated into all ports? */
619
620 +#ifdef CONFIG_PAX_RANDMMAP
621 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
622 +#endif
623 +
624 if (addr) {
625 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
626 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
627 if (addr != (unsigned long) -ENOMEM)
628 return addr;
629 }
630
631 /* Next, try allocating at TASK_UNMAPPED_BASE. */
632 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
633 - len, limit);
634 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
635 +
636 if (addr != (unsigned long) -ENOMEM)
637 return addr;
638
639 /* Finally, try allocating in low memory. */
640 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
641 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
642
643 return addr;
644 }
645 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
646 index 0c4132d..88f0d53 100644
647 --- a/arch/alpha/mm/fault.c
648 +++ b/arch/alpha/mm/fault.c
649 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
650 __reload_thread(pcb);
651 }
652
653 +#ifdef CONFIG_PAX_PAGEEXEC
654 +/*
655 + * PaX: decide what to do with offenders (regs->pc = fault address)
656 + *
657 + * returns 1 when task should be killed
658 + * 2 when patched PLT trampoline was detected
659 + * 3 when unpatched PLT trampoline was detected
660 + */
661 +static int pax_handle_fetch_fault(struct pt_regs *regs)
662 +{
663 +
664 +#ifdef CONFIG_PAX_EMUPLT
665 + int err;
666 +
667 + do { /* PaX: patched PLT emulation #1 */
668 + unsigned int ldah, ldq, jmp;
669 +
670 + err = get_user(ldah, (unsigned int *)regs->pc);
671 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
672 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
673 +
674 + if (err)
675 + break;
676 +
677 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
678 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
679 + jmp == 0x6BFB0000U)
680 + {
681 + unsigned long r27, addr;
682 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
683 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
684 +
685 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
686 + err = get_user(r27, (unsigned long *)addr);
687 + if (err)
688 + break;
689 +
690 + regs->r27 = r27;
691 + regs->pc = r27;
692 + return 2;
693 + }
694 + } while (0);
695 +
696 + do { /* PaX: patched PLT emulation #2 */
697 + unsigned int ldah, lda, br;
698 +
699 + err = get_user(ldah, (unsigned int *)regs->pc);
700 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
701 + err |= get_user(br, (unsigned int *)(regs->pc+8));
702 +
703 + if (err)
704 + break;
705 +
706 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
707 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
708 + (br & 0xFFE00000U) == 0xC3E00000U)
709 + {
710 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
711 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
712 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
713 +
714 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
715 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
716 + return 2;
717 + }
718 + } while (0);
719 +
720 + do { /* PaX: unpatched PLT emulation */
721 + unsigned int br;
722 +
723 + err = get_user(br, (unsigned int *)regs->pc);
724 +
725 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
726 + unsigned int br2, ldq, nop, jmp;
727 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
728 +
729 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
730 + err = get_user(br2, (unsigned int *)addr);
731 + err |= get_user(ldq, (unsigned int *)(addr+4));
732 + err |= get_user(nop, (unsigned int *)(addr+8));
733 + err |= get_user(jmp, (unsigned int *)(addr+12));
734 + err |= get_user(resolver, (unsigned long *)(addr+16));
735 +
736 + if (err)
737 + break;
738 +
739 + if (br2 == 0xC3600000U &&
740 + ldq == 0xA77B000CU &&
741 + nop == 0x47FF041FU &&
742 + jmp == 0x6B7B0000U)
743 + {
744 + regs->r28 = regs->pc+4;
745 + regs->r27 = addr+16;
746 + regs->pc = resolver;
747 + return 3;
748 + }
749 + }
750 + } while (0);
751 +#endif
752 +
753 + return 1;
754 +}
755 +
756 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
757 +{
758 + unsigned long i;
759 +
760 + printk(KERN_ERR "PAX: bytes at PC: ");
761 + for (i = 0; i < 5; i++) {
762 + unsigned int c;
763 + if (get_user(c, (unsigned int *)pc+i))
764 + printk(KERN_CONT "???????? ");
765 + else
766 + printk(KERN_CONT "%08x ", c);
767 + }
768 + printk("\n");
769 +}
770 +#endif
771
772 /*
773 * This routine handles page faults. It determines the address,
774 @@ -133,8 +251,29 @@ retry:
775 good_area:
776 si_code = SEGV_ACCERR;
777 if (cause < 0) {
778 - if (!(vma->vm_flags & VM_EXEC))
779 + if (!(vma->vm_flags & VM_EXEC)) {
780 +
781 +#ifdef CONFIG_PAX_PAGEEXEC
782 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
783 + goto bad_area;
784 +
785 + up_read(&mm->mmap_sem);
786 + switch (pax_handle_fetch_fault(regs)) {
787 +
788 +#ifdef CONFIG_PAX_EMUPLT
789 + case 2:
790 + case 3:
791 + return;
792 +#endif
793 +
794 + }
795 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
796 + do_group_exit(SIGKILL);
797 +#else
798 goto bad_area;
799 +#endif
800 +
801 + }
802 } else if (!cause) {
803 /* Allow reads even for write-only mappings */
804 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
805 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
806 index 67874b8..0e40765 100644
807 --- a/arch/arm/Kconfig
808 +++ b/arch/arm/Kconfig
809 @@ -1813,7 +1813,7 @@ config ALIGNMENT_TRAP
810
811 config UACCESS_WITH_MEMCPY
812 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
813 - depends on MMU
814 + depends on MMU && !PAX_MEMORY_UDEREF
815 default y if CPU_FEROCEON
816 help
817 Implement faster copy_to_user and clear_user methods for CPU
818 diff --git a/arch/arm/common/gic.c b/arch/arm/common/gic.c
819 index 87dfa902..3a523fc 100644
820 --- a/arch/arm/common/gic.c
821 +++ b/arch/arm/common/gic.c
822 @@ -81,7 +81,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
823 * Supported arch specific GIC irq extension.
824 * Default make them NULL.
825 */
826 -struct irq_chip gic_arch_extn = {
827 +irq_chip_no_const gic_arch_extn __read_only = {
828 .irq_eoi = NULL,
829 .irq_mask = NULL,
830 .irq_unmask = NULL,
831 @@ -329,7 +329,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
832 chained_irq_exit(chip, desc);
833 }
834
835 -static struct irq_chip gic_chip = {
836 +static irq_chip_no_const gic_chip __read_only = {
837 .name = "GIC",
838 .irq_mask = gic_mask_irq,
839 .irq_unmask = gic_unmask_irq,
840 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
841 index c79f61f..9ac0642 100644
842 --- a/arch/arm/include/asm/atomic.h
843 +++ b/arch/arm/include/asm/atomic.h
844 @@ -17,17 +17,35 @@
845 #include <asm/barrier.h>
846 #include <asm/cmpxchg.h>
847
848 +#ifdef CONFIG_GENERIC_ATOMIC64
849 +#include <asm-generic/atomic64.h>
850 +#endif
851 +
852 #define ATOMIC_INIT(i) { (i) }
853
854 #ifdef __KERNEL__
855
856 +#define _ASM_EXTABLE(from, to) \
857 +" .pushsection __ex_table,\"a\"\n"\
858 +" .align 3\n" \
859 +" .long " #from ", " #to"\n" \
860 +" .popsection"
861 +
862 /*
863 * On ARM, ordinary assignment (str instruction) doesn't clear the local
864 * strex/ldrex monitor on some implementations. The reason we can use it for
865 * atomic_set() is the clrex or dummy strex done on every exception return.
866 */
867 #define atomic_read(v) (*(volatile int *)&(v)->counter)
868 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
869 +{
870 + return v->counter;
871 +}
872 #define atomic_set(v,i) (((v)->counter) = (i))
873 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
874 +{
875 + v->counter = i;
876 +}
877
878 #if __LINUX_ARM_ARCH__ >= 6
879
880 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
881 int result;
882
883 __asm__ __volatile__("@ atomic_add\n"
884 +"1: ldrex %1, [%3]\n"
885 +" adds %0, %1, %4\n"
886 +
887 +#ifdef CONFIG_PAX_REFCOUNT
888 +" bvc 3f\n"
889 +"2: bkpt 0xf103\n"
890 +"3:\n"
891 +#endif
892 +
893 +" strex %1, %0, [%3]\n"
894 +" teq %1, #0\n"
895 +" bne 1b"
896 +
897 +#ifdef CONFIG_PAX_REFCOUNT
898 +"\n4:\n"
899 + _ASM_EXTABLE(2b, 4b)
900 +#endif
901 +
902 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
903 + : "r" (&v->counter), "Ir" (i)
904 + : "cc");
905 +}
906 +
907 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
908 +{
909 + unsigned long tmp;
910 + int result;
911 +
912 + __asm__ __volatile__("@ atomic_add_unchecked\n"
913 "1: ldrex %0, [%3]\n"
914 " add %0, %0, %4\n"
915 " strex %1, %0, [%3]\n"
916 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
917 smp_mb();
918
919 __asm__ __volatile__("@ atomic_add_return\n"
920 +"1: ldrex %1, [%3]\n"
921 +" adds %0, %1, %4\n"
922 +
923 +#ifdef CONFIG_PAX_REFCOUNT
924 +" bvc 3f\n"
925 +" mov %0, %1\n"
926 +"2: bkpt 0xf103\n"
927 +"3:\n"
928 +#endif
929 +
930 +" strex %1, %0, [%3]\n"
931 +" teq %1, #0\n"
932 +" bne 1b"
933 +
934 +#ifdef CONFIG_PAX_REFCOUNT
935 +"\n4:\n"
936 + _ASM_EXTABLE(2b, 4b)
937 +#endif
938 +
939 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
940 + : "r" (&v->counter), "Ir" (i)
941 + : "cc");
942 +
943 + smp_mb();
944 +
945 + return result;
946 +}
947 +
948 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
949 +{
950 + unsigned long tmp;
951 + int result;
952 +
953 + smp_mb();
954 +
955 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
956 "1: ldrex %0, [%3]\n"
957 " add %0, %0, %4\n"
958 " strex %1, %0, [%3]\n"
959 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
960 int result;
961
962 __asm__ __volatile__("@ atomic_sub\n"
963 +"1: ldrex %1, [%3]\n"
964 +" subs %0, %1, %4\n"
965 +
966 +#ifdef CONFIG_PAX_REFCOUNT
967 +" bvc 3f\n"
968 +"2: bkpt 0xf103\n"
969 +"3:\n"
970 +#endif
971 +
972 +" strex %1, %0, [%3]\n"
973 +" teq %1, #0\n"
974 +" bne 1b"
975 +
976 +#ifdef CONFIG_PAX_REFCOUNT
977 +"\n4:\n"
978 + _ASM_EXTABLE(2b, 4b)
979 +#endif
980 +
981 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
982 + : "r" (&v->counter), "Ir" (i)
983 + : "cc");
984 +}
985 +
986 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
987 +{
988 + unsigned long tmp;
989 + int result;
990 +
991 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
992 "1: ldrex %0, [%3]\n"
993 " sub %0, %0, %4\n"
994 " strex %1, %0, [%3]\n"
995 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
996 smp_mb();
997
998 __asm__ __volatile__("@ atomic_sub_return\n"
999 -"1: ldrex %0, [%3]\n"
1000 -" sub %0, %0, %4\n"
1001 +"1: ldrex %1, [%3]\n"
1002 +" subs %0, %1, %4\n"
1003 +
1004 +#ifdef CONFIG_PAX_REFCOUNT
1005 +" bvc 3f\n"
1006 +" mov %0, %1\n"
1007 +"2: bkpt 0xf103\n"
1008 +"3:\n"
1009 +#endif
1010 +
1011 " strex %1, %0, [%3]\n"
1012 " teq %1, #0\n"
1013 " bne 1b"
1014 +
1015 +#ifdef CONFIG_PAX_REFCOUNT
1016 +"\n4:\n"
1017 + _ASM_EXTABLE(2b, 4b)
1018 +#endif
1019 +
1020 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1021 : "r" (&v->counter), "Ir" (i)
1022 : "cc");
1023 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1024 return oldval;
1025 }
1026
1027 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1028 +{
1029 + unsigned long oldval, res;
1030 +
1031 + smp_mb();
1032 +
1033 + do {
1034 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1035 + "ldrex %1, [%3]\n"
1036 + "mov %0, #0\n"
1037 + "teq %1, %4\n"
1038 + "strexeq %0, %5, [%3]\n"
1039 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1040 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1041 + : "cc");
1042 + } while (res);
1043 +
1044 + smp_mb();
1045 +
1046 + return oldval;
1047 +}
1048 +
1049 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1050 {
1051 unsigned long tmp, tmp2;
1052 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1053
1054 return val;
1055 }
1056 +
1057 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1058 +{
1059 + return atomic_add_return(i, v);
1060 +}
1061 +
1062 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1063 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1064 +{
1065 + (void) atomic_add_return(i, v);
1066 +}
1067
1068 static inline int atomic_sub_return(int i, atomic_t *v)
1069 {
1070 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1071 return val;
1072 }
1073 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1074 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1075 +{
1076 + (void) atomic_sub_return(i, v);
1077 +}
1078
1079 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1080 {
1081 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1082 return ret;
1083 }
1084
1085 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1086 +{
1087 + return atomic_cmpxchg(v, old, new);
1088 +}
1089 +
1090 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1091 {
1092 unsigned long flags;
1093 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1094 #endif /* __LINUX_ARM_ARCH__ */
1095
1096 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1097 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1098 +{
1099 + return xchg(&v->counter, new);
1100 +}
1101
1102 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1103 {
1104 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1105 }
1106
1107 #define atomic_inc(v) atomic_add(1, v)
1108 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1109 +{
1110 + atomic_add_unchecked(1, v);
1111 +}
1112 #define atomic_dec(v) atomic_sub(1, v)
1113 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1114 +{
1115 + atomic_sub_unchecked(1, v);
1116 +}
1117
1118 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1119 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1120 +{
1121 + return atomic_add_return_unchecked(1, v) == 0;
1122 +}
1123 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1124 #define atomic_inc_return(v) (atomic_add_return(1, v))
1125 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1126 +{
1127 + return atomic_add_return_unchecked(1, v);
1128 +}
1129 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1130 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1131
1132 @@ -241,6 +428,14 @@ typedef struct {
1133 u64 __aligned(8) counter;
1134 } atomic64_t;
1135
1136 +#ifdef CONFIG_PAX_REFCOUNT
1137 +typedef struct {
1138 + u64 __aligned(8) counter;
1139 +} atomic64_unchecked_t;
1140 +#else
1141 +typedef atomic64_t atomic64_unchecked_t;
1142 +#endif
1143 +
1144 #define ATOMIC64_INIT(i) { (i) }
1145
1146 static inline u64 atomic64_read(const atomic64_t *v)
1147 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1148 return result;
1149 }
1150
1151 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1152 +{
1153 + u64 result;
1154 +
1155 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1156 +" ldrexd %0, %H0, [%1]"
1157 + : "=&r" (result)
1158 + : "r" (&v->counter), "Qo" (v->counter)
1159 + );
1160 +
1161 + return result;
1162 +}
1163 +
1164 static inline void atomic64_set(atomic64_t *v, u64 i)
1165 {
1166 u64 tmp;
1167 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1168 : "cc");
1169 }
1170
1171 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1172 +{
1173 + u64 tmp;
1174 +
1175 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1176 +"1: ldrexd %0, %H0, [%2]\n"
1177 +" strexd %0, %3, %H3, [%2]\n"
1178 +" teq %0, #0\n"
1179 +" bne 1b"
1180 + : "=&r" (tmp), "=Qo" (v->counter)
1181 + : "r" (&v->counter), "r" (i)
1182 + : "cc");
1183 +}
1184 +
1185 static inline void atomic64_add(u64 i, atomic64_t *v)
1186 {
1187 u64 result;
1188 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1189 __asm__ __volatile__("@ atomic64_add\n"
1190 "1: ldrexd %0, %H0, [%3]\n"
1191 " adds %0, %0, %4\n"
1192 +" adcs %H0, %H0, %H4\n"
1193 +
1194 +#ifdef CONFIG_PAX_REFCOUNT
1195 +" bvc 3f\n"
1196 +"2: bkpt 0xf103\n"
1197 +"3:\n"
1198 +#endif
1199 +
1200 +" strexd %1, %0, %H0, [%3]\n"
1201 +" teq %1, #0\n"
1202 +" bne 1b"
1203 +
1204 +#ifdef CONFIG_PAX_REFCOUNT
1205 +"\n4:\n"
1206 + _ASM_EXTABLE(2b, 4b)
1207 +#endif
1208 +
1209 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1210 + : "r" (&v->counter), "r" (i)
1211 + : "cc");
1212 +}
1213 +
1214 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1215 +{
1216 + u64 result;
1217 + unsigned long tmp;
1218 +
1219 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1220 +"1: ldrexd %0, %H0, [%3]\n"
1221 +" adds %0, %0, %4\n"
1222 " adc %H0, %H0, %H4\n"
1223 " strexd %1, %0, %H0, [%3]\n"
1224 " teq %1, #0\n"
1225 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1226
1227 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1228 {
1229 - u64 result;
1230 - unsigned long tmp;
1231 + u64 result, tmp;
1232
1233 smp_mb();
1234
1235 __asm__ __volatile__("@ atomic64_add_return\n"
1236 +"1: ldrexd %1, %H1, [%3]\n"
1237 +" adds %0, %1, %4\n"
1238 +" adcs %H0, %H1, %H4\n"
1239 +
1240 +#ifdef CONFIG_PAX_REFCOUNT
1241 +" bvc 3f\n"
1242 +" mov %0, %1\n"
1243 +" mov %H0, %H1\n"
1244 +"2: bkpt 0xf103\n"
1245 +"3:\n"
1246 +#endif
1247 +
1248 +" strexd %1, %0, %H0, [%3]\n"
1249 +" teq %1, #0\n"
1250 +" bne 1b"
1251 +
1252 +#ifdef CONFIG_PAX_REFCOUNT
1253 +"\n4:\n"
1254 + _ASM_EXTABLE(2b, 4b)
1255 +#endif
1256 +
1257 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1258 + : "r" (&v->counter), "r" (i)
1259 + : "cc");
1260 +
1261 + smp_mb();
1262 +
1263 + return result;
1264 +}
1265 +
1266 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1267 +{
1268 + u64 result;
1269 + unsigned long tmp;
1270 +
1271 + smp_mb();
1272 +
1273 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1274 "1: ldrexd %0, %H0, [%3]\n"
1275 " adds %0, %0, %4\n"
1276 " adc %H0, %H0, %H4\n"
1277 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1278 __asm__ __volatile__("@ atomic64_sub\n"
1279 "1: ldrexd %0, %H0, [%3]\n"
1280 " subs %0, %0, %4\n"
1281 +" sbcs %H0, %H0, %H4\n"
1282 +
1283 +#ifdef CONFIG_PAX_REFCOUNT
1284 +" bvc 3f\n"
1285 +"2: bkpt 0xf103\n"
1286 +"3:\n"
1287 +#endif
1288 +
1289 +" strexd %1, %0, %H0, [%3]\n"
1290 +" teq %1, #0\n"
1291 +" bne 1b"
1292 +
1293 +#ifdef CONFIG_PAX_REFCOUNT
1294 +"\n4:\n"
1295 + _ASM_EXTABLE(2b, 4b)
1296 +#endif
1297 +
1298 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1299 + : "r" (&v->counter), "r" (i)
1300 + : "cc");
1301 +}
1302 +
1303 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1304 +{
1305 + u64 result;
1306 + unsigned long tmp;
1307 +
1308 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1309 +"1: ldrexd %0, %H0, [%3]\n"
1310 +" subs %0, %0, %4\n"
1311 " sbc %H0, %H0, %H4\n"
1312 " strexd %1, %0, %H0, [%3]\n"
1313 " teq %1, #0\n"
1314 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1315
1316 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1317 {
1318 - u64 result;
1319 - unsigned long tmp;
1320 + u64 result, tmp;
1321
1322 smp_mb();
1323
1324 __asm__ __volatile__("@ atomic64_sub_return\n"
1325 -"1: ldrexd %0, %H0, [%3]\n"
1326 -" subs %0, %0, %4\n"
1327 -" sbc %H0, %H0, %H4\n"
1328 +"1: ldrexd %1, %H1, [%3]\n"
1329 +" subs %0, %1, %4\n"
1330 +" sbcs %H0, %H1, %H4\n"
1331 +
1332 +#ifdef CONFIG_PAX_REFCOUNT
1333 +" bvc 3f\n"
1334 +" mov %0, %1\n"
1335 +" mov %H0, %H1\n"
1336 +"2: bkpt 0xf103\n"
1337 +"3:\n"
1338 +#endif
1339 +
1340 " strexd %1, %0, %H0, [%3]\n"
1341 " teq %1, #0\n"
1342 " bne 1b"
1343 +
1344 +#ifdef CONFIG_PAX_REFCOUNT
1345 +"\n4:\n"
1346 + _ASM_EXTABLE(2b, 4b)
1347 +#endif
1348 +
1349 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1350 : "r" (&v->counter), "r" (i)
1351 : "cc");
1352 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1353 return oldval;
1354 }
1355
1356 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1357 +{
1358 + u64 oldval;
1359 + unsigned long res;
1360 +
1361 + smp_mb();
1362 +
1363 + do {
1364 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1365 + "ldrexd %1, %H1, [%3]\n"
1366 + "mov %0, #0\n"
1367 + "teq %1, %4\n"
1368 + "teqeq %H1, %H4\n"
1369 + "strexdeq %0, %5, %H5, [%3]"
1370 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1371 + : "r" (&ptr->counter), "r" (old), "r" (new)
1372 + : "cc");
1373 + } while (res);
1374 +
1375 + smp_mb();
1376 +
1377 + return oldval;
1378 +}
1379 +
1380 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1381 {
1382 u64 result;
1383 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1384
1385 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1386 {
1387 - u64 result;
1388 - unsigned long tmp;
1389 + u64 result, tmp;
1390
1391 smp_mb();
1392
1393 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1394 -"1: ldrexd %0, %H0, [%3]\n"
1395 -" subs %0, %0, #1\n"
1396 -" sbc %H0, %H0, #0\n"
1397 +"1: ldrexd %1, %H1, [%3]\n"
1398 +" subs %0, %1, #1\n"
1399 +" sbcs %H0, %H1, #0\n"
1400 +
1401 +#ifdef CONFIG_PAX_REFCOUNT
1402 +" bvc 3f\n"
1403 +" mov %0, %1\n"
1404 +" mov %H0, %H1\n"
1405 +"2: bkpt 0xf103\n"
1406 +"3:\n"
1407 +#endif
1408 +
1409 " teq %H0, #0\n"
1410 -" bmi 2f\n"
1411 +" bmi 4f\n"
1412 " strexd %1, %0, %H0, [%3]\n"
1413 " teq %1, #0\n"
1414 " bne 1b\n"
1415 -"2:"
1416 +"4:\n"
1417 +
1418 +#ifdef CONFIG_PAX_REFCOUNT
1419 + _ASM_EXTABLE(2b, 4b)
1420 +#endif
1421 +
1422 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1423 : "r" (&v->counter)
1424 : "cc");
1425 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1426 " teq %0, %5\n"
1427 " teqeq %H0, %H5\n"
1428 " moveq %1, #0\n"
1429 -" beq 2f\n"
1430 +" beq 4f\n"
1431 " adds %0, %0, %6\n"
1432 -" adc %H0, %H0, %H6\n"
1433 +" adcs %H0, %H0, %H6\n"
1434 +
1435 +#ifdef CONFIG_PAX_REFCOUNT
1436 +" bvc 3f\n"
1437 +"2: bkpt 0xf103\n"
1438 +"3:\n"
1439 +#endif
1440 +
1441 " strexd %2, %0, %H0, [%4]\n"
1442 " teq %2, #0\n"
1443 " bne 1b\n"
1444 -"2:"
1445 +"4:\n"
1446 +
1447 +#ifdef CONFIG_PAX_REFCOUNT
1448 + _ASM_EXTABLE(2b, 4b)
1449 +#endif
1450 +
1451 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1452 : "r" (&v->counter), "r" (u), "r" (a)
1453 : "cc");
1454 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1455
1456 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1457 #define atomic64_inc(v) atomic64_add(1LL, (v))
1458 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1459 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1460 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1461 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1462 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1463 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1464 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1465 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1466 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1467 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1468 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1469 index 75fe66b..ba3dee4 100644
1470 --- a/arch/arm/include/asm/cache.h
1471 +++ b/arch/arm/include/asm/cache.h
1472 @@ -4,8 +4,10 @@
1473 #ifndef __ASMARM_CACHE_H
1474 #define __ASMARM_CACHE_H
1475
1476 +#include <linux/const.h>
1477 +
1478 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1479 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1480 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1481
1482 /*
1483 * Memory returned by kmalloc() may be used for DMA, so we must make
1484 @@ -24,5 +26,6 @@
1485 #endif
1486
1487 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1488 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1489
1490 #endif
1491 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1492 index e1489c5..d418304 100644
1493 --- a/arch/arm/include/asm/cacheflush.h
1494 +++ b/arch/arm/include/asm/cacheflush.h
1495 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1496 void (*dma_unmap_area)(const void *, size_t, int);
1497
1498 void (*dma_flush_range)(const void *, const void *);
1499 -};
1500 +} __no_const;
1501
1502 /*
1503 * Select the calling method
1504 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1505 index 6dcc164..b14d917 100644
1506 --- a/arch/arm/include/asm/checksum.h
1507 +++ b/arch/arm/include/asm/checksum.h
1508 @@ -37,7 +37,19 @@ __wsum
1509 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1510
1511 __wsum
1512 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1513 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1514 +
1515 +static inline __wsum
1516 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1517 +{
1518 + __wsum ret;
1519 + pax_open_userland();
1520 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1521 + pax_close_userland();
1522 + return ret;
1523 +}
1524 +
1525 +
1526
1527 /*
1528 * Fold a partial checksum without adding pseudo headers
1529 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1530 index 7eb18c1..e38b6d2 100644
1531 --- a/arch/arm/include/asm/cmpxchg.h
1532 +++ b/arch/arm/include/asm/cmpxchg.h
1533 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1534
1535 #define xchg(ptr,x) \
1536 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1537 +#define xchg_unchecked(ptr,x) \
1538 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1539
1540 #include <asm-generic/cmpxchg-local.h>
1541
1542 diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1543 index 720799f..2f67631 100644
1544 --- a/arch/arm/include/asm/delay.h
1545 +++ b/arch/arm/include/asm/delay.h
1546 @@ -25,9 +25,9 @@ extern struct arm_delay_ops {
1547 void (*const_udelay)(unsigned long);
1548 void (*udelay)(unsigned long);
1549 bool const_clock;
1550 -} arm_delay_ops;
1551 +} *arm_delay_ops;
1552
1553 -#define __delay(n) arm_delay_ops.delay(n)
1554 +#define __delay(n) arm_delay_ops->delay(n)
1555
1556 /*
1557 * This function intentionally does not exist; if you see references to
1558 @@ -48,8 +48,8 @@ extern void __bad_udelay(void);
1559 * first constant multiplications gets optimized away if the delay is
1560 * a constant)
1561 */
1562 -#define __udelay(n) arm_delay_ops.udelay(n)
1563 -#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1564 +#define __udelay(n) arm_delay_ops->udelay(n)
1565 +#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1566
1567 #define udelay(n) \
1568 (__builtin_constant_p(n) ? \
1569 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1570 index 6ddbe44..b5e38b1 100644
1571 --- a/arch/arm/include/asm/domain.h
1572 +++ b/arch/arm/include/asm/domain.h
1573 @@ -48,18 +48,37 @@
1574 * Domain types
1575 */
1576 #define DOMAIN_NOACCESS 0
1577 -#define DOMAIN_CLIENT 1
1578 #ifdef CONFIG_CPU_USE_DOMAINS
1579 +#define DOMAIN_USERCLIENT 1
1580 +#define DOMAIN_KERNELCLIENT 1
1581 #define DOMAIN_MANAGER 3
1582 +#define DOMAIN_VECTORS DOMAIN_USER
1583 #else
1584 +
1585 +#ifdef CONFIG_PAX_KERNEXEC
1586 #define DOMAIN_MANAGER 1
1587 +#define DOMAIN_KERNEXEC 3
1588 +#else
1589 +#define DOMAIN_MANAGER 1
1590 +#endif
1591 +
1592 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1593 +#define DOMAIN_USERCLIENT 0
1594 +#define DOMAIN_UDEREF 1
1595 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1596 +#else
1597 +#define DOMAIN_USERCLIENT 1
1598 +#define DOMAIN_VECTORS DOMAIN_USER
1599 +#endif
1600 +#define DOMAIN_KERNELCLIENT 1
1601 +
1602 #endif
1603
1604 #define domain_val(dom,type) ((type) << (2*(dom)))
1605
1606 #ifndef __ASSEMBLY__
1607
1608 -#ifdef CONFIG_CPU_USE_DOMAINS
1609 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1610 static inline void set_domain(unsigned val)
1611 {
1612 asm volatile(
1613 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1614 isb();
1615 }
1616
1617 -#define modify_domain(dom,type) \
1618 - do { \
1619 - struct thread_info *thread = current_thread_info(); \
1620 - unsigned int domain = thread->cpu_domain; \
1621 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1622 - thread->cpu_domain = domain | domain_val(dom, type); \
1623 - set_domain(thread->cpu_domain); \
1624 - } while (0)
1625 -
1626 +extern void modify_domain(unsigned int dom, unsigned int type);
1627 #else
1628 static inline void set_domain(unsigned val) { }
1629 static inline void modify_domain(unsigned dom, unsigned type) { }
1630 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1631 index 38050b1..9d90e8b 100644
1632 --- a/arch/arm/include/asm/elf.h
1633 +++ b/arch/arm/include/asm/elf.h
1634 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1635 the loader. We need to make sure that it is out of the way of the program
1636 that it will "exec", and that there is sufficient room for the brk. */
1637
1638 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1639 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1640 +
1641 +#ifdef CONFIG_PAX_ASLR
1642 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1643 +
1644 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1645 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1646 +#endif
1647
1648 /* When the program starts, a1 contains a pointer to a function to be
1649 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1650 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1651 extern void elf_set_personality(const struct elf32_hdr *);
1652 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1653
1654 -struct mm_struct;
1655 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1656 -#define arch_randomize_brk arch_randomize_brk
1657 -
1658 #endif
1659 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1660 index de53547..52b9a28 100644
1661 --- a/arch/arm/include/asm/fncpy.h
1662 +++ b/arch/arm/include/asm/fncpy.h
1663 @@ -81,7 +81,9 @@
1664 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1665 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1666 \
1667 + pax_open_kernel(); \
1668 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1669 + pax_close_kernel(); \
1670 flush_icache_range((unsigned long)(dest_buf), \
1671 (unsigned long)(dest_buf) + (size)); \
1672 \
1673 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1674 index e42cf59..7b94b8f 100644
1675 --- a/arch/arm/include/asm/futex.h
1676 +++ b/arch/arm/include/asm/futex.h
1677 @@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1678 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1679 return -EFAULT;
1680
1681 + pax_open_userland();
1682 +
1683 smp_mb();
1684 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1685 "1: ldrex %1, [%4]\n"
1686 @@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1687 : "cc", "memory");
1688 smp_mb();
1689
1690 + pax_close_userland();
1691 +
1692 *uval = val;
1693 return ret;
1694 }
1695 @@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1696 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1697 return -EFAULT;
1698
1699 + pax_open_userland();
1700 +
1701 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1702 "1: " TUSER(ldr) " %1, [%4]\n"
1703 " teq %1, %2\n"
1704 @@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1705 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1706 : "cc", "memory");
1707
1708 + pax_close_userland();
1709 +
1710 *uval = val;
1711 return ret;
1712 }
1713 @@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1714 return -EFAULT;
1715
1716 pagefault_disable(); /* implies preempt_disable() */
1717 + pax_open_userland();
1718
1719 switch (op) {
1720 case FUTEX_OP_SET:
1721 @@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1722 ret = -ENOSYS;
1723 }
1724
1725 + pax_close_userland();
1726 pagefault_enable(); /* subsumes preempt_enable() */
1727
1728 if (!ret) {
1729 diff --git a/arch/arm/include/asm/hardware/gic.h b/arch/arm/include/asm/hardware/gic.h
1730 index 4b1ce6c..bea3f73 100644
1731 --- a/arch/arm/include/asm/hardware/gic.h
1732 +++ b/arch/arm/include/asm/hardware/gic.h
1733 @@ -34,9 +34,10 @@
1734
1735 #ifndef __ASSEMBLY__
1736 #include <linux/irqdomain.h>
1737 +#include <linux/irq.h>
1738 struct device_node;
1739
1740 -extern struct irq_chip gic_arch_extn;
1741 +extern irq_chip_no_const gic_arch_extn;
1742
1743 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
1744 u32 offset, struct device_node *);
1745 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1746 index 83eb2f7..ed77159 100644
1747 --- a/arch/arm/include/asm/kmap_types.h
1748 +++ b/arch/arm/include/asm/kmap_types.h
1749 @@ -4,6 +4,6 @@
1750 /*
1751 * This is the "bare minimum". AIO seems to require this.
1752 */
1753 -#define KM_TYPE_NR 16
1754 +#define KM_TYPE_NR 17
1755
1756 #endif
1757 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1758 index 9e614a1..3302cca 100644
1759 --- a/arch/arm/include/asm/mach/dma.h
1760 +++ b/arch/arm/include/asm/mach/dma.h
1761 @@ -22,7 +22,7 @@ struct dma_ops {
1762 int (*residue)(unsigned int, dma_t *); /* optional */
1763 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1764 const char *type;
1765 -};
1766 +} __do_const;
1767
1768 struct dma_struct {
1769 void *addr; /* single DMA address */
1770 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1771 index 2fe141f..192dc01 100644
1772 --- a/arch/arm/include/asm/mach/map.h
1773 +++ b/arch/arm/include/asm/mach/map.h
1774 @@ -27,13 +27,16 @@ struct map_desc {
1775 #define MT_MINICLEAN 6
1776 #define MT_LOW_VECTORS 7
1777 #define MT_HIGH_VECTORS 8
1778 -#define MT_MEMORY 9
1779 +#define MT_MEMORY_RWX 9
1780 #define MT_ROM 10
1781 -#define MT_MEMORY_NONCACHED 11
1782 +#define MT_MEMORY_NONCACHED_RX 11
1783 #define MT_MEMORY_DTCM 12
1784 #define MT_MEMORY_ITCM 13
1785 #define MT_MEMORY_SO 14
1786 #define MT_MEMORY_DMA_READY 15
1787 +#define MT_MEMORY_RW 16
1788 +#define MT_MEMORY_RX 17
1789 +#define MT_MEMORY_NONCACHED_RW 18
1790
1791 #ifdef CONFIG_MMU
1792 extern void iotable_init(struct map_desc *, int);
1793 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1794 index 53426c6..c7baff3 100644
1795 --- a/arch/arm/include/asm/outercache.h
1796 +++ b/arch/arm/include/asm/outercache.h
1797 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1798 #endif
1799 void (*set_debug)(unsigned long);
1800 void (*resume)(void);
1801 -};
1802 +} __no_const;
1803
1804 #ifdef CONFIG_OUTER_CACHE
1805
1806 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1807 index 812a494..71fc0b6 100644
1808 --- a/arch/arm/include/asm/page.h
1809 +++ b/arch/arm/include/asm/page.h
1810 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1811 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1812 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1813 unsigned long vaddr, struct vm_area_struct *vma);
1814 -};
1815 +} __no_const;
1816
1817 #ifdef MULTI_USER
1818 extern struct cpu_user_fns cpu_user;
1819 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1820 index 943504f..c37a730 100644
1821 --- a/arch/arm/include/asm/pgalloc.h
1822 +++ b/arch/arm/include/asm/pgalloc.h
1823 @@ -17,6 +17,7 @@
1824 #include <asm/processor.h>
1825 #include <asm/cacheflush.h>
1826 #include <asm/tlbflush.h>
1827 +#include <asm/system_info.h>
1828
1829 #define check_pgt_cache() do { } while (0)
1830
1831 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1832 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1833 }
1834
1835 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1836 +{
1837 + pud_populate(mm, pud, pmd);
1838 +}
1839 +
1840 #else /* !CONFIG_ARM_LPAE */
1841
1842 /*
1843 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1844 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1845 #define pmd_free(mm, pmd) do { } while (0)
1846 #define pud_populate(mm,pmd,pte) BUG()
1847 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1848
1849 #endif /* CONFIG_ARM_LPAE */
1850
1851 @@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1852 __free_page(pte);
1853 }
1854
1855 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1856 +{
1857 +#ifdef CONFIG_ARM_LPAE
1858 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1859 +#else
1860 + if (addr & SECTION_SIZE)
1861 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1862 + else
1863 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1864 +#endif
1865 + flush_pmd_entry(pmdp);
1866 +}
1867 +
1868 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1869 pmdval_t prot)
1870 {
1871 @@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1872 static inline void
1873 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1874 {
1875 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1876 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1877 }
1878 #define pmd_pgtable(pmd) pmd_page(pmd)
1879
1880 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1881 index 5cfba15..f415e1a 100644
1882 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1883 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1884 @@ -20,12 +20,15 @@
1885 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1886 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1887 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1888 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1889 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1890 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1891 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1892 +
1893 /*
1894 * - section
1895 */
1896 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1897 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1898 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1899 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1900 @@ -37,6 +40,7 @@
1901 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1902 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1903 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1904 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1905
1906 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1907 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1908 @@ -66,6 +70,7 @@
1909 * - extended small page/tiny page
1910 */
1911 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1912 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1913 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1914 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1915 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1916 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1917 index f97ee02..07f1be5 100644
1918 --- a/arch/arm/include/asm/pgtable-2level.h
1919 +++ b/arch/arm/include/asm/pgtable-2level.h
1920 @@ -125,6 +125,7 @@
1921 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1922 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1923 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1924 +#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1925
1926 /*
1927 * These are the memory types, defined to be compatible with
1928 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1929 index d795282..a43ea90 100644
1930 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1931 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1932 @@ -32,15 +32,18 @@
1933 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1934 #define PMD_BIT4 (_AT(pmdval_t, 0))
1935 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1936 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1937
1938 /*
1939 * - section
1940 */
1941 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1942 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1943 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1944 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1945 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1946 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1947 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1948 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1949 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1950 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1951 @@ -66,6 +69,7 @@
1952 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1953 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1954 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1955 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1956 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1957
1958 /*
1959 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1960 index a3f3792..7b932a6 100644
1961 --- a/arch/arm/include/asm/pgtable-3level.h
1962 +++ b/arch/arm/include/asm/pgtable-3level.h
1963 @@ -74,6 +74,7 @@
1964 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1965 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1966 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1967 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1968 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1969 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1970 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1971 @@ -82,6 +83,7 @@
1972 /*
1973 * To be used in assembly code with the upper page attributes.
1974 */
1975 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1976 #define L_PTE_XN_HIGH (1 << (54 - 32))
1977 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1978
1979 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1980 index c094749..fd8272e 100644
1981 --- a/arch/arm/include/asm/pgtable.h
1982 +++ b/arch/arm/include/asm/pgtable.h
1983 @@ -30,6 +30,9 @@
1984 #include <asm/pgtable-2level.h>
1985 #endif
1986
1987 +#define ktla_ktva(addr) (addr)
1988 +#define ktva_ktla(addr) (addr)
1989 +
1990 /*
1991 * Just any arbitrary offset to the start of the vmalloc VM area: the
1992 * current 8MB value just means that there will be a 8MB "hole" after the
1993 @@ -45,6 +48,9 @@
1994 #define LIBRARY_TEXT_START 0x0c000000
1995
1996 #ifndef __ASSEMBLY__
1997 +extern pteval_t __supported_pte_mask;
1998 +extern pmdval_t __supported_pmd_mask;
1999 +
2000 extern void __pte_error(const char *file, int line, pte_t);
2001 extern void __pmd_error(const char *file, int line, pmd_t);
2002 extern void __pgd_error(const char *file, int line, pgd_t);
2003 @@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2004 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2005 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2006
2007 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2008 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2009 +
2010 +#ifdef CONFIG_PAX_KERNEXEC
2011 +#include <asm/domain.h>
2012 +#include <linux/thread_info.h>
2013 +#include <linux/preempt.h>
2014 +#endif
2015 +
2016 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2017 +static inline int test_domain(int domain, int domaintype)
2018 +{
2019 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2020 +}
2021 +#endif
2022 +
2023 +#ifdef CONFIG_PAX_KERNEXEC
2024 +static inline unsigned long pax_open_kernel(void) {
2025 +#ifdef CONFIG_ARM_LPAE
2026 + /* TODO */
2027 +#else
2028 + preempt_disable();
2029 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2030 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2031 +#endif
2032 + return 0;
2033 +}
2034 +
2035 +static inline unsigned long pax_close_kernel(void) {
2036 +#ifdef CONFIG_ARM_LPAE
2037 + /* TODO */
2038 +#else
2039 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2040 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2041 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2042 + preempt_enable_no_resched();
2043 +#endif
2044 + return 0;
2045 +}
2046 +#else
2047 +static inline unsigned long pax_open_kernel(void) { return 0; }
2048 +static inline unsigned long pax_close_kernel(void) { return 0; }
2049 +#endif
2050 +
2051 /*
2052 * This is the lowest virtual address we can permit any user space
2053 * mapping to be mapped at. This is particularly important for
2054 @@ -63,8 +113,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2055 /*
2056 * The pgprot_* and protection_map entries will be fixed up in runtime
2057 * to include the cachable and bufferable bits based on memory policy,
2058 - * as well as any architecture dependent bits like global/ASID and SMP
2059 - * shared mapping bits.
2060 + * as well as any architecture dependent bits like global/ASID, PXN,
2061 + * and SMP shared mapping bits.
2062 */
2063 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2064
2065 @@ -240,8 +290,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2066
2067 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2068 {
2069 - const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2070 - L_PTE_NONE | L_PTE_VALID;
2071 + const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2072 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2073 return pte;
2074 }
2075 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2076 index f3628fb..a0672dd 100644
2077 --- a/arch/arm/include/asm/proc-fns.h
2078 +++ b/arch/arm/include/asm/proc-fns.h
2079 @@ -75,7 +75,7 @@ extern struct processor {
2080 unsigned int suspend_size;
2081 void (*do_suspend)(void *);
2082 void (*do_resume)(void *);
2083 -} processor;
2084 +} __do_const processor;
2085
2086 #ifndef MULTI_CPU
2087 extern void cpu_proc_init(void);
2088 diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2089 index 06e7d50..8a8e251 100644
2090 --- a/arch/arm/include/asm/processor.h
2091 +++ b/arch/arm/include/asm/processor.h
2092 @@ -65,9 +65,8 @@ struct thread_struct {
2093 regs->ARM_cpsr |= PSR_ENDSTATE; \
2094 regs->ARM_pc = pc & ~1; /* pc */ \
2095 regs->ARM_sp = sp; /* sp */ \
2096 - regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2097 - regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2098 - regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2099 + /* r2 (envp), r1 (argv), r0 (argc) */ \
2100 + (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2101 nommu_start_thread(regs); \
2102 })
2103
2104 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2105 index d3a22be..3a69ad5 100644
2106 --- a/arch/arm/include/asm/smp.h
2107 +++ b/arch/arm/include/asm/smp.h
2108 @@ -107,7 +107,7 @@ struct smp_operations {
2109 int (*cpu_disable)(unsigned int cpu);
2110 #endif
2111 #endif
2112 -};
2113 +} __no_const;
2114
2115 /*
2116 * set platform specific SMP operations
2117 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2118 index cddda1f..ff357f7 100644
2119 --- a/arch/arm/include/asm/thread_info.h
2120 +++ b/arch/arm/include/asm/thread_info.h
2121 @@ -77,9 +77,9 @@ struct thread_info {
2122 .flags = 0, \
2123 .preempt_count = INIT_PREEMPT_COUNT, \
2124 .addr_limit = KERNEL_DS, \
2125 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2126 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2127 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2128 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2129 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2130 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2131 .restart_block = { \
2132 .fn = do_no_restart_syscall, \
2133 }, \
2134 @@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2135 #define TIF_SYSCALL_AUDIT 9
2136 #define TIF_SYSCALL_TRACEPOINT 10
2137 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2138 +
2139 +/* within 8 bits of TIF_SYSCALL_TRACE
2140 + * to meet flexible second operand requirements
2141 + */
2142 +#define TIF_GRSEC_SETXID 12
2143 +
2144 #define TIF_USING_IWMMXT 17
2145 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2146 #define TIF_RESTORE_SIGMASK 20
2147 @@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2148 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2149 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2150 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2151 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2152
2153 /* Checks for any syscall work in entry-common.S */
2154 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2155 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2156 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2157
2158 /*
2159 * Change these and you break ASM code in entry-common.S
2160 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2161 index 7e1f760..752fcb7 100644
2162 --- a/arch/arm/include/asm/uaccess.h
2163 +++ b/arch/arm/include/asm/uaccess.h
2164 @@ -18,6 +18,7 @@
2165 #include <asm/domain.h>
2166 #include <asm/unified.h>
2167 #include <asm/compiler.h>
2168 +#include <asm/pgtable.h>
2169
2170 #define VERIFY_READ 0
2171 #define VERIFY_WRITE 1
2172 @@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2173 #define USER_DS TASK_SIZE
2174 #define get_fs() (current_thread_info()->addr_limit)
2175
2176 +static inline void pax_open_userland(void)
2177 +{
2178 +
2179 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2180 + if (get_fs() == USER_DS) {
2181 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2182 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2183 + }
2184 +#endif
2185 +
2186 +}
2187 +
2188 +static inline void pax_close_userland(void)
2189 +{
2190 +
2191 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2192 + if (get_fs() == USER_DS) {
2193 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2194 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2195 + }
2196 +#endif
2197 +
2198 +}
2199 +
2200 static inline void set_fs(mm_segment_t fs)
2201 {
2202 current_thread_info()->addr_limit = fs;
2203 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2204 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2205 }
2206
2207 #define segment_eq(a,b) ((a) == (b))
2208 @@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2209
2210 #define get_user(x,p) \
2211 ({ \
2212 + int __e; \
2213 might_fault(); \
2214 - __get_user_check(x,p); \
2215 + pax_open_userland(); \
2216 + __e = __get_user_check(x,p); \
2217 + pax_close_userland(); \
2218 + __e; \
2219 })
2220
2221 extern int __put_user_1(void *, unsigned int);
2222 @@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2223
2224 #define put_user(x,p) \
2225 ({ \
2226 + int __e; \
2227 might_fault(); \
2228 - __put_user_check(x,p); \
2229 + pax_open_userland(); \
2230 + __e = __put_user_check(x,p); \
2231 + pax_close_userland(); \
2232 + __e; \
2233 })
2234
2235 #else /* CONFIG_MMU */
2236 @@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2237 #define __get_user(x,ptr) \
2238 ({ \
2239 long __gu_err = 0; \
2240 + pax_open_userland(); \
2241 __get_user_err((x),(ptr),__gu_err); \
2242 + pax_close_userland(); \
2243 __gu_err; \
2244 })
2245
2246 #define __get_user_error(x,ptr,err) \
2247 ({ \
2248 + pax_open_userland(); \
2249 __get_user_err((x),(ptr),err); \
2250 + pax_close_userland(); \
2251 (void) 0; \
2252 })
2253
2254 @@ -312,13 +349,17 @@ do { \
2255 #define __put_user(x,ptr) \
2256 ({ \
2257 long __pu_err = 0; \
2258 + pax_open_userland(); \
2259 __put_user_err((x),(ptr),__pu_err); \
2260 + pax_close_userland(); \
2261 __pu_err; \
2262 })
2263
2264 #define __put_user_error(x,ptr,err) \
2265 ({ \
2266 + pax_open_userland(); \
2267 __put_user_err((x),(ptr),err); \
2268 + pax_close_userland(); \
2269 (void) 0; \
2270 })
2271
2272 @@ -418,11 +459,44 @@ do { \
2273
2274
2275 #ifdef CONFIG_MMU
2276 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2277 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2278 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2279 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2280 +
2281 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2282 +{
2283 + unsigned long ret;
2284 +
2285 + check_object_size(to, n, false);
2286 + pax_open_userland();
2287 + ret = ___copy_from_user(to, from, n);
2288 + pax_close_userland();
2289 + return ret;
2290 +}
2291 +
2292 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2293 +{
2294 + unsigned long ret;
2295 +
2296 + check_object_size(from, n, true);
2297 + pax_open_userland();
2298 + ret = ___copy_to_user(to, from, n);
2299 + pax_close_userland();
2300 + return ret;
2301 +}
2302 +
2303 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2304 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2305 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2306 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2307 +
2308 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2309 +{
2310 + unsigned long ret;
2311 + pax_open_userland();
2312 + ret = ___clear_user(addr, n);
2313 + pax_close_userland();
2314 + return ret;
2315 +}
2316 +
2317 #else
2318 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2319 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2320 @@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2321
2322 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2323 {
2324 + if ((long)n < 0)
2325 + return n;
2326 +
2327 if (access_ok(VERIFY_READ, from, n))
2328 n = __copy_from_user(to, from, n);
2329 else /* security hole - plug it */
2330 @@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2331
2332 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2333 {
2334 + if ((long)n < 0)
2335 + return n;
2336 +
2337 if (access_ok(VERIFY_WRITE, to, n))
2338 n = __copy_to_user(to, from, n);
2339 return n;
2340 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2341 index 96ee092..37f1844 100644
2342 --- a/arch/arm/include/uapi/asm/ptrace.h
2343 +++ b/arch/arm/include/uapi/asm/ptrace.h
2344 @@ -73,7 +73,7 @@
2345 * ARMv7 groups of PSR bits
2346 */
2347 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2348 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2349 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2350 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2351 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2352
2353 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2354 index 60d3b73..d27ee09 100644
2355 --- a/arch/arm/kernel/armksyms.c
2356 +++ b/arch/arm/kernel/armksyms.c
2357 @@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2358 #ifdef CONFIG_MMU
2359 EXPORT_SYMBOL(copy_page);
2360
2361 -EXPORT_SYMBOL(__copy_from_user);
2362 -EXPORT_SYMBOL(__copy_to_user);
2363 -EXPORT_SYMBOL(__clear_user);
2364 +EXPORT_SYMBOL(___copy_from_user);
2365 +EXPORT_SYMBOL(___copy_to_user);
2366 +EXPORT_SYMBOL(___clear_user);
2367
2368 EXPORT_SYMBOL(__get_user_1);
2369 EXPORT_SYMBOL(__get_user_2);
2370 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2371 index 0f82098..3dbd3ee 100644
2372 --- a/arch/arm/kernel/entry-armv.S
2373 +++ b/arch/arm/kernel/entry-armv.S
2374 @@ -47,6 +47,87 @@
2375 9997:
2376 .endm
2377
2378 + .macro pax_enter_kernel
2379 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2380 + @ make aligned space for saved DACR
2381 + sub sp, sp, #8
2382 + @ save regs
2383 + stmdb sp!, {r1, r2}
2384 + @ read DACR from cpu_domain into r1
2385 + mov r2, sp
2386 + @ assume 8K pages, since we have to split the immediate in two
2387 + bic r2, r2, #(0x1fc0)
2388 + bic r2, r2, #(0x3f)
2389 + ldr r1, [r2, #TI_CPU_DOMAIN]
2390 + @ store old DACR on stack
2391 + str r1, [sp, #8]
2392 +#ifdef CONFIG_PAX_KERNEXEC
2393 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2394 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2395 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2396 +#endif
2397 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2398 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2399 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2400 +#endif
2401 + @ write r1 to current_thread_info()->cpu_domain
2402 + str r1, [r2, #TI_CPU_DOMAIN]
2403 + @ write r1 to DACR
2404 + mcr p15, 0, r1, c3, c0, 0
2405 + @ instruction sync
2406 + instr_sync
2407 + @ restore regs
2408 + ldmia sp!, {r1, r2}
2409 +#endif
2410 + .endm
2411 +
2412 + .macro pax_open_userland
2413 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2414 + @ save regs
2415 + stmdb sp!, {r0, r1}
2416 + @ read DACR from cpu_domain into r1
2417 + mov r0, sp
2418 + @ assume 8K pages, since we have to split the immediate in two
2419 + bic r0, r0, #(0x1fc0)
2420 + bic r0, r0, #(0x3f)
2421 + ldr r1, [r0, #TI_CPU_DOMAIN]
2422 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2423 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2424 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2425 + @ write r1 to current_thread_info()->cpu_domain
2426 + str r1, [r0, #TI_CPU_DOMAIN]
2427 + @ write r1 to DACR
2428 + mcr p15, 0, r1, c3, c0, 0
2429 + @ instruction sync
2430 + instr_sync
2431 + @ restore regs
2432 + ldmia sp!, {r0, r1}
2433 +#endif
2434 + .endm
2435 +
2436 + .macro pax_close_userland
2437 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2438 + @ save regs
2439 + stmdb sp!, {r0, r1}
2440 + @ read DACR from cpu_domain into r1
2441 + mov r0, sp
2442 + @ assume 8K pages, since we have to split the immediate in two
2443 + bic r0, r0, #(0x1fc0)
2444 + bic r0, r0, #(0x3f)
2445 + ldr r1, [r0, #TI_CPU_DOMAIN]
2446 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2447 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2448 + @ write r1 to current_thread_info()->cpu_domain
2449 + str r1, [r0, #TI_CPU_DOMAIN]
2450 + @ write r1 to DACR
2451 + mcr p15, 0, r1, c3, c0, 0
2452 + @ instruction sync
2453 + instr_sync
2454 + @ restore regs
2455 + ldmia sp!, {r0, r1}
2456 +#endif
2457 + .endm
2458 +
2459 .macro pabt_helper
2460 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2461 #ifdef MULTI_PABORT
2462 @@ -89,11 +170,15 @@
2463 * Invalid mode handlers
2464 */
2465 .macro inv_entry, reason
2466 +
2467 + pax_enter_kernel
2468 +
2469 sub sp, sp, #S_FRAME_SIZE
2470 ARM( stmib sp, {r1 - lr} )
2471 THUMB( stmia sp, {r0 - r12} )
2472 THUMB( str sp, [sp, #S_SP] )
2473 THUMB( str lr, [sp, #S_LR] )
2474 +
2475 mov r1, #\reason
2476 .endm
2477
2478 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2479 .macro svc_entry, stack_hole=0
2480 UNWIND(.fnstart )
2481 UNWIND(.save {r0 - pc} )
2482 +
2483 + pax_enter_kernel
2484 +
2485 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2486 +
2487 #ifdef CONFIG_THUMB2_KERNEL
2488 SPFIX( str r0, [sp] ) @ temporarily saved
2489 SPFIX( mov r0, sp )
2490 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2491 ldmia r0, {r3 - r5}
2492 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2493 mov r6, #-1 @ "" "" "" ""
2494 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2495 + @ offset sp by 8 as done in pax_enter_kernel
2496 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2497 +#else
2498 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2499 +#endif
2500 SPFIX( addeq r2, r2, #4 )
2501 str r3, [sp, #-4]! @ save the "real" r0 copied
2502 @ from the exception stack
2503 @@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2504 .macro usr_entry
2505 UNWIND(.fnstart )
2506 UNWIND(.cantunwind ) @ don't unwind the user space
2507 +
2508 + pax_enter_kernel_user
2509 +
2510 sub sp, sp, #S_FRAME_SIZE
2511 ARM( stmib sp, {r1 - r12} )
2512 THUMB( stmia sp, {r0 - r12} )
2513 @@ -456,7 +553,9 @@ __und_usr:
2514 tst r3, #PSR_T_BIT @ Thumb mode?
2515 bne __und_usr_thumb
2516 sub r4, r2, #4 @ ARM instr at LR - 4
2517 + pax_open_userland
2518 1: ldrt r0, [r4]
2519 + pax_close_userland
2520 #ifdef CONFIG_CPU_ENDIAN_BE8
2521 rev r0, r0 @ little endian instruction
2522 #endif
2523 @@ -491,10 +590,14 @@ __und_usr_thumb:
2524 */
2525 .arch armv6t2
2526 #endif
2527 + pax_open_userland
2528 2: ldrht r5, [r4]
2529 + pax_close_userland
2530 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2531 blo __und_usr_fault_16 @ 16bit undefined instruction
2532 + pax_open_userland
2533 3: ldrht r0, [r2]
2534 + pax_close_userland
2535 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2536 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2537 orr r0, r0, r5, lsl #16
2538 @@ -733,7 +836,7 @@ ENTRY(__switch_to)
2539 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2540 THUMB( str sp, [ip], #4 )
2541 THUMB( str lr, [ip], #4 )
2542 -#ifdef CONFIG_CPU_USE_DOMAINS
2543 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2544 ldr r6, [r2, #TI_CPU_DOMAIN]
2545 #endif
2546 set_tls r3, r4, r5
2547 @@ -742,7 +845,7 @@ ENTRY(__switch_to)
2548 ldr r8, =__stack_chk_guard
2549 ldr r7, [r7, #TSK_STACK_CANARY]
2550 #endif
2551 -#ifdef CONFIG_CPU_USE_DOMAINS
2552 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2553 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2554 #endif
2555 mov r5, r0
2556 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2557 index a6c301e..908821b 100644
2558 --- a/arch/arm/kernel/entry-common.S
2559 +++ b/arch/arm/kernel/entry-common.S
2560 @@ -10,18 +10,46 @@
2561
2562 #include <asm/unistd.h>
2563 #include <asm/ftrace.h>
2564 +#include <asm/domain.h>
2565 #include <asm/unwind.h>
2566
2567 +#include "entry-header.S"
2568 +
2569 #ifdef CONFIG_NEED_RET_TO_USER
2570 #include <mach/entry-macro.S>
2571 #else
2572 .macro arch_ret_to_user, tmp1, tmp2
2573 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2574 + @ save regs
2575 + stmdb sp!, {r1, r2}
2576 + @ read DACR from cpu_domain into r1
2577 + mov r2, sp
2578 + @ assume 8K pages, since we have to split the immediate in two
2579 + bic r2, r2, #(0x1fc0)
2580 + bic r2, r2, #(0x3f)
2581 + ldr r1, [r2, #TI_CPU_DOMAIN]
2582 +#ifdef CONFIG_PAX_KERNEXEC
2583 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2584 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2585 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2586 +#endif
2587 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2588 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2589 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2590 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2591 +#endif
2592 + @ write r1 to current_thread_info()->cpu_domain
2593 + str r1, [r2, #TI_CPU_DOMAIN]
2594 + @ write r1 to DACR
2595 + mcr p15, 0, r1, c3, c0, 0
2596 + @ instruction sync
2597 + instr_sync
2598 + @ restore regs
2599 + ldmia sp!, {r1, r2}
2600 +#endif
2601 .endm
2602 #endif
2603
2604 -#include "entry-header.S"
2605 -
2606 -
2607 .align 5
2608 /*
2609 * This is the fast syscall return path. We do as little as
2610 @@ -339,6 +367,7 @@ ENDPROC(ftrace_stub)
2611
2612 .align 5
2613 ENTRY(vector_swi)
2614 +
2615 sub sp, sp, #S_FRAME_SIZE
2616 stmia sp, {r0 - r12} @ Calling r0 - r12
2617 ARM( add r8, sp, #S_PC )
2618 @@ -388,6 +417,12 @@ ENTRY(vector_swi)
2619 ldr scno, [lr, #-4] @ get SWI instruction
2620 #endif
2621
2622 + /*
2623 + * do this here to avoid a performance hit of wrapping the code above
2624 + * that directly dereferences userland to parse the SWI instruction
2625 + */
2626 + pax_enter_kernel_user
2627 +
2628 #ifdef CONFIG_ALIGNMENT_TRAP
2629 ldr ip, __cr_alignment
2630 ldr ip, [ip]
2631 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2632 index 9a8531e..812e287 100644
2633 --- a/arch/arm/kernel/entry-header.S
2634 +++ b/arch/arm/kernel/entry-header.S
2635 @@ -73,9 +73,66 @@
2636 msr cpsr_c, \rtemp @ switch back to the SVC mode
2637 .endm
2638
2639 + .macro pax_enter_kernel_user
2640 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2641 + @ save regs
2642 + stmdb sp!, {r0, r1}
2643 + @ read DACR from cpu_domain into r1
2644 + mov r0, sp
2645 + @ assume 8K pages, since we have to split the immediate in two
2646 + bic r0, r0, #(0x1fc0)
2647 + bic r0, r0, #(0x3f)
2648 + ldr r1, [r0, #TI_CPU_DOMAIN]
2649 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2650 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2651 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2652 +#endif
2653 +#ifdef CONFIG_PAX_KERNEXEC
2654 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2655 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2656 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2657 +#endif
2658 + @ write r1 to current_thread_info()->cpu_domain
2659 + str r1, [r0, #TI_CPU_DOMAIN]
2660 + @ write r1 to DACR
2661 + mcr p15, 0, r1, c3, c0, 0
2662 + @ instruction sync
2663 + instr_sync
2664 + @ restore regs
2665 + ldmia sp!, {r0, r1}
2666 +#endif
2667 + .endm
2668 +
2669 + .macro pax_exit_kernel
2670 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2671 + @ save regs
2672 + stmdb sp!, {r0, r1}
2673 + @ read old DACR from stack into r1
2674 + ldr r1, [sp, #(8 + S_SP)]
2675 + sub r1, r1, #8
2676 + ldr r1, [r1]
2677 +
2678 + @ write r1 to current_thread_info()->cpu_domain
2679 + mov r0, sp
2680 + @ assume 8K pages, since we have to split the immediate in two
2681 + bic r0, r0, #(0x1fc0)
2682 + bic r0, r0, #(0x3f)
2683 + str r1, [r0, #TI_CPU_DOMAIN]
2684 + @ write r1 to DACR
2685 + mcr p15, 0, r1, c3, c0, 0
2686 + @ instruction sync
2687 + instr_sync
2688 + @ restore regs
2689 + ldmia sp!, {r0, r1}
2690 +#endif
2691 + .endm
2692 +
2693 #ifndef CONFIG_THUMB2_KERNEL
2694 .macro svc_exit, rpsr
2695 msr spsr_cxsf, \rpsr
2696 +
2697 + pax_exit_kernel
2698 +
2699 #if defined(CONFIG_CPU_V6)
2700 ldr r0, [sp]
2701 strex r1, r2, [sp] @ clear the exclusive monitor
2702 @@ -121,6 +178,9 @@
2703 .endm
2704 #else /* CONFIG_THUMB2_KERNEL */
2705 .macro svc_exit, rpsr
2706 +
2707 + pax_exit_kernel
2708 +
2709 ldr lr, [sp, #S_SP] @ top of the stack
2710 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2711 clrex @ clear the exclusive monitor
2712 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2713 index 2adda11..7fbe958 100644
2714 --- a/arch/arm/kernel/fiq.c
2715 +++ b/arch/arm/kernel/fiq.c
2716 @@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2717 #if defined(CONFIG_CPU_USE_DOMAINS)
2718 memcpy((void *)0xffff001c, start, length);
2719 #else
2720 + pax_open_kernel();
2721 memcpy(vectors_page + 0x1c, start, length);
2722 + pax_close_kernel();
2723 #endif
2724 flush_icache_range(0xffff001c, 0xffff001c + length);
2725 if (!vectors_high())
2726 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2727 index e0eb9a1..c7d74a3 100644
2728 --- a/arch/arm/kernel/head.S
2729 +++ b/arch/arm/kernel/head.S
2730 @@ -52,7 +52,9 @@
2731 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2732
2733 .macro pgtbl, rd, phys
2734 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2735 + mov \rd, #TEXT_OFFSET
2736 + sub \rd, #PG_DIR_SIZE
2737 + add \rd, \rd, \phys
2738 .endm
2739
2740 /*
2741 @@ -434,7 +436,7 @@ __enable_mmu:
2742 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2743 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2744 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2745 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2746 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2747 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2748 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2749 #endif
2750 diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2751 index 5ff2e77..556d030 100644
2752 --- a/arch/arm/kernel/hw_breakpoint.c
2753 +++ b/arch/arm/kernel/hw_breakpoint.c
2754 @@ -1011,7 +1011,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2755 return NOTIFY_OK;
2756 }
2757
2758 -static struct notifier_block __cpuinitdata dbg_reset_nb = {
2759 +static struct notifier_block dbg_reset_nb = {
2760 .notifier_call = dbg_reset_notify,
2761 };
2762
2763 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2764 index 1e9be5d..03edbc2 100644
2765 --- a/arch/arm/kernel/module.c
2766 +++ b/arch/arm/kernel/module.c
2767 @@ -37,12 +37,37 @@
2768 #endif
2769
2770 #ifdef CONFIG_MMU
2771 -void *module_alloc(unsigned long size)
2772 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2773 {
2774 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2775 + return NULL;
2776 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2777 - GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2778 + GFP_KERNEL, prot, -1,
2779 __builtin_return_address(0));
2780 }
2781 +
2782 +void *module_alloc(unsigned long size)
2783 +{
2784 +
2785 +#ifdef CONFIG_PAX_KERNEXEC
2786 + return __module_alloc(size, PAGE_KERNEL);
2787 +#else
2788 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2789 +#endif
2790 +
2791 +}
2792 +
2793 +#ifdef CONFIG_PAX_KERNEXEC
2794 +void module_free_exec(struct module *mod, void *module_region)
2795 +{
2796 + module_free(mod, module_region);
2797 +}
2798 +
2799 +void *module_alloc_exec(unsigned long size)
2800 +{
2801 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2802 +}
2803 +#endif
2804 #endif
2805
2806 int
2807 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2808 index 07314af..c46655c 100644
2809 --- a/arch/arm/kernel/patch.c
2810 +++ b/arch/arm/kernel/patch.c
2811 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2812 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2813 int size;
2814
2815 + pax_open_kernel();
2816 if (thumb2 && __opcode_is_thumb16(insn)) {
2817 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2818 size = sizeof(u16);
2819 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2820 *(u32 *)addr = insn;
2821 size = sizeof(u32);
2822 }
2823 + pax_close_kernel();
2824
2825 flush_icache_range((uintptr_t)(addr),
2826 (uintptr_t)(addr) + size);
2827 diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2828 index 5f66206..dce492f 100644
2829 --- a/arch/arm/kernel/perf_event_cpu.c
2830 +++ b/arch/arm/kernel/perf_event_cpu.c
2831 @@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2832 return NOTIFY_OK;
2833 }
2834
2835 -static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2836 +static struct notifier_block cpu_pmu_hotplug_notifier = {
2837 .notifier_call = cpu_pmu_notify,
2838 };
2839
2840 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2841 index c6dec5f..f853532 100644
2842 --- a/arch/arm/kernel/process.c
2843 +++ b/arch/arm/kernel/process.c
2844 @@ -28,7 +28,6 @@
2845 #include <linux/tick.h>
2846 #include <linux/utsname.h>
2847 #include <linux/uaccess.h>
2848 -#include <linux/random.h>
2849 #include <linux/hw_breakpoint.h>
2850 #include <linux/cpuidle.h>
2851 #include <linux/leds.h>
2852 @@ -256,9 +255,10 @@ void machine_power_off(void)
2853 machine_shutdown();
2854 if (pm_power_off)
2855 pm_power_off();
2856 + BUG();
2857 }
2858
2859 -void machine_restart(char *cmd)
2860 +__noreturn void machine_restart(char *cmd)
2861 {
2862 machine_shutdown();
2863
2864 @@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2865 init_utsname()->release,
2866 (int)strcspn(init_utsname()->version, " "),
2867 init_utsname()->version);
2868 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2869 - print_symbol("LR is at %s\n", regs->ARM_lr);
2870 + printk("PC is at %pA\n", instruction_pointer(regs));
2871 + printk("LR is at %pA\n", regs->ARM_lr);
2872 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2873 "sp : %08lx ip : %08lx fp : %08lx\n",
2874 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2875 @@ -452,12 +452,6 @@ unsigned long get_wchan(struct task_struct *p)
2876 return 0;
2877 }
2878
2879 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2880 -{
2881 - unsigned long range_end = mm->brk + 0x02000000;
2882 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2883 -}
2884 -
2885 #ifdef CONFIG_MMU
2886 /*
2887 * The vectors page is always readable from user space for the
2888 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2889 index 03deeff..741ce88 100644
2890 --- a/arch/arm/kernel/ptrace.c
2891 +++ b/arch/arm/kernel/ptrace.c
2892 @@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2893 return current_thread_info()->syscall;
2894 }
2895
2896 +#ifdef CONFIG_GRKERNSEC_SETXID
2897 +extern void gr_delayed_cred_worker(void);
2898 +#endif
2899 +
2900 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2901 {
2902 current_thread_info()->syscall = scno;
2903
2904 +#ifdef CONFIG_GRKERNSEC_SETXID
2905 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2906 + gr_delayed_cred_worker();
2907 +#endif
2908 +
2909 /* Do the secure computing check first; failures should be fast. */
2910 if (secure_computing(scno) == -1)
2911 return -1;
2912 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2913 index 3f6cbb2..6d856f5 100644
2914 --- a/arch/arm/kernel/setup.c
2915 +++ b/arch/arm/kernel/setup.c
2916 @@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2917 unsigned int elf_hwcap __read_mostly;
2918 EXPORT_SYMBOL(elf_hwcap);
2919
2920 +pteval_t __supported_pte_mask __read_only;
2921 +pmdval_t __supported_pmd_mask __read_only;
2922
2923 #ifdef MULTI_CPU
2924 -struct processor processor __read_mostly;
2925 +struct processor processor;
2926 #endif
2927 #ifdef MULTI_TLB
2928 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2929 +struct cpu_tlb_fns cpu_tlb __read_only;
2930 #endif
2931 #ifdef MULTI_USER
2932 -struct cpu_user_fns cpu_user __read_mostly;
2933 +struct cpu_user_fns cpu_user __read_only;
2934 #endif
2935 #ifdef MULTI_CACHE
2936 -struct cpu_cache_fns cpu_cache __read_mostly;
2937 +struct cpu_cache_fns cpu_cache __read_only;
2938 #endif
2939 #ifdef CONFIG_OUTER_CACHE
2940 -struct outer_cache_fns outer_cache __read_mostly;
2941 +struct outer_cache_fns outer_cache __read_only;
2942 EXPORT_SYMBOL(outer_cache);
2943 #endif
2944
2945 @@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2946 asm("mrc p15, 0, %0, c0, c1, 4"
2947 : "=r" (mmfr0));
2948 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2949 - (mmfr0 & 0x000000f0) >= 0x00000030)
2950 + (mmfr0 & 0x000000f0) >= 0x00000030) {
2951 cpu_arch = CPU_ARCH_ARMv7;
2952 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2953 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2954 + __supported_pte_mask |= L_PTE_PXN;
2955 + __supported_pmd_mask |= PMD_PXNTABLE;
2956 + }
2957 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2958 (mmfr0 & 0x000000f0) == 0x00000020)
2959 cpu_arch = CPU_ARCH_ARMv6;
2960 else
2961 @@ -462,7 +468,7 @@ static void __init setup_processor(void)
2962 __cpu_architecture = __get_cpu_architecture();
2963
2964 #ifdef MULTI_CPU
2965 - processor = *list->proc;
2966 + memcpy((void *)&processor, list->proc, sizeof processor);
2967 #endif
2968 #ifdef MULTI_TLB
2969 cpu_tlb = *list->tlb;
2970 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2971 index 58af91c..343ce99 100644
2972 --- a/arch/arm/kernel/smp.c
2973 +++ b/arch/arm/kernel/smp.c
2974 @@ -70,7 +70,7 @@ enum ipi_msg_type {
2975
2976 static DECLARE_COMPLETION(cpu_running);
2977
2978 -static struct smp_operations smp_ops;
2979 +static struct smp_operations smp_ops __read_only;
2980
2981 void __init smp_set_ops(struct smp_operations *ops)
2982 {
2983 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2984 index b0179b8..b7b16c7 100644
2985 --- a/arch/arm/kernel/traps.c
2986 +++ b/arch/arm/kernel/traps.c
2987 @@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2988 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2989 {
2990 #ifdef CONFIG_KALLSYMS
2991 - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2992 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2993 #else
2994 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2995 #endif
2996 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2997 static int die_owner = -1;
2998 static unsigned int die_nest_count;
2999
3000 +extern void gr_handle_kernel_exploit(void);
3001 +
3002 static unsigned long oops_begin(void)
3003 {
3004 int cpu;
3005 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3006 panic("Fatal exception in interrupt");
3007 if (panic_on_oops)
3008 panic("Fatal exception");
3009 +
3010 + gr_handle_kernel_exploit();
3011 +
3012 if (signr)
3013 do_exit(signr);
3014 }
3015 @@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3016 * The user helper at 0xffff0fe0 must be used instead.
3017 * (see entry-armv.S for details)
3018 */
3019 + pax_open_kernel();
3020 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3021 + pax_close_kernel();
3022 }
3023 return 0;
3024
3025 @@ -849,5 +856,9 @@ void __init early_trap_init(void *vectors_base)
3026 sigreturn_codes, sizeof(sigreturn_codes));
3027
3028 flush_icache_range(vectors, vectors + PAGE_SIZE);
3029 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3030 +
3031 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3032 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3033 +#endif
3034 +
3035 }
3036 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3037 index 11c1785..c67d54c 100644
3038 --- a/arch/arm/kernel/vmlinux.lds.S
3039 +++ b/arch/arm/kernel/vmlinux.lds.S
3040 @@ -8,7 +8,11 @@
3041 #include <asm/thread_info.h>
3042 #include <asm/memory.h>
3043 #include <asm/page.h>
3044 -
3045 +
3046 +#ifdef CONFIG_PAX_KERNEXEC
3047 +#include <asm/pgtable.h>
3048 +#endif
3049 +
3050 #define PROC_INFO \
3051 . = ALIGN(4); \
3052 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3053 @@ -90,6 +94,11 @@ SECTIONS
3054 _text = .;
3055 HEAD_TEXT
3056 }
3057 +
3058 +#ifdef CONFIG_PAX_KERNEXEC
3059 + . = ALIGN(1<<SECTION_SHIFT);
3060 +#endif
3061 +
3062 .text : { /* Real text segment */
3063 _stext = .; /* Text and read-only data */
3064 __exception_text_start = .;
3065 @@ -144,6 +153,10 @@ SECTIONS
3066
3067 _etext = .; /* End of text and rodata section */
3068
3069 +#ifdef CONFIG_PAX_KERNEXEC
3070 + . = ALIGN(1<<SECTION_SHIFT);
3071 +#endif
3072 +
3073 #ifndef CONFIG_XIP_KERNEL
3074 . = ALIGN(PAGE_SIZE);
3075 __init_begin = .;
3076 @@ -203,6 +216,11 @@ SECTIONS
3077 . = PAGE_OFFSET + TEXT_OFFSET;
3078 #else
3079 __init_end = .;
3080 +
3081 +#ifdef CONFIG_PAX_KERNEXEC
3082 + . = ALIGN(1<<SECTION_SHIFT);
3083 +#endif
3084 +
3085 . = ALIGN(THREAD_SIZE);
3086 __data_loc = .;
3087 #endif
3088 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3089 index 14a0d98..7771a7d 100644
3090 --- a/arch/arm/lib/clear_user.S
3091 +++ b/arch/arm/lib/clear_user.S
3092 @@ -12,14 +12,14 @@
3093
3094 .text
3095
3096 -/* Prototype: int __clear_user(void *addr, size_t sz)
3097 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3098 * Purpose : clear some user memory
3099 * Params : addr - user memory address to clear
3100 * : sz - number of bytes to clear
3101 * Returns : number of bytes NOT cleared
3102 */
3103 ENTRY(__clear_user_std)
3104 -WEAK(__clear_user)
3105 +WEAK(___clear_user)
3106 stmfd sp!, {r1, lr}
3107 mov r2, #0
3108 cmp r1, #4
3109 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3110 USER( strnebt r2, [r0])
3111 mov r0, #0
3112 ldmfd sp!, {r1, pc}
3113 -ENDPROC(__clear_user)
3114 +ENDPROC(___clear_user)
3115 ENDPROC(__clear_user_std)
3116
3117 .pushsection .fixup,"ax"
3118 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3119 index 66a477a..bee61d3 100644
3120 --- a/arch/arm/lib/copy_from_user.S
3121 +++ b/arch/arm/lib/copy_from_user.S
3122 @@ -16,7 +16,7 @@
3123 /*
3124 * Prototype:
3125 *
3126 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3127 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3128 *
3129 * Purpose:
3130 *
3131 @@ -84,11 +84,11 @@
3132
3133 .text
3134
3135 -ENTRY(__copy_from_user)
3136 +ENTRY(___copy_from_user)
3137
3138 #include "copy_template.S"
3139
3140 -ENDPROC(__copy_from_user)
3141 +ENDPROC(___copy_from_user)
3142
3143 .pushsection .fixup,"ax"
3144 .align 0
3145 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3146 index 6ee2f67..d1cce76 100644
3147 --- a/arch/arm/lib/copy_page.S
3148 +++ b/arch/arm/lib/copy_page.S
3149 @@ -10,6 +10,7 @@
3150 * ASM optimised string functions
3151 */
3152 #include <linux/linkage.h>
3153 +#include <linux/const.h>
3154 #include <asm/assembler.h>
3155 #include <asm/asm-offsets.h>
3156 #include <asm/cache.h>
3157 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3158 index d066df6..df28194 100644
3159 --- a/arch/arm/lib/copy_to_user.S
3160 +++ b/arch/arm/lib/copy_to_user.S
3161 @@ -16,7 +16,7 @@
3162 /*
3163 * Prototype:
3164 *
3165 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3166 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3167 *
3168 * Purpose:
3169 *
3170 @@ -88,11 +88,11 @@
3171 .text
3172
3173 ENTRY(__copy_to_user_std)
3174 -WEAK(__copy_to_user)
3175 +WEAK(___copy_to_user)
3176
3177 #include "copy_template.S"
3178
3179 -ENDPROC(__copy_to_user)
3180 +ENDPROC(___copy_to_user)
3181 ENDPROC(__copy_to_user_std)
3182
3183 .pushsection .fixup,"ax"
3184 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3185 index 7d08b43..f7ca7ea 100644
3186 --- a/arch/arm/lib/csumpartialcopyuser.S
3187 +++ b/arch/arm/lib/csumpartialcopyuser.S
3188 @@ -57,8 +57,8 @@
3189 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3190 */
3191
3192 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3193 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3194 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3195 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3196
3197 #include "csumpartialcopygeneric.S"
3198
3199 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3200 index 6b93f6a..88d9b64 100644
3201 --- a/arch/arm/lib/delay.c
3202 +++ b/arch/arm/lib/delay.c
3203 @@ -28,12 +28,14 @@
3204 /*
3205 * Default to the loop-based delay implementation.
3206 */
3207 -struct arm_delay_ops arm_delay_ops = {
3208 +static struct arm_delay_ops arm_loop_delay_ops = {
3209 .delay = __loop_delay,
3210 .const_udelay = __loop_const_udelay,
3211 .udelay = __loop_udelay,
3212 };
3213
3214 +struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
3215 +
3216 static const struct delay_timer *delay_timer;
3217 static bool delay_calibrated;
3218
3219 @@ -67,6 +69,13 @@ static void __timer_udelay(unsigned long usecs)
3220 __timer_const_udelay(usecs * UDELAY_MULT);
3221 }
3222
3223 +static struct arm_delay_ops arm_timer_delay_ops = {
3224 + .delay = __timer_delay,
3225 + .const_udelay = __timer_const_udelay,
3226 + .udelay = __timer_udelay,
3227 + .const_clock = true,
3228 +};
3229 +
3230 void __init register_current_timer_delay(const struct delay_timer *timer)
3231 {
3232 if (!delay_calibrated) {
3233 @@ -74,10 +83,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
3234 delay_timer = timer;
3235 lpj_fine = timer->freq / HZ;
3236 loops_per_jiffy = lpj_fine;
3237 - arm_delay_ops.delay = __timer_delay;
3238 - arm_delay_ops.const_udelay = __timer_const_udelay;
3239 - arm_delay_ops.udelay = __timer_udelay;
3240 - arm_delay_ops.const_clock = true;
3241 + arm_delay_ops = &arm_timer_delay_ops;
3242 delay_calibrated = true;
3243 } else {
3244 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
3245 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3246 index 025f742..8432b08 100644
3247 --- a/arch/arm/lib/uaccess_with_memcpy.c
3248 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3249 @@ -104,7 +104,7 @@ out:
3250 }
3251
3252 unsigned long
3253 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3254 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3255 {
3256 /*
3257 * This test is stubbed out of the main function above to keep
3258 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3259 index bac21a5..b67ef8e 100644
3260 --- a/arch/arm/mach-kirkwood/common.c
3261 +++ b/arch/arm/mach-kirkwood/common.c
3262 @@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3263 clk_gate_ops.disable(hw);
3264 }
3265
3266 -static struct clk_ops clk_gate_fn_ops;
3267 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3268 +{
3269 + return clk_gate_ops.is_enabled(hw);
3270 +}
3271 +
3272 +static struct clk_ops clk_gate_fn_ops = {
3273 + .enable = clk_gate_fn_enable,
3274 + .disable = clk_gate_fn_disable,
3275 + .is_enabled = clk_gate_fn_is_enabled,
3276 +};
3277
3278 static struct clk __init *clk_register_gate_fn(struct device *dev,
3279 const char *name,
3280 @@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3281 gate_fn->fn_en = fn_en;
3282 gate_fn->fn_dis = fn_dis;
3283
3284 - /* ops is the gate ops, but with our enable/disable functions */
3285 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3286 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3287 - clk_gate_fn_ops = clk_gate_ops;
3288 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3289 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3290 - }
3291 -
3292 clk = clk_register(dev, &gate_fn->gate.hw);
3293
3294 if (IS_ERR(clk))
3295 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3296 index 0abb30f..54064da 100644
3297 --- a/arch/arm/mach-omap2/board-n8x0.c
3298 +++ b/arch/arm/mach-omap2/board-n8x0.c
3299 @@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3300 }
3301 #endif
3302
3303 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3304 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3305 .late_init = n8x0_menelaus_late_init,
3306 };
3307
3308 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3309 index 8033cb7..2f7cb62 100644
3310 --- a/arch/arm/mach-omap2/gpmc.c
3311 +++ b/arch/arm/mach-omap2/gpmc.c
3312 @@ -139,7 +139,6 @@ struct omap3_gpmc_regs {
3313 };
3314
3315 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3316 -static struct irq_chip gpmc_irq_chip;
3317 static unsigned gpmc_irq_start;
3318
3319 static struct resource gpmc_mem_root;
3320 @@ -700,6 +699,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3321
3322 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3323
3324 +static struct irq_chip gpmc_irq_chip = {
3325 + .name = "gpmc",
3326 + .irq_startup = gpmc_irq_noop_ret,
3327 + .irq_enable = gpmc_irq_enable,
3328 + .irq_disable = gpmc_irq_disable,
3329 + .irq_shutdown = gpmc_irq_noop,
3330 + .irq_ack = gpmc_irq_noop,
3331 + .irq_mask = gpmc_irq_noop,
3332 + .irq_unmask = gpmc_irq_noop,
3333 +
3334 +};
3335 +
3336 static int gpmc_setup_irq(void)
3337 {
3338 int i;
3339 @@ -714,15 +725,6 @@ static int gpmc_setup_irq(void)
3340 return gpmc_irq_start;
3341 }
3342
3343 - gpmc_irq_chip.name = "gpmc";
3344 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3345 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3346 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3347 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3348 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3349 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3350 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3351 -
3352 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3353 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3354
3355 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3356 index 5d3b4f4..ddba3c0 100644
3357 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3358 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3359 @@ -340,7 +340,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3360 return NOTIFY_OK;
3361 }
3362
3363 -static struct notifier_block __refdata irq_hotplug_notifier = {
3364 +static struct notifier_block irq_hotplug_notifier = {
3365 .notifier_call = irq_cpu_hotplug_notify,
3366 };
3367
3368 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3369 index e065daa..7b1ad9b 100644
3370 --- a/arch/arm/mach-omap2/omap_device.c
3371 +++ b/arch/arm/mach-omap2/omap_device.c
3372 @@ -686,7 +686,7 @@ void omap_device_delete(struct omap_device *od)
3373 * passes along the return value of omap_device_build_ss().
3374 */
3375 struct platform_device __init *omap_device_build(const char *pdev_name, int pdev_id,
3376 - struct omap_hwmod *oh, void *pdata,
3377 + struct omap_hwmod *oh, const void *pdata,
3378 int pdata_len,
3379 struct omap_device_pm_latency *pm_lats,
3380 int pm_lats_cnt, int is_early_device)
3381 @@ -720,7 +720,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name, int pdev
3382 */
3383 struct platform_device __init *omap_device_build_ss(const char *pdev_name, int pdev_id,
3384 struct omap_hwmod **ohs, int oh_cnt,
3385 - void *pdata, int pdata_len,
3386 + const void *pdata, int pdata_len,
3387 struct omap_device_pm_latency *pm_lats,
3388 int pm_lats_cnt, int is_early_device)
3389 {
3390 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3391 index 0933c59..42b8e2d 100644
3392 --- a/arch/arm/mach-omap2/omap_device.h
3393 +++ b/arch/arm/mach-omap2/omap_device.h
3394 @@ -91,14 +91,14 @@ int omap_device_shutdown(struct platform_device *pdev);
3395 /* Core code interface */
3396
3397 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3398 - struct omap_hwmod *oh, void *pdata,
3399 + struct omap_hwmod *oh, const void *pdata,
3400 int pdata_len,
3401 struct omap_device_pm_latency *pm_lats,
3402 int pm_lats_cnt, int is_early_device);
3403
3404 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3405 struct omap_hwmod **oh, int oh_cnt,
3406 - void *pdata, int pdata_len,
3407 + const void *pdata, int pdata_len,
3408 struct omap_device_pm_latency *pm_lats,
3409 int pm_lats_cnt, int is_early_device);
3410
3411 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3412 index 4653efb..8c60bf7 100644
3413 --- a/arch/arm/mach-omap2/omap_hwmod.c
3414 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3415 @@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
3416 int (*init_clkdm)(struct omap_hwmod *oh);
3417 void (*update_context_lost)(struct omap_hwmod *oh);
3418 int (*get_context_lost)(struct omap_hwmod *oh);
3419 -};
3420 +} __no_const;
3421
3422 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3423 -static struct omap_hwmod_soc_ops soc_ops;
3424 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3425
3426 /* omap_hwmod_list contains all registered struct omap_hwmods */
3427 static LIST_HEAD(omap_hwmod_list);
3428 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3429 index 7c2b4ed..b2ea51f 100644
3430 --- a/arch/arm/mach-omap2/wd_timer.c
3431 +++ b/arch/arm/mach-omap2/wd_timer.c
3432 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3433 struct omap_hwmod *oh;
3434 char *oh_name = "wd_timer2";
3435 char *dev_name = "omap_wdt";
3436 - struct omap_wd_timer_platform_data pdata;
3437 + static struct omap_wd_timer_platform_data pdata = {
3438 + .read_reset_sources = prm_read_reset_sources
3439 + };
3440
3441 if (!cpu_class_is_omap2() || of_have_populated_dt())
3442 return 0;
3443 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3444 return -EINVAL;
3445 }
3446
3447 - pdata.read_reset_sources = prm_read_reset_sources;
3448 -
3449 pdev = omap_device_build(dev_name, id, oh, &pdata,
3450 sizeof(struct omap_wd_timer_platform_data),
3451 NULL, 0, 0);
3452 diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3453 index 6be4c4d..32ac32a 100644
3454 --- a/arch/arm/mach-ux500/include/mach/setup.h
3455 +++ b/arch/arm/mach-ux500/include/mach/setup.h
3456 @@ -38,13 +38,6 @@ extern struct sys_timer ux500_timer;
3457 .type = MT_DEVICE, \
3458 }
3459
3460 -#define __MEM_DEV_DESC(x, sz) { \
3461 - .virtual = IO_ADDRESS(x), \
3462 - .pfn = __phys_to_pfn(x), \
3463 - .length = sz, \
3464 - .type = MT_MEMORY, \
3465 -}
3466 -
3467 extern struct smp_operations ux500_smp_ops;
3468 extern void ux500_cpu_die(unsigned int cpu);
3469
3470 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3471 index 3fd629d..8b1aca9 100644
3472 --- a/arch/arm/mm/Kconfig
3473 +++ b/arch/arm/mm/Kconfig
3474 @@ -425,7 +425,7 @@ config CPU_32v5
3475
3476 config CPU_32v6
3477 bool
3478 - select CPU_USE_DOMAINS if CPU_V6 && MMU
3479 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3480 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3481
3482 config CPU_32v6K
3483 @@ -577,6 +577,7 @@ config CPU_CP15_MPU
3484
3485 config CPU_USE_DOMAINS
3486 bool
3487 + depends on !ARM_LPAE && !PAX_KERNEXEC
3488 help
3489 This option enables or disables the use of domain switching
3490 via the set_fs() function.
3491 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3492 index 5dbf13f..6393f55 100644
3493 --- a/arch/arm/mm/fault.c
3494 +++ b/arch/arm/mm/fault.c
3495 @@ -25,6 +25,7 @@
3496 #include <asm/system_misc.h>
3497 #include <asm/system_info.h>
3498 #include <asm/tlbflush.h>
3499 +#include <asm/sections.h>
3500
3501 #include "fault.h"
3502
3503 @@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3504 if (fixup_exception(regs))
3505 return;
3506
3507 +#ifdef CONFIG_PAX_KERNEXEC
3508 + if ((fsr & FSR_WRITE) &&
3509 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3510 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3511 + {
3512 + if (current->signal->curr_ip)
3513 + 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),
3514 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3515 + else
3516 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3517 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3518 + }
3519 +#endif
3520 +
3521 /*
3522 * No handler, we'll have to terminate things with extreme prejudice.
3523 */
3524 @@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3525 }
3526 #endif
3527
3528 +#ifdef CONFIG_PAX_PAGEEXEC
3529 + if (fsr & FSR_LNX_PF) {
3530 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3531 + do_group_exit(SIGKILL);
3532 + }
3533 +#endif
3534 +
3535 tsk->thread.address = addr;
3536 tsk->thread.error_code = fsr;
3537 tsk->thread.trap_no = 14;
3538 @@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3539 }
3540 #endif /* CONFIG_MMU */
3541
3542 +#ifdef CONFIG_PAX_PAGEEXEC
3543 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3544 +{
3545 + long i;
3546 +
3547 + printk(KERN_ERR "PAX: bytes at PC: ");
3548 + for (i = 0; i < 20; i++) {
3549 + unsigned char c;
3550 + if (get_user(c, (__force unsigned char __user *)pc+i))
3551 + printk(KERN_CONT "?? ");
3552 + else
3553 + printk(KERN_CONT "%02x ", c);
3554 + }
3555 + printk("\n");
3556 +
3557 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3558 + for (i = -1; i < 20; i++) {
3559 + unsigned long c;
3560 + if (get_user(c, (__force unsigned long __user *)sp+i))
3561 + printk(KERN_CONT "???????? ");
3562 + else
3563 + printk(KERN_CONT "%08lx ", c);
3564 + }
3565 + printk("\n");
3566 +}
3567 +#endif
3568 +
3569 /*
3570 * First Level Translation Fault Handler
3571 *
3572 @@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3573 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3574 struct siginfo info;
3575
3576 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3577 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3578 + if (current->signal->curr_ip)
3579 + 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),
3580 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3581 + else
3582 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3583 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3584 + goto die;
3585 + }
3586 +#endif
3587 +
3588 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3589 return;
3590
3591 +die:
3592 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3593 inf->name, fsr, addr);
3594
3595 @@ -575,9 +637,38 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3596 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3597 struct siginfo info;
3598
3599 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3600 + if (!user_mode(regs) && (is_domain_fault(ifsr) || is_xn_fault(ifsr))) {
3601 + if (current->signal->curr_ip)
3602 + 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),
3603 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3604 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3605 + else
3606 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3607 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3608 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3609 + goto die;
3610 + }
3611 +#endif
3612 +
3613 +#ifdef CONFIG_PAX_REFCOUNT
3614 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3615 + unsigned int bkpt;
3616 +
3617 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3618 + current->thread.error_code = ifsr;
3619 + current->thread.trap_no = 0;
3620 + pax_report_refcount_overflow(regs);
3621 + fixup_exception(regs);
3622 + return;
3623 + }
3624 + }
3625 +#endif
3626 +
3627 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3628 return;
3629
3630 +die:
3631 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3632 inf->name, ifsr, addr);
3633
3634 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3635 index cf08bdf..772656c 100644
3636 --- a/arch/arm/mm/fault.h
3637 +++ b/arch/arm/mm/fault.h
3638 @@ -3,6 +3,7 @@
3639
3640 /*
3641 * Fault status register encodings. We steal bit 31 for our own purposes.
3642 + * Set when the FSR value is from an instruction fault.
3643 */
3644 #define FSR_LNX_PF (1 << 31)
3645 #define FSR_WRITE (1 << 11)
3646 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3647 }
3648 #endif
3649
3650 +/* valid for LPAE and !LPAE */
3651 +static inline int is_xn_fault(unsigned int fsr)
3652 +{
3653 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
3654 +}
3655 +
3656 +static inline int is_domain_fault(unsigned int fsr)
3657 +{
3658 + return ((fsr_fs(fsr) & 0xD) == 0x9);
3659 +}
3660 +
3661 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3662 unsigned long search_exception_table(unsigned long addr);
3663
3664 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3665 index ad722f1..763fdd3 100644
3666 --- a/arch/arm/mm/init.c
3667 +++ b/arch/arm/mm/init.c
3668 @@ -30,6 +30,8 @@
3669 #include <asm/setup.h>
3670 #include <asm/tlb.h>
3671 #include <asm/fixmap.h>
3672 +#include <asm/system_info.h>
3673 +#include <asm/cp15.h>
3674
3675 #include <asm/mach/arch.h>
3676 #include <asm/mach/map.h>
3677 @@ -736,7 +738,46 @@ void free_initmem(void)
3678 {
3679 #ifdef CONFIG_HAVE_TCM
3680 extern char __tcm_start, __tcm_end;
3681 +#endif
3682
3683 +#ifdef CONFIG_PAX_KERNEXEC
3684 + unsigned long addr;
3685 + pgd_t *pgd;
3686 + pud_t *pud;
3687 + pmd_t *pmd;
3688 + int cpu_arch = cpu_architecture();
3689 + unsigned int cr = get_cr();
3690 +
3691 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3692 + /* make pages tables, etc before .text NX */
3693 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3694 + pgd = pgd_offset_k(addr);
3695 + pud = pud_offset(pgd, addr);
3696 + pmd = pmd_offset(pud, addr);
3697 + __section_update(pmd, addr, PMD_SECT_XN);
3698 + }
3699 + /* make init NX */
3700 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3701 + pgd = pgd_offset_k(addr);
3702 + pud = pud_offset(pgd, addr);
3703 + pmd = pmd_offset(pud, addr);
3704 + __section_update(pmd, addr, PMD_SECT_XN);
3705 + }
3706 + /* make kernel code/rodata RX */
3707 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3708 + pgd = pgd_offset_k(addr);
3709 + pud = pud_offset(pgd, addr);
3710 + pmd = pmd_offset(pud, addr);
3711 +#ifdef CONFIG_ARM_LPAE
3712 + __section_update(pmd, addr, PMD_SECT_RDONLY);
3713 +#else
3714 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3715 +#endif
3716 + }
3717 + }
3718 +#endif
3719 +
3720 +#ifdef CONFIG_HAVE_TCM
3721 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3722 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3723 __phys_to_pfn(__pa(&__tcm_end)),
3724 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3725 index 88fd86c..7a224ce 100644
3726 --- a/arch/arm/mm/ioremap.c
3727 +++ b/arch/arm/mm/ioremap.c
3728 @@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3729 unsigned int mtype;
3730
3731 if (cached)
3732 - mtype = MT_MEMORY;
3733 + mtype = MT_MEMORY_RX;
3734 else
3735 - mtype = MT_MEMORY_NONCACHED;
3736 + mtype = MT_MEMORY_NONCACHED_RX;
3737
3738 return __arm_ioremap_caller(phys_addr, size, mtype,
3739 __builtin_return_address(0));
3740 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3741 index 10062ce..aa96dd7 100644
3742 --- a/arch/arm/mm/mmap.c
3743 +++ b/arch/arm/mm/mmap.c
3744 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3745 struct vm_area_struct *vma;
3746 int do_align = 0;
3747 int aliasing = cache_is_vipt_aliasing();
3748 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3749 struct vm_unmapped_area_info info;
3750
3751 /*
3752 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3753 if (len > TASK_SIZE)
3754 return -ENOMEM;
3755
3756 +#ifdef CONFIG_PAX_RANDMMAP
3757 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3758 +#endif
3759 +
3760 if (addr) {
3761 if (do_align)
3762 addr = COLOUR_ALIGN(addr, pgoff);
3763 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3764 addr = PAGE_ALIGN(addr);
3765
3766 vma = find_vma(mm, addr);
3767 - if (TASK_SIZE - len >= addr &&
3768 - (!vma || addr + len <= vma->vm_start))
3769 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3770 return addr;
3771 }
3772
3773 @@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3774 unsigned long addr = addr0;
3775 int do_align = 0;
3776 int aliasing = cache_is_vipt_aliasing();
3777 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3778 struct vm_unmapped_area_info info;
3779
3780 /*
3781 @@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3782 return addr;
3783 }
3784
3785 +#ifdef CONFIG_PAX_RANDMMAP
3786 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3787 +#endif
3788 +
3789 /* requesting a specific address */
3790 if (addr) {
3791 if (do_align)
3792 @@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3793 else
3794 addr = PAGE_ALIGN(addr);
3795 vma = find_vma(mm, addr);
3796 - if (TASK_SIZE - len >= addr &&
3797 - (!vma || addr + len <= vma->vm_start))
3798 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3799 return addr;
3800 }
3801
3802 @@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3803 VM_BUG_ON(addr != -ENOMEM);
3804 info.flags = 0;
3805 info.low_limit = mm->mmap_base;
3806 +
3807 +#ifdef CONFIG_PAX_RANDMMAP
3808 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3809 + info.low_limit += mm->delta_mmap;
3810 +#endif
3811 +
3812 info.high_limit = TASK_SIZE;
3813 addr = vm_unmapped_area(&info);
3814 }
3815 @@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3816 {
3817 unsigned long random_factor = 0UL;
3818
3819 +#ifdef CONFIG_PAX_RANDMMAP
3820 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3821 +#endif
3822 +
3823 /* 8 bits of randomness in 20 address space bits */
3824 if ((current->flags & PF_RANDOMIZE) &&
3825 !(current->personality & ADDR_NO_RANDOMIZE))
3826 @@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3827
3828 if (mmap_is_legacy()) {
3829 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3830 +
3831 +#ifdef CONFIG_PAX_RANDMMAP
3832 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3833 + mm->mmap_base += mm->delta_mmap;
3834 +#endif
3835 +
3836 mm->get_unmapped_area = arch_get_unmapped_area;
3837 mm->unmap_area = arch_unmap_area;
3838 } else {
3839 mm->mmap_base = mmap_base(random_factor);
3840 +
3841 +#ifdef CONFIG_PAX_RANDMMAP
3842 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3843 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3844 +#endif
3845 +
3846 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3847 mm->unmap_area = arch_unmap_area_topdown;
3848 }
3849 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3850 index ce328c7..f82bebb 100644
3851 --- a/arch/arm/mm/mmu.c
3852 +++ b/arch/arm/mm/mmu.c
3853 @@ -35,6 +35,23 @@
3854
3855 #include "mm.h"
3856
3857 +
3858 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3859 +void modify_domain(unsigned int dom, unsigned int type)
3860 +{
3861 + struct thread_info *thread = current_thread_info();
3862 + unsigned int domain = thread->cpu_domain;
3863 + /*
3864 + * DOMAIN_MANAGER might be defined to some other value,
3865 + * use the arch-defined constant
3866 + */
3867 + domain &= ~domain_val(dom, 3);
3868 + thread->cpu_domain = domain | domain_val(dom, type);
3869 + set_domain(thread->cpu_domain);
3870 +}
3871 +EXPORT_SYMBOL(modify_domain);
3872 +#endif
3873 +
3874 /*
3875 * empty_zero_page is a special page that is used for
3876 * zero-initialized data and COW.
3877 @@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
3878 }
3879 #endif
3880
3881 -#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
3882 +#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
3883 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
3884
3885 -static struct mem_type mem_types[] = {
3886 +#ifdef CONFIG_PAX_KERNEXEC
3887 +#define L_PTE_KERNEXEC L_PTE_RDONLY
3888 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
3889 +#else
3890 +#define L_PTE_KERNEXEC L_PTE_DIRTY
3891 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
3892 +#endif
3893 +
3894 +static struct mem_type mem_types[] __read_only = {
3895 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
3896 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
3897 L_PTE_SHARED,
3898 @@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
3899 [MT_UNCACHED] = {
3900 .prot_pte = PROT_PTE_DEVICE,
3901 .prot_l1 = PMD_TYPE_TABLE,
3902 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3903 + .prot_sect = PROT_SECT_DEVICE,
3904 .domain = DOMAIN_IO,
3905 },
3906 [MT_CACHECLEAN] = {
3907 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3908 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3909 .domain = DOMAIN_KERNEL,
3910 },
3911 #ifndef CONFIG_ARM_LPAE
3912 [MT_MINICLEAN] = {
3913 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
3914 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
3915 .domain = DOMAIN_KERNEL,
3916 },
3917 #endif
3918 @@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
3919 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3920 L_PTE_RDONLY,
3921 .prot_l1 = PMD_TYPE_TABLE,
3922 - .domain = DOMAIN_USER,
3923 + .domain = DOMAIN_VECTORS,
3924 },
3925 [MT_HIGH_VECTORS] = {
3926 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3927 L_PTE_USER | L_PTE_RDONLY,
3928 .prot_l1 = PMD_TYPE_TABLE,
3929 - .domain = DOMAIN_USER,
3930 + .domain = DOMAIN_VECTORS,
3931 },
3932 - [MT_MEMORY] = {
3933 + [MT_MEMORY_RWX] = {
3934 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3935 .prot_l1 = PMD_TYPE_TABLE,
3936 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3937 .domain = DOMAIN_KERNEL,
3938 },
3939 + [MT_MEMORY_RW] = {
3940 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3941 + .prot_l1 = PMD_TYPE_TABLE,
3942 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3943 + .domain = DOMAIN_KERNEL,
3944 + },
3945 + [MT_MEMORY_RX] = {
3946 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
3947 + .prot_l1 = PMD_TYPE_TABLE,
3948 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3949 + .domain = DOMAIN_KERNEL,
3950 + },
3951 [MT_ROM] = {
3952 - .prot_sect = PMD_TYPE_SECT,
3953 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3954 .domain = DOMAIN_KERNEL,
3955 },
3956 - [MT_MEMORY_NONCACHED] = {
3957 + [MT_MEMORY_NONCACHED_RW] = {
3958 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3959 L_PTE_MT_BUFFERABLE,
3960 .prot_l1 = PMD_TYPE_TABLE,
3961 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3962 .domain = DOMAIN_KERNEL,
3963 },
3964 + [MT_MEMORY_NONCACHED_RX] = {
3965 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
3966 + L_PTE_MT_BUFFERABLE,
3967 + .prot_l1 = PMD_TYPE_TABLE,
3968 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3969 + .domain = DOMAIN_KERNEL,
3970 + },
3971 [MT_MEMORY_DTCM] = {
3972 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3973 - L_PTE_XN,
3974 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3975 .prot_l1 = PMD_TYPE_TABLE,
3976 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3977 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3978 .domain = DOMAIN_KERNEL,
3979 },
3980 [MT_MEMORY_ITCM] = {
3981 @@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
3982 },
3983 [MT_MEMORY_SO] = {
3984 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3985 - L_PTE_MT_UNCACHED | L_PTE_XN,
3986 + L_PTE_MT_UNCACHED,
3987 .prot_l1 = PMD_TYPE_TABLE,
3988 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
3989 - PMD_SECT_UNCACHED | PMD_SECT_XN,
3990 + PMD_SECT_UNCACHED,
3991 .domain = DOMAIN_KERNEL,
3992 },
3993 [MT_MEMORY_DMA_READY] = {
3994 @@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
3995 * to prevent speculative instruction fetches.
3996 */
3997 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
3998 + mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
3999 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4000 + mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4001 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4002 + mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4003 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4004 + mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4005 +
4006 + /* Mark other regions on ARMv6+ as execute-never */
4007 +
4008 +#ifdef CONFIG_PAX_KERNEXEC
4009 + mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4010 + mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4011 + mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4012 + mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4013 +#ifndef CONFIG_ARM_LPAE
4014 + mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4015 + mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4016 +#endif
4017 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4018 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4019 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4020 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4021 + mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4022 + mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4023 +#endif
4024 +
4025 + mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4026 + mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4027 }
4028 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4029 /*
4030 @@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
4031 * from SVC mode and no access from userspace.
4032 */
4033 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4034 +#ifdef CONFIG_PAX_KERNEXEC
4035 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4036 +#endif
4037 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4038 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4039 #endif
4040 @@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
4041 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4042 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4043 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4044 - mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4045 - mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4046 + mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4047 + mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4048 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4049 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4050 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4051 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4052 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4053 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4054 - mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4055 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4056 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4057 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4058 + mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4059 }
4060 }
4061
4062 @@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
4063 if (cpu_arch >= CPU_ARCH_ARMv6) {
4064 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4065 /* Non-cacheable Normal is XCB = 001 */
4066 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4067 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4068 + PMD_SECT_BUFFERED;
4069 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4070 PMD_SECT_BUFFERED;
4071 } else {
4072 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4073 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4074 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4075 + PMD_SECT_TEX(1);
4076 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4077 PMD_SECT_TEX(1);
4078 }
4079 } else {
4080 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4081 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4082 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4083 }
4084
4085 #ifdef CONFIG_ARM_LPAE
4086 @@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
4087 vecs_pgprot |= PTE_EXT_AF;
4088 #endif
4089
4090 + user_pgprot |= __supported_pte_mask;
4091 +
4092 for (i = 0; i < 16; i++) {
4093 pteval_t v = pgprot_val(protection_map[i]);
4094 protection_map[i] = __pgprot(v | user_pgprot);
4095 @@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
4096
4097 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4098 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4099 - mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4100 - mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4101 + mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4102 + mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4103 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4104 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4105 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4106 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4107 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4108 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4109 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4110 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4111 mem_types[MT_ROM].prot_sect |= cp->pmd;
4112
4113 switch (cp->pmd) {
4114 @@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
4115 * called function. This means you can't use any function or debugging
4116 * method which may touch any device, otherwise the kernel _will_ crash.
4117 */
4118 +
4119 +static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4120 +
4121 static void __init devicemaps_init(struct machine_desc *mdesc)
4122 {
4123 struct map_desc map;
4124 unsigned long addr;
4125 - void *vectors;
4126
4127 - /*
4128 - * Allocate the vector page early.
4129 - */
4130 - vectors = early_alloc(PAGE_SIZE);
4131 -
4132 - early_trap_init(vectors);
4133 + early_trap_init(&vectors);
4134
4135 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4136 pmd_clear(pmd_off_k(addr));
4137 @@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4138 * location (0xffff0000). If we aren't using high-vectors, also
4139 * create a mapping at the low-vectors virtual address.
4140 */
4141 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4142 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4143 map.virtual = 0xffff0000;
4144 map.length = PAGE_SIZE;
4145 map.type = MT_HIGH_VECTORS;
4146 @@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
4147 map.pfn = __phys_to_pfn(start);
4148 map.virtual = __phys_to_virt(start);
4149 map.length = end - start;
4150 - map.type = MT_MEMORY;
4151
4152 +#ifdef CONFIG_PAX_KERNEXEC
4153 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4154 + struct map_desc kernel;
4155 + struct map_desc initmap;
4156 +
4157 + /* when freeing initmem we will make this RW */
4158 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4159 + initmap.virtual = (unsigned long)__init_begin;
4160 + initmap.length = _sdata - __init_begin;
4161 + initmap.type = MT_MEMORY_RWX;
4162 + create_mapping(&initmap);
4163 +
4164 + /* when freeing initmem we will make this RX */
4165 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4166 + kernel.virtual = (unsigned long)_stext;
4167 + kernel.length = __init_begin - _stext;
4168 + kernel.type = MT_MEMORY_RWX;
4169 + create_mapping(&kernel);
4170 +
4171 + if (map.virtual < (unsigned long)_stext) {
4172 + map.length = (unsigned long)_stext - map.virtual;
4173 + map.type = MT_MEMORY_RWX;
4174 + create_mapping(&map);
4175 + }
4176 +
4177 + map.pfn = __phys_to_pfn(__pa(_sdata));
4178 + map.virtual = (unsigned long)_sdata;
4179 + map.length = end - __pa(_sdata);
4180 + }
4181 +#endif
4182 +
4183 + map.type = MT_MEMORY_RW;
4184 create_mapping(&map);
4185 }
4186 }
4187 diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4188 index 6d98c13..3cfb174 100644
4189 --- a/arch/arm/mm/proc-v7-2level.S
4190 +++ b/arch/arm/mm/proc-v7-2level.S
4191 @@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4192 tst r1, #L_PTE_XN
4193 orrne r3, r3, #PTE_EXT_XN
4194
4195 + tst r1, #L_PTE_PXN
4196 + orrne r3, r3, #PTE_EXT_PXN
4197 +
4198 tst r1, #L_PTE_YOUNG
4199 tstne r1, #L_PTE_VALID
4200 #ifndef CONFIG_CPU_USE_DOMAINS
4201 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4202 index a5bc92d..0bb4730 100644
4203 --- a/arch/arm/plat-omap/sram.c
4204 +++ b/arch/arm/plat-omap/sram.c
4205 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4206 * Looks like we need to preserve some bootloader code at the
4207 * beginning of SRAM for jumping to flash for reboot to work...
4208 */
4209 + pax_open_kernel();
4210 memset_io(omap_sram_base + omap_sram_skip, 0,
4211 omap_sram_size - omap_sram_skip);
4212 + pax_close_kernel();
4213 }
4214 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4215 index f5144cd..71f6d1f 100644
4216 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4217 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4218 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4219 int (*started)(unsigned ch);
4220 int (*flush)(unsigned ch);
4221 int (*stop)(unsigned ch);
4222 -};
4223 +} __no_const;
4224
4225 extern void *samsung_dmadev_get_ops(void);
4226 extern void *s3c_dma_get_ops(void);
4227 diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4228 index 0c3ba9f..95722b3 100644
4229 --- a/arch/arm64/kernel/debug-monitors.c
4230 +++ b/arch/arm64/kernel/debug-monitors.c
4231 @@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4232 return NOTIFY_OK;
4233 }
4234
4235 -static struct notifier_block __cpuinitdata os_lock_nb = {
4236 +static struct notifier_block os_lock_nb = {
4237 .notifier_call = os_lock_notify,
4238 };
4239
4240 diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4241 index 5ab825c..96aaec8 100644
4242 --- a/arch/arm64/kernel/hw_breakpoint.c
4243 +++ b/arch/arm64/kernel/hw_breakpoint.c
4244 @@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4245 return NOTIFY_OK;
4246 }
4247
4248 -static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4249 +static struct notifier_block hw_breakpoint_reset_nb = {
4250 .notifier_call = hw_breakpoint_reset_notify,
4251 };
4252
4253 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4254 index c3a58a1..78fbf54 100644
4255 --- a/arch/avr32/include/asm/cache.h
4256 +++ b/arch/avr32/include/asm/cache.h
4257 @@ -1,8 +1,10 @@
4258 #ifndef __ASM_AVR32_CACHE_H
4259 #define __ASM_AVR32_CACHE_H
4260
4261 +#include <linux/const.h>
4262 +
4263 #define L1_CACHE_SHIFT 5
4264 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4265 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4266
4267 /*
4268 * Memory returned by kmalloc() may be used for DMA, so we must make
4269 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4270 index e2c3287..6c4f98c 100644
4271 --- a/arch/avr32/include/asm/elf.h
4272 +++ b/arch/avr32/include/asm/elf.h
4273 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4274 the loader. We need to make sure that it is out of the way of the program
4275 that it will "exec", and that there is sufficient room for the brk. */
4276
4277 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4278 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4279
4280 +#ifdef CONFIG_PAX_ASLR
4281 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4282 +
4283 +#define PAX_DELTA_MMAP_LEN 15
4284 +#define PAX_DELTA_STACK_LEN 15
4285 +#endif
4286
4287 /* This yields a mask that user programs can use to figure out what
4288 instruction set this CPU supports. This could be done in user space,
4289 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4290 index 479330b..53717a8 100644
4291 --- a/arch/avr32/include/asm/kmap_types.h
4292 +++ b/arch/avr32/include/asm/kmap_types.h
4293 @@ -2,9 +2,9 @@
4294 #define __ASM_AVR32_KMAP_TYPES_H
4295
4296 #ifdef CONFIG_DEBUG_HIGHMEM
4297 -# define KM_TYPE_NR 29
4298 +# define KM_TYPE_NR 30
4299 #else
4300 -# define KM_TYPE_NR 14
4301 +# define KM_TYPE_NR 15
4302 #endif
4303
4304 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4305 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4306 index b2f2d2d..d1c85cb 100644
4307 --- a/arch/avr32/mm/fault.c
4308 +++ b/arch/avr32/mm/fault.c
4309 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4310
4311 int exception_trace = 1;
4312
4313 +#ifdef CONFIG_PAX_PAGEEXEC
4314 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4315 +{
4316 + unsigned long i;
4317 +
4318 + printk(KERN_ERR "PAX: bytes at PC: ");
4319 + for (i = 0; i < 20; i++) {
4320 + unsigned char c;
4321 + if (get_user(c, (unsigned char *)pc+i))
4322 + printk(KERN_CONT "???????? ");
4323 + else
4324 + printk(KERN_CONT "%02x ", c);
4325 + }
4326 + printk("\n");
4327 +}
4328 +#endif
4329 +
4330 /*
4331 * This routine handles page faults. It determines the address and the
4332 * problem, and then passes it off to one of the appropriate routines.
4333 @@ -174,6 +191,16 @@ bad_area:
4334 up_read(&mm->mmap_sem);
4335
4336 if (user_mode(regs)) {
4337 +
4338 +#ifdef CONFIG_PAX_PAGEEXEC
4339 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4340 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4341 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4342 + do_group_exit(SIGKILL);
4343 + }
4344 + }
4345 +#endif
4346 +
4347 if (exception_trace && printk_ratelimit())
4348 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4349 "sp %08lx ecr %lu\n",
4350 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4351 index 568885a..f8008df 100644
4352 --- a/arch/blackfin/include/asm/cache.h
4353 +++ b/arch/blackfin/include/asm/cache.h
4354 @@ -7,6 +7,7 @@
4355 #ifndef __ARCH_BLACKFIN_CACHE_H
4356 #define __ARCH_BLACKFIN_CACHE_H
4357
4358 +#include <linux/const.h>
4359 #include <linux/linkage.h> /* for asmlinkage */
4360
4361 /*
4362 @@ -14,7 +15,7 @@
4363 * Blackfin loads 32 bytes for cache
4364 */
4365 #define L1_CACHE_SHIFT 5
4366 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4367 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4368 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4369
4370 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4371 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4372 index aea2718..3639a60 100644
4373 --- a/arch/cris/include/arch-v10/arch/cache.h
4374 +++ b/arch/cris/include/arch-v10/arch/cache.h
4375 @@ -1,8 +1,9 @@
4376 #ifndef _ASM_ARCH_CACHE_H
4377 #define _ASM_ARCH_CACHE_H
4378
4379 +#include <linux/const.h>
4380 /* Etrax 100LX have 32-byte cache-lines. */
4381 -#define L1_CACHE_BYTES 32
4382 #define L1_CACHE_SHIFT 5
4383 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4384
4385 #endif /* _ASM_ARCH_CACHE_H */
4386 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4387 index 7caf25d..ee65ac5 100644
4388 --- a/arch/cris/include/arch-v32/arch/cache.h
4389 +++ b/arch/cris/include/arch-v32/arch/cache.h
4390 @@ -1,11 +1,12 @@
4391 #ifndef _ASM_CRIS_ARCH_CACHE_H
4392 #define _ASM_CRIS_ARCH_CACHE_H
4393
4394 +#include <linux/const.h>
4395 #include <arch/hwregs/dma.h>
4396
4397 /* A cache-line is 32 bytes. */
4398 -#define L1_CACHE_BYTES 32
4399 #define L1_CACHE_SHIFT 5
4400 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4401
4402 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4403
4404 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4405 index b86329d..6709906 100644
4406 --- a/arch/frv/include/asm/atomic.h
4407 +++ b/arch/frv/include/asm/atomic.h
4408 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4409 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4410 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4411
4412 +#define atomic64_read_unchecked(v) atomic64_read(v)
4413 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4414 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4415 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4416 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4417 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4418 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4419 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4420 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4421 +
4422 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4423 {
4424 int c, old;
4425 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4426 index 2797163..c2a401d 100644
4427 --- a/arch/frv/include/asm/cache.h
4428 +++ b/arch/frv/include/asm/cache.h
4429 @@ -12,10 +12,11 @@
4430 #ifndef __ASM_CACHE_H
4431 #define __ASM_CACHE_H
4432
4433 +#include <linux/const.h>
4434
4435 /* bytes per L1 cache line */
4436 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4437 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4438 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4439
4440 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4441 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4442 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4443 index 43901f2..0d8b865 100644
4444 --- a/arch/frv/include/asm/kmap_types.h
4445 +++ b/arch/frv/include/asm/kmap_types.h
4446 @@ -2,6 +2,6 @@
4447 #ifndef _ASM_KMAP_TYPES_H
4448 #define _ASM_KMAP_TYPES_H
4449
4450 -#define KM_TYPE_NR 17
4451 +#define KM_TYPE_NR 18
4452
4453 #endif
4454 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4455 index 385fd30..3aaf4fe 100644
4456 --- a/arch/frv/mm/elf-fdpic.c
4457 +++ b/arch/frv/mm/elf-fdpic.c
4458 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4459 {
4460 struct vm_area_struct *vma;
4461 unsigned long limit;
4462 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4463
4464 if (len > TASK_SIZE)
4465 return -ENOMEM;
4466 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4467 if (addr) {
4468 addr = PAGE_ALIGN(addr);
4469 vma = find_vma(current->mm, addr);
4470 - if (TASK_SIZE - len >= addr &&
4471 - (!vma || addr + len <= vma->vm_start))
4472 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4473 goto success;
4474 }
4475
4476 @@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4477 for (; vma; vma = vma->vm_next) {
4478 if (addr > limit)
4479 break;
4480 - if (addr + len <= vma->vm_start)
4481 + if (check_heap_stack_gap(vma, addr, len, offset))
4482 goto success;
4483 addr = vma->vm_end;
4484 }
4485 @@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4486 for (; vma; vma = vma->vm_next) {
4487 if (addr > limit)
4488 break;
4489 - if (addr + len <= vma->vm_start)
4490 + if (check_heap_stack_gap(vma, addr, len, offset))
4491 goto success;
4492 addr = vma->vm_end;
4493 }
4494 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4495 index f4ca594..adc72fd6 100644
4496 --- a/arch/hexagon/include/asm/cache.h
4497 +++ b/arch/hexagon/include/asm/cache.h
4498 @@ -21,9 +21,11 @@
4499 #ifndef __ASM_CACHE_H
4500 #define __ASM_CACHE_H
4501
4502 +#include <linux/const.h>
4503 +
4504 /* Bytes per L1 cache line */
4505 -#define L1_CACHE_SHIFT (5)
4506 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4507 +#define L1_CACHE_SHIFT 5
4508 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4509
4510 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4511 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4512 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4513 index 6e6fe18..a6ae668 100644
4514 --- a/arch/ia64/include/asm/atomic.h
4515 +++ b/arch/ia64/include/asm/atomic.h
4516 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4517 #define atomic64_inc(v) atomic64_add(1, (v))
4518 #define atomic64_dec(v) atomic64_sub(1, (v))
4519
4520 +#define atomic64_read_unchecked(v) atomic64_read(v)
4521 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4522 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4523 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4524 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4525 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4526 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4527 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4528 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4529 +
4530 /* Atomic operations are already serializing */
4531 #define smp_mb__before_atomic_dec() barrier()
4532 #define smp_mb__after_atomic_dec() barrier()
4533 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4534 index 988254a..e1ee885 100644
4535 --- a/arch/ia64/include/asm/cache.h
4536 +++ b/arch/ia64/include/asm/cache.h
4537 @@ -1,6 +1,7 @@
4538 #ifndef _ASM_IA64_CACHE_H
4539 #define _ASM_IA64_CACHE_H
4540
4541 +#include <linux/const.h>
4542
4543 /*
4544 * Copyright (C) 1998-2000 Hewlett-Packard Co
4545 @@ -9,7 +10,7 @@
4546
4547 /* Bytes per L1 (data) cache line. */
4548 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4549 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4550 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4551
4552 #ifdef CONFIG_SMP
4553 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4554 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4555 index b5298eb..67c6e62 100644
4556 --- a/arch/ia64/include/asm/elf.h
4557 +++ b/arch/ia64/include/asm/elf.h
4558 @@ -42,6 +42,13 @@
4559 */
4560 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4561
4562 +#ifdef CONFIG_PAX_ASLR
4563 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4564 +
4565 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4566 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4567 +#endif
4568 +
4569 #define PT_IA_64_UNWIND 0x70000001
4570
4571 /* IA-64 relocations: */
4572 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4573 index 96a8d92..617a1cf 100644
4574 --- a/arch/ia64/include/asm/pgalloc.h
4575 +++ b/arch/ia64/include/asm/pgalloc.h
4576 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4577 pgd_val(*pgd_entry) = __pa(pud);
4578 }
4579
4580 +static inline void
4581 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4582 +{
4583 + pgd_populate(mm, pgd_entry, pud);
4584 +}
4585 +
4586 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4587 {
4588 return quicklist_alloc(0, GFP_KERNEL, NULL);
4589 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4590 pud_val(*pud_entry) = __pa(pmd);
4591 }
4592
4593 +static inline void
4594 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4595 +{
4596 + pud_populate(mm, pud_entry, pmd);
4597 +}
4598 +
4599 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4600 {
4601 return quicklist_alloc(0, GFP_KERNEL, NULL);
4602 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4603 index 815810c..d60bd4c 100644
4604 --- a/arch/ia64/include/asm/pgtable.h
4605 +++ b/arch/ia64/include/asm/pgtable.h
4606 @@ -12,7 +12,7 @@
4607 * David Mosberger-Tang <davidm@hpl.hp.com>
4608 */
4609
4610 -
4611 +#include <linux/const.h>
4612 #include <asm/mman.h>
4613 #include <asm/page.h>
4614 #include <asm/processor.h>
4615 @@ -142,6 +142,17 @@
4616 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4617 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4618 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4619 +
4620 +#ifdef CONFIG_PAX_PAGEEXEC
4621 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4622 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4623 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4624 +#else
4625 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4626 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4627 +# define PAGE_COPY_NOEXEC PAGE_COPY
4628 +#endif
4629 +
4630 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4631 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4632 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4633 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4634 index 54ff557..70c88b7 100644
4635 --- a/arch/ia64/include/asm/spinlock.h
4636 +++ b/arch/ia64/include/asm/spinlock.h
4637 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4638 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4639
4640 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4641 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4642 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4643 }
4644
4645 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4646 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4647 index 449c8c0..50cdf87 100644
4648 --- a/arch/ia64/include/asm/uaccess.h
4649 +++ b/arch/ia64/include/asm/uaccess.h
4650 @@ -42,6 +42,8 @@
4651 #include <asm/pgtable.h>
4652 #include <asm/io.h>
4653
4654 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
4655 +
4656 /*
4657 * For historical reasons, the following macros are grossly misnamed:
4658 */
4659 @@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4660 static inline unsigned long
4661 __copy_to_user (void __user *to, const void *from, unsigned long count)
4662 {
4663 + if (count > INT_MAX)
4664 + return count;
4665 +
4666 + if (!__builtin_constant_p(count))
4667 + check_object_size(from, count, true);
4668 +
4669 return __copy_user(to, (__force void __user *) from, count);
4670 }
4671
4672 static inline unsigned long
4673 __copy_from_user (void *to, const void __user *from, unsigned long count)
4674 {
4675 + if (count > INT_MAX)
4676 + return count;
4677 +
4678 + if (!__builtin_constant_p(count))
4679 + check_object_size(to, count, false);
4680 +
4681 return __copy_user((__force void __user *) to, from, count);
4682 }
4683
4684 @@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4685 ({ \
4686 void __user *__cu_to = (to); \
4687 const void *__cu_from = (from); \
4688 - long __cu_len = (n); \
4689 + unsigned long __cu_len = (n); \
4690 \
4691 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
4692 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4693 + if (!__builtin_constant_p(n)) \
4694 + check_object_size(__cu_from, __cu_len, true); \
4695 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4696 + } \
4697 __cu_len; \
4698 })
4699
4700 @@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4701 ({ \
4702 void *__cu_to = (to); \
4703 const void __user *__cu_from = (from); \
4704 - long __cu_len = (n); \
4705 + unsigned long __cu_len = (n); \
4706 \
4707 __chk_user_ptr(__cu_from); \
4708 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
4709 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4710 + if (!__builtin_constant_p(n)) \
4711 + check_object_size(__cu_to, __cu_len, false); \
4712 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4713 + } \
4714 __cu_len; \
4715 })
4716
4717 diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4718 index 2d67317..07d8bfa 100644
4719 --- a/arch/ia64/kernel/err_inject.c
4720 +++ b/arch/ia64/kernel/err_inject.c
4721 @@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4722 return NOTIFY_OK;
4723 }
4724
4725 -static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4726 +static struct notifier_block err_inject_cpu_notifier =
4727 {
4728 .notifier_call = err_inject_cpu_callback,
4729 };
4730 diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4731 index 65bf9cd..794f06b 100644
4732 --- a/arch/ia64/kernel/mca.c
4733 +++ b/arch/ia64/kernel/mca.c
4734 @@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4735 return NOTIFY_OK;
4736 }
4737
4738 -static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4739 +static struct notifier_block mca_cpu_notifier = {
4740 .notifier_call = mca_cpu_callback
4741 };
4742
4743 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4744 index 24603be..948052d 100644
4745 --- a/arch/ia64/kernel/module.c
4746 +++ b/arch/ia64/kernel/module.c
4747 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4748 void
4749 module_free (struct module *mod, void *module_region)
4750 {
4751 - if (mod && mod->arch.init_unw_table &&
4752 - module_region == mod->module_init) {
4753 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4754 unw_remove_unwind_table(mod->arch.init_unw_table);
4755 mod->arch.init_unw_table = NULL;
4756 }
4757 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4758 }
4759
4760 static inline int
4761 +in_init_rx (const struct module *mod, uint64_t addr)
4762 +{
4763 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4764 +}
4765 +
4766 +static inline int
4767 +in_init_rw (const struct module *mod, uint64_t addr)
4768 +{
4769 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4770 +}
4771 +
4772 +static inline int
4773 in_init (const struct module *mod, uint64_t addr)
4774 {
4775 - return addr - (uint64_t) mod->module_init < mod->init_size;
4776 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4777 +}
4778 +
4779 +static inline int
4780 +in_core_rx (const struct module *mod, uint64_t addr)
4781 +{
4782 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4783 +}
4784 +
4785 +static inline int
4786 +in_core_rw (const struct module *mod, uint64_t addr)
4787 +{
4788 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4789 }
4790
4791 static inline int
4792 in_core (const struct module *mod, uint64_t addr)
4793 {
4794 - return addr - (uint64_t) mod->module_core < mod->core_size;
4795 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4796 }
4797
4798 static inline int
4799 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4800 break;
4801
4802 case RV_BDREL:
4803 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4804 + if (in_init_rx(mod, val))
4805 + val -= (uint64_t) mod->module_init_rx;
4806 + else if (in_init_rw(mod, val))
4807 + val -= (uint64_t) mod->module_init_rw;
4808 + else if (in_core_rx(mod, val))
4809 + val -= (uint64_t) mod->module_core_rx;
4810 + else if (in_core_rw(mod, val))
4811 + val -= (uint64_t) mod->module_core_rw;
4812 break;
4813
4814 case RV_LTV:
4815 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4816 * addresses have been selected...
4817 */
4818 uint64_t gp;
4819 - if (mod->core_size > MAX_LTOFF)
4820 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4821 /*
4822 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4823 * at the end of the module.
4824 */
4825 - gp = mod->core_size - MAX_LTOFF / 2;
4826 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4827 else
4828 - gp = mod->core_size / 2;
4829 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4830 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4831 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4832 mod->arch.gp = gp;
4833 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4834 }
4835 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4836 index 77597e5..6f28f3f 100644
4837 --- a/arch/ia64/kernel/palinfo.c
4838 +++ b/arch/ia64/kernel/palinfo.c
4839 @@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4840 return NOTIFY_OK;
4841 }
4842
4843 -static struct notifier_block __refdata palinfo_cpu_notifier =
4844 +static struct notifier_block palinfo_cpu_notifier =
4845 {
4846 .notifier_call = palinfo_cpu_callback,
4847 .priority = 0,
4848 diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4849 index 79802e5..1a89ec5 100644
4850 --- a/arch/ia64/kernel/salinfo.c
4851 +++ b/arch/ia64/kernel/salinfo.c
4852 @@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4853 return NOTIFY_OK;
4854 }
4855
4856 -static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4857 +static struct notifier_block salinfo_cpu_notifier =
4858 {
4859 .notifier_call = salinfo_cpu_callback,
4860 .priority = 0,
4861 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4862 index d9439ef..d0cac6b 100644
4863 --- a/arch/ia64/kernel/sys_ia64.c
4864 +++ b/arch/ia64/kernel/sys_ia64.c
4865 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4866 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
4867 struct mm_struct *mm = current->mm;
4868 struct vm_area_struct *vma;
4869 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4870
4871 if (len > RGN_MAP_LIMIT)
4872 return -ENOMEM;
4873 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4874 if (REGION_NUMBER(addr) == RGN_HPAGE)
4875 addr = 0;
4876 #endif
4877 +
4878 +#ifdef CONFIG_PAX_RANDMMAP
4879 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4880 + addr = mm->free_area_cache;
4881 + else
4882 +#endif
4883 +
4884 if (!addr)
4885 addr = mm->free_area_cache;
4886
4887 @@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4888 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
4889 /* At this point: (!vma || addr < vma->vm_end). */
4890 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
4891 - if (start_addr != TASK_UNMAPPED_BASE) {
4892 + if (start_addr != mm->mmap_base) {
4893 /* Start a new search --- just in case we missed some holes. */
4894 - addr = TASK_UNMAPPED_BASE;
4895 + addr = mm->mmap_base;
4896 goto full_search;
4897 }
4898 return -ENOMEM;
4899 }
4900 - if (!vma || addr + len <= vma->vm_start) {
4901 + if (check_heap_stack_gap(vma, addr, len, offset)) {
4902 /* Remember the address where we stopped this search: */
4903 mm->free_area_cache = addr + len;
4904 return addr;
4905 diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
4906 index dc00b2c..cce53c2 100644
4907 --- a/arch/ia64/kernel/topology.c
4908 +++ b/arch/ia64/kernel/topology.c
4909 @@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
4910 return NOTIFY_OK;
4911 }
4912
4913 -static struct notifier_block __cpuinitdata cache_cpu_notifier =
4914 +static struct notifier_block cache_cpu_notifier =
4915 {
4916 .notifier_call = cache_cpu_callback
4917 };
4918 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
4919 index 0ccb28f..8992469 100644
4920 --- a/arch/ia64/kernel/vmlinux.lds.S
4921 +++ b/arch/ia64/kernel/vmlinux.lds.S
4922 @@ -198,7 +198,7 @@ SECTIONS {
4923 /* Per-cpu data: */
4924 . = ALIGN(PERCPU_PAGE_SIZE);
4925 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
4926 - __phys_per_cpu_start = __per_cpu_load;
4927 + __phys_per_cpu_start = per_cpu_load;
4928 /*
4929 * ensure percpu data fits
4930 * into percpu page size
4931 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
4932 index 6cf0341..d352594 100644
4933 --- a/arch/ia64/mm/fault.c
4934 +++ b/arch/ia64/mm/fault.c
4935 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
4936 return pte_present(pte);
4937 }
4938
4939 +#ifdef CONFIG_PAX_PAGEEXEC
4940 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4941 +{
4942 + unsigned long i;
4943 +
4944 + printk(KERN_ERR "PAX: bytes at PC: ");
4945 + for (i = 0; i < 8; i++) {
4946 + unsigned int c;
4947 + if (get_user(c, (unsigned int *)pc+i))
4948 + printk(KERN_CONT "???????? ");
4949 + else
4950 + printk(KERN_CONT "%08x ", c);
4951 + }
4952 + printk("\n");
4953 +}
4954 +#endif
4955 +
4956 # define VM_READ_BIT 0
4957 # define VM_WRITE_BIT 1
4958 # define VM_EXEC_BIT 2
4959 @@ -149,8 +166,21 @@ retry:
4960 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
4961 goto bad_area;
4962
4963 - if ((vma->vm_flags & mask) != mask)
4964 + if ((vma->vm_flags & mask) != mask) {
4965 +
4966 +#ifdef CONFIG_PAX_PAGEEXEC
4967 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
4968 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
4969 + goto bad_area;
4970 +
4971 + up_read(&mm->mmap_sem);
4972 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
4973 + do_group_exit(SIGKILL);
4974 + }
4975 +#endif
4976 +
4977 goto bad_area;
4978 + }
4979
4980 /*
4981 * If for any reason at all we couldn't handle the fault, make
4982 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
4983 index 5ca674b..127c3cb 100644
4984 --- a/arch/ia64/mm/hugetlbpage.c
4985 +++ b/arch/ia64/mm/hugetlbpage.c
4986 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4987 unsigned long pgoff, unsigned long flags)
4988 {
4989 struct vm_area_struct *vmm;
4990 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
4991
4992 if (len > RGN_MAP_LIMIT)
4993 return -ENOMEM;
4994 @@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4995 /* At this point: (!vmm || addr < vmm->vm_end). */
4996 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
4997 return -ENOMEM;
4998 - if (!vmm || (addr + len) <= vmm->vm_start)
4999 + if (check_heap_stack_gap(vmm, addr, len, offset))
5000 return addr;
5001 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
5002 }
5003 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5004 index b755ea9..b9a969e 100644
5005 --- a/arch/ia64/mm/init.c
5006 +++ b/arch/ia64/mm/init.c
5007 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5008 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5009 vma->vm_end = vma->vm_start + PAGE_SIZE;
5010 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5011 +
5012 +#ifdef CONFIG_PAX_PAGEEXEC
5013 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5014 + vma->vm_flags &= ~VM_EXEC;
5015 +
5016 +#ifdef CONFIG_PAX_MPROTECT
5017 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5018 + vma->vm_flags &= ~VM_MAYEXEC;
5019 +#endif
5020 +
5021 + }
5022 +#endif
5023 +
5024 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5025 down_write(&current->mm->mmap_sem);
5026 if (insert_vm_struct(current->mm, vma)) {
5027 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5028 index 40b3ee9..8c2c112 100644
5029 --- a/arch/m32r/include/asm/cache.h
5030 +++ b/arch/m32r/include/asm/cache.h
5031 @@ -1,8 +1,10 @@
5032 #ifndef _ASM_M32R_CACHE_H
5033 #define _ASM_M32R_CACHE_H
5034
5035 +#include <linux/const.h>
5036 +
5037 /* L1 cache line size */
5038 #define L1_CACHE_SHIFT 4
5039 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5040 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5041
5042 #endif /* _ASM_M32R_CACHE_H */
5043 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5044 index 82abd15..d95ae5d 100644
5045 --- a/arch/m32r/lib/usercopy.c
5046 +++ b/arch/m32r/lib/usercopy.c
5047 @@ -14,6 +14,9 @@
5048 unsigned long
5049 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5050 {
5051 + if ((long)n < 0)
5052 + return n;
5053 +
5054 prefetch(from);
5055 if (access_ok(VERIFY_WRITE, to, n))
5056 __copy_user(to,from,n);
5057 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5058 unsigned long
5059 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5060 {
5061 + if ((long)n < 0)
5062 + return n;
5063 +
5064 prefetchw(to);
5065 if (access_ok(VERIFY_READ, from, n))
5066 __copy_user_zeroing(to,from,n);
5067 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5068 index 0395c51..5f26031 100644
5069 --- a/arch/m68k/include/asm/cache.h
5070 +++ b/arch/m68k/include/asm/cache.h
5071 @@ -4,9 +4,11 @@
5072 #ifndef __ARCH_M68K_CACHE_H
5073 #define __ARCH_M68K_CACHE_H
5074
5075 +#include <linux/const.h>
5076 +
5077 /* bytes per L1 cache line */
5078 #define L1_CACHE_SHIFT 4
5079 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5080 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5081
5082 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5083
5084 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5085 index 4efe96a..60e8699 100644
5086 --- a/arch/microblaze/include/asm/cache.h
5087 +++ b/arch/microblaze/include/asm/cache.h
5088 @@ -13,11 +13,12 @@
5089 #ifndef _ASM_MICROBLAZE_CACHE_H
5090 #define _ASM_MICROBLAZE_CACHE_H
5091
5092 +#include <linux/const.h>
5093 #include <asm/registers.h>
5094
5095 #define L1_CACHE_SHIFT 5
5096 /* word-granular cache in microblaze */
5097 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5098 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5099
5100 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5101
5102 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5103 index 01cc6ba..bcb7a5d 100644
5104 --- a/arch/mips/include/asm/atomic.h
5105 +++ b/arch/mips/include/asm/atomic.h
5106 @@ -21,6 +21,10 @@
5107 #include <asm/cmpxchg.h>
5108 #include <asm/war.h>
5109
5110 +#ifdef CONFIG_GENERIC_ATOMIC64
5111 +#include <asm-generic/atomic64.h>
5112 +#endif
5113 +
5114 #define ATOMIC_INIT(i) { (i) }
5115
5116 /*
5117 @@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5118 */
5119 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5120
5121 +#define atomic64_read_unchecked(v) atomic64_read(v)
5122 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5123 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5124 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5125 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5126 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5127 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5128 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5129 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5130 +
5131 #endif /* CONFIG_64BIT */
5132
5133 /*
5134 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5135 index b4db69f..8f3b093 100644
5136 --- a/arch/mips/include/asm/cache.h
5137 +++ b/arch/mips/include/asm/cache.h
5138 @@ -9,10 +9,11 @@
5139 #ifndef _ASM_CACHE_H
5140 #define _ASM_CACHE_H
5141
5142 +#include <linux/const.h>
5143 #include <kmalloc.h>
5144
5145 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5146 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5147 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5148
5149 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5150 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5151 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5152 index 455c0ac..ad65fbe 100644
5153 --- a/arch/mips/include/asm/elf.h
5154 +++ b/arch/mips/include/asm/elf.h
5155 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
5156 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5157 #endif
5158
5159 +#ifdef CONFIG_PAX_ASLR
5160 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5161 +
5162 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5163 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5164 +#endif
5165 +
5166 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5167 struct linux_binprm;
5168 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5169 int uses_interp);
5170
5171 -struct mm_struct;
5172 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5173 -#define arch_randomize_brk arch_randomize_brk
5174 -
5175 #endif /* _ASM_ELF_H */
5176 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5177 index c1f6afa..38cc6e9 100644
5178 --- a/arch/mips/include/asm/exec.h
5179 +++ b/arch/mips/include/asm/exec.h
5180 @@ -12,6 +12,6 @@
5181 #ifndef _ASM_EXEC_H
5182 #define _ASM_EXEC_H
5183
5184 -extern unsigned long arch_align_stack(unsigned long sp);
5185 +#define arch_align_stack(x) ((x) & ~0xfUL)
5186
5187 #endif /* _ASM_EXEC_H */
5188 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5189 index dbaec94..6a14935 100644
5190 --- a/arch/mips/include/asm/page.h
5191 +++ b/arch/mips/include/asm/page.h
5192 @@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5193 #ifdef CONFIG_CPU_MIPS32
5194 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5195 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5196 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5197 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5198 #else
5199 typedef struct { unsigned long long pte; } pte_t;
5200 #define pte_val(x) ((x).pte)
5201 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5202 index 881d18b..cea38bc 100644
5203 --- a/arch/mips/include/asm/pgalloc.h
5204 +++ b/arch/mips/include/asm/pgalloc.h
5205 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5206 {
5207 set_pud(pud, __pud((unsigned long)pmd));
5208 }
5209 +
5210 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5211 +{
5212 + pud_populate(mm, pud, pmd);
5213 +}
5214 #endif
5215
5216 /*
5217 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5218 index b2050b9..d71bb1b 100644
5219 --- a/arch/mips/include/asm/thread_info.h
5220 +++ b/arch/mips/include/asm/thread_info.h
5221 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5222 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5223 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5224 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5225 +/* li takes a 32bit immediate */
5226 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5227 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5228
5229 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5230 @@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5231 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5232 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5233 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5234 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5235 +
5236 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5237
5238 /* work to do in syscall_trace_leave() */
5239 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5240 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5241
5242 /* work to do on interrupt/exception return */
5243 #define _TIF_WORK_MASK \
5244 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5245 /* work to do on any return to u-space */
5246 -#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5247 +#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5248
5249 #endif /* __KERNEL__ */
5250
5251 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5252 index 9fdd8bc..4bd7f1a 100644
5253 --- a/arch/mips/kernel/binfmt_elfn32.c
5254 +++ b/arch/mips/kernel/binfmt_elfn32.c
5255 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5256 #undef ELF_ET_DYN_BASE
5257 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5258
5259 +#ifdef CONFIG_PAX_ASLR
5260 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5261 +
5262 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5263 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5264 +#endif
5265 +
5266 #include <asm/processor.h>
5267 #include <linux/module.h>
5268 #include <linux/elfcore.h>
5269 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5270 index ff44823..97f8906 100644
5271 --- a/arch/mips/kernel/binfmt_elfo32.c
5272 +++ b/arch/mips/kernel/binfmt_elfo32.c
5273 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5274 #undef ELF_ET_DYN_BASE
5275 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5276
5277 +#ifdef CONFIG_PAX_ASLR
5278 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5279 +
5280 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5281 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5282 +#endif
5283 +
5284 #include <asm/processor.h>
5285
5286 /*
5287 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5288 index a11c6f9..be5e164 100644
5289 --- a/arch/mips/kernel/process.c
5290 +++ b/arch/mips/kernel/process.c
5291 @@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5292 out:
5293 return pc;
5294 }
5295 -
5296 -/*
5297 - * Don't forget that the stack pointer must be aligned on a 8 bytes
5298 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5299 - */
5300 -unsigned long arch_align_stack(unsigned long sp)
5301 -{
5302 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5303 - sp -= get_random_int() & ~PAGE_MASK;
5304 -
5305 - return sp & ALMASK;
5306 -}
5307 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5308 index 4812c6d..2069554 100644
5309 --- a/arch/mips/kernel/ptrace.c
5310 +++ b/arch/mips/kernel/ptrace.c
5311 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
5312 return arch;
5313 }
5314
5315 +#ifdef CONFIG_GRKERNSEC_SETXID
5316 +extern void gr_delayed_cred_worker(void);
5317 +#endif
5318 +
5319 /*
5320 * Notification of system call entry/exit
5321 * - triggered by current->work.syscall_trace
5322 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5323 /* do the secure computing check first */
5324 secure_computing_strict(regs->regs[2]);
5325
5326 +#ifdef CONFIG_GRKERNSEC_SETXID
5327 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5328 + gr_delayed_cred_worker();
5329 +#endif
5330 +
5331 if (!(current->ptrace & PT_PTRACED))
5332 goto out;
5333
5334 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5335 index d20a4bc..7096ae5 100644
5336 --- a/arch/mips/kernel/scall32-o32.S
5337 +++ b/arch/mips/kernel/scall32-o32.S
5338 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5339
5340 stack_done:
5341 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5342 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5343 + li t1, _TIF_SYSCALL_WORK
5344 and t0, t1
5345 bnez t0, syscall_trace_entry # -> yes
5346
5347 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5348 index b64f642..0fe6eab 100644
5349 --- a/arch/mips/kernel/scall64-64.S
5350 +++ b/arch/mips/kernel/scall64-64.S
5351 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5352
5353 sd a3, PT_R26(sp) # save a3 for syscall restarting
5354
5355 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5356 + li t1, _TIF_SYSCALL_WORK
5357 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5358 and t0, t1, t0
5359 bnez t0, syscall_trace_entry
5360 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5361 index c29ac19..c592d05 100644
5362 --- a/arch/mips/kernel/scall64-n32.S
5363 +++ b/arch/mips/kernel/scall64-n32.S
5364 @@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5365
5366 sd a3, PT_R26(sp) # save a3 for syscall restarting
5367
5368 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5369 + li t1, _TIF_SYSCALL_WORK
5370 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5371 and t0, t1, t0
5372 bnez t0, n32_syscall_trace_entry
5373 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5374 index cf3e75e..72e93fe 100644
5375 --- a/arch/mips/kernel/scall64-o32.S
5376 +++ b/arch/mips/kernel/scall64-o32.S
5377 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5378 PTR 4b, bad_stack
5379 .previous
5380
5381 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5382 + li t1, _TIF_SYSCALL_WORK
5383 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5384 and t0, t1, t0
5385 bnez t0, trace_a_syscall
5386 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5387 index ddcec1e..c7f983e 100644
5388 --- a/arch/mips/mm/fault.c
5389 +++ b/arch/mips/mm/fault.c
5390 @@ -27,6 +27,23 @@
5391 #include <asm/highmem.h> /* For VMALLOC_END */
5392 #include <linux/kdebug.h>
5393
5394 +#ifdef CONFIG_PAX_PAGEEXEC
5395 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5396 +{
5397 + unsigned long i;
5398 +
5399 + printk(KERN_ERR "PAX: bytes at PC: ");
5400 + for (i = 0; i < 5; i++) {
5401 + unsigned int c;
5402 + if (get_user(c, (unsigned int *)pc+i))
5403 + printk(KERN_CONT "???????? ");
5404 + else
5405 + printk(KERN_CONT "%08x ", c);
5406 + }
5407 + printk("\n");
5408 +}
5409 +#endif
5410 +
5411 /*
5412 * This routine handles page faults. It determines the address,
5413 * and the problem, and then passes it off to one of the appropriate
5414 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5415 index 7e5fe27..479a219 100644
5416 --- a/arch/mips/mm/mmap.c
5417 +++ b/arch/mips/mm/mmap.c
5418 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5419 struct vm_area_struct *vma;
5420 unsigned long addr = addr0;
5421 int do_color_align;
5422 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5423 struct vm_unmapped_area_info info;
5424
5425 if (unlikely(len > TASK_SIZE))
5426 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5427 do_color_align = 1;
5428
5429 /* requesting a specific address */
5430 +
5431 +#ifdef CONFIG_PAX_RANDMMAP
5432 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5433 +#endif
5434 +
5435 if (addr) {
5436 if (do_color_align)
5437 addr = COLOUR_ALIGN(addr, pgoff);
5438 @@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5439 addr = PAGE_ALIGN(addr);
5440
5441 vma = find_vma(mm, addr);
5442 - if (TASK_SIZE - len >= addr &&
5443 - (!vma || addr + len <= vma->vm_start))
5444 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5445 return addr;
5446 }
5447
5448 @@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5449 {
5450 unsigned long random_factor = 0UL;
5451
5452 +#ifdef CONFIG_PAX_RANDMMAP
5453 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5454 +#endif
5455 +
5456 if (current->flags & PF_RANDOMIZE) {
5457 random_factor = get_random_int();
5458 random_factor = random_factor << PAGE_SHIFT;
5459 @@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5460
5461 if (mmap_is_legacy()) {
5462 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5463 +
5464 +#ifdef CONFIG_PAX_RANDMMAP
5465 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5466 + mm->mmap_base += mm->delta_mmap;
5467 +#endif
5468 +
5469 mm->get_unmapped_area = arch_get_unmapped_area;
5470 mm->unmap_area = arch_unmap_area;
5471 } else {
5472 mm->mmap_base = mmap_base(random_factor);
5473 +
5474 +#ifdef CONFIG_PAX_RANDMMAP
5475 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5476 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5477 +#endif
5478 +
5479 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5480 mm->unmap_area = arch_unmap_area_topdown;
5481 }
5482 }
5483
5484 -static inline unsigned long brk_rnd(void)
5485 -{
5486 - unsigned long rnd = get_random_int();
5487 -
5488 - rnd = rnd << PAGE_SHIFT;
5489 - /* 8MB for 32bit, 256MB for 64bit */
5490 - if (TASK_IS_32BIT_ADDR)
5491 - rnd = rnd & 0x7ffffful;
5492 - else
5493 - rnd = rnd & 0xffffffful;
5494 -
5495 - return rnd;
5496 -}
5497 -
5498 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5499 -{
5500 - unsigned long base = mm->brk;
5501 - unsigned long ret;
5502 -
5503 - ret = PAGE_ALIGN(base + brk_rnd());
5504 -
5505 - if (ret < mm->brk)
5506 - return mm->brk;
5507 -
5508 - return ret;
5509 -}
5510 -
5511 int __virt_addr_valid(const volatile void *kaddr)
5512 {
5513 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5514 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5515 index 967d144..db12197 100644
5516 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5517 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5518 @@ -11,12 +11,14 @@
5519 #ifndef _ASM_PROC_CACHE_H
5520 #define _ASM_PROC_CACHE_H
5521
5522 +#include <linux/const.h>
5523 +
5524 /* L1 cache */
5525
5526 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5527 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5528 -#define L1_CACHE_BYTES 16 /* bytes per entry */
5529 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5530 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5531 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5532
5533 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5534 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5535 index bcb5df2..84fabd2 100644
5536 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5537 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5538 @@ -16,13 +16,15 @@
5539 #ifndef _ASM_PROC_CACHE_H
5540 #define _ASM_PROC_CACHE_H
5541
5542 +#include <linux/const.h>
5543 +
5544 /*
5545 * L1 cache
5546 */
5547 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5548 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5549 -#define L1_CACHE_BYTES 32 /* bytes per entry */
5550 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5551 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5552 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5553
5554 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5555 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5556 index 4ce7a01..449202a 100644
5557 --- a/arch/openrisc/include/asm/cache.h
5558 +++ b/arch/openrisc/include/asm/cache.h
5559 @@ -19,11 +19,13 @@
5560 #ifndef __ASM_OPENRISC_CACHE_H
5561 #define __ASM_OPENRISC_CACHE_H
5562
5563 +#include <linux/const.h>
5564 +
5565 /* FIXME: How can we replace these with values from the CPU...
5566 * they shouldn't be hard-coded!
5567 */
5568
5569 -#define L1_CACHE_BYTES 16
5570 #define L1_CACHE_SHIFT 4
5571 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5572
5573 #endif /* __ASM_OPENRISC_CACHE_H */
5574 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5575 index af9cf30..2aae9b2 100644
5576 --- a/arch/parisc/include/asm/atomic.h
5577 +++ b/arch/parisc/include/asm/atomic.h
5578 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5579
5580 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5581
5582 +#define atomic64_read_unchecked(v) atomic64_read(v)
5583 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5584 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5585 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5586 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5587 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5588 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5589 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5590 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5591 +
5592 #endif /* !CONFIG_64BIT */
5593
5594
5595 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5596 index 47f11c7..3420df2 100644
5597 --- a/arch/parisc/include/asm/cache.h
5598 +++ b/arch/parisc/include/asm/cache.h
5599 @@ -5,6 +5,7 @@
5600 #ifndef __ARCH_PARISC_CACHE_H
5601 #define __ARCH_PARISC_CACHE_H
5602
5603 +#include <linux/const.h>
5604
5605 /*
5606 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5607 @@ -15,13 +16,13 @@
5608 * just ruin performance.
5609 */
5610 #ifdef CONFIG_PA20
5611 -#define L1_CACHE_BYTES 64
5612 #define L1_CACHE_SHIFT 6
5613 #else
5614 -#define L1_CACHE_BYTES 32
5615 #define L1_CACHE_SHIFT 5
5616 #endif
5617
5618 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5619 +
5620 #ifndef __ASSEMBLY__
5621
5622 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5623 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5624 index 19f6cb1..6c78cf2 100644
5625 --- a/arch/parisc/include/asm/elf.h
5626 +++ b/arch/parisc/include/asm/elf.h
5627 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5628
5629 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5630
5631 +#ifdef CONFIG_PAX_ASLR
5632 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5633 +
5634 +#define PAX_DELTA_MMAP_LEN 16
5635 +#define PAX_DELTA_STACK_LEN 16
5636 +#endif
5637 +
5638 /* This yields a mask that user programs can use to figure out what
5639 instruction set this CPU supports. This could be done in user space,
5640 but it's not easy, and we've already done it here. */
5641 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5642 index fc987a1..6e068ef 100644
5643 --- a/arch/parisc/include/asm/pgalloc.h
5644 +++ b/arch/parisc/include/asm/pgalloc.h
5645 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5646 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5647 }
5648
5649 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5650 +{
5651 + pgd_populate(mm, pgd, pmd);
5652 +}
5653 +
5654 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5655 {
5656 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5657 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5658 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5659 #define pmd_free(mm, x) do { } while (0)
5660 #define pgd_populate(mm, pmd, pte) BUG()
5661 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
5662
5663 #endif
5664
5665 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5666 index 7df49fa..38b62bf 100644
5667 --- a/arch/parisc/include/asm/pgtable.h
5668 +++ b/arch/parisc/include/asm/pgtable.h
5669 @@ -218,6 +218,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5670 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5671 #define PAGE_COPY PAGE_EXECREAD
5672 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5673 +
5674 +#ifdef CONFIG_PAX_PAGEEXEC
5675 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5676 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5677 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5678 +#else
5679 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5680 +# define PAGE_COPY_NOEXEC PAGE_COPY
5681 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5682 +#endif
5683 +
5684 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5685 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5686 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5687 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5688 index 4ba2c93..f5e3974 100644
5689 --- a/arch/parisc/include/asm/uaccess.h
5690 +++ b/arch/parisc/include/asm/uaccess.h
5691 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5692 const void __user *from,
5693 unsigned long n)
5694 {
5695 - int sz = __compiletime_object_size(to);
5696 + size_t sz = __compiletime_object_size(to);
5697 int ret = -EFAULT;
5698
5699 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5700 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5701 ret = __copy_from_user(to, from, n);
5702 else
5703 copy_from_user_overflow();
5704 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5705 index 2a625fb..9908930 100644
5706 --- a/arch/parisc/kernel/module.c
5707 +++ b/arch/parisc/kernel/module.c
5708 @@ -98,16 +98,38 @@
5709
5710 /* three functions to determine where in the module core
5711 * or init pieces the location is */
5712 +static inline int in_init_rx(struct module *me, void *loc)
5713 +{
5714 + return (loc >= me->module_init_rx &&
5715 + loc < (me->module_init_rx + me->init_size_rx));
5716 +}
5717 +
5718 +static inline int in_init_rw(struct module *me, void *loc)
5719 +{
5720 + return (loc >= me->module_init_rw &&
5721 + loc < (me->module_init_rw + me->init_size_rw));
5722 +}
5723 +
5724 static inline int in_init(struct module *me, void *loc)
5725 {
5726 - return (loc >= me->module_init &&
5727 - loc <= (me->module_init + me->init_size));
5728 + return in_init_rx(me, loc) || in_init_rw(me, loc);
5729 +}
5730 +
5731 +static inline int in_core_rx(struct module *me, void *loc)
5732 +{
5733 + return (loc >= me->module_core_rx &&
5734 + loc < (me->module_core_rx + me->core_size_rx));
5735 +}
5736 +
5737 +static inline int in_core_rw(struct module *me, void *loc)
5738 +{
5739 + return (loc >= me->module_core_rw &&
5740 + loc < (me->module_core_rw + me->core_size_rw));
5741 }
5742
5743 static inline int in_core(struct module *me, void *loc)
5744 {
5745 - return (loc >= me->module_core &&
5746 - loc <= (me->module_core + me->core_size));
5747 + return in_core_rx(me, loc) || in_core_rw(me, loc);
5748 }
5749
5750 static inline int in_local(struct module *me, void *loc)
5751 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5752 }
5753
5754 /* align things a bit */
5755 - me->core_size = ALIGN(me->core_size, 16);
5756 - me->arch.got_offset = me->core_size;
5757 - me->core_size += gots * sizeof(struct got_entry);
5758 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
5759 + me->arch.got_offset = me->core_size_rw;
5760 + me->core_size_rw += gots * sizeof(struct got_entry);
5761
5762 - me->core_size = ALIGN(me->core_size, 16);
5763 - me->arch.fdesc_offset = me->core_size;
5764 - me->core_size += fdescs * sizeof(Elf_Fdesc);
5765 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
5766 + me->arch.fdesc_offset = me->core_size_rw;
5767 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5768
5769 me->arch.got_max = gots;
5770 me->arch.fdesc_max = fdescs;
5771 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5772
5773 BUG_ON(value == 0);
5774
5775 - got = me->module_core + me->arch.got_offset;
5776 + got = me->module_core_rw + me->arch.got_offset;
5777 for (i = 0; got[i].addr; i++)
5778 if (got[i].addr == value)
5779 goto out;
5780 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5781 #ifdef CONFIG_64BIT
5782 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5783 {
5784 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5785 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5786
5787 if (!value) {
5788 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5789 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5790
5791 /* Create new one */
5792 fdesc->addr = value;
5793 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5794 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5795 return (Elf_Addr)fdesc;
5796 }
5797 #endif /* CONFIG_64BIT */
5798 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5799
5800 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5801 end = table + sechdrs[me->arch.unwind_section].sh_size;
5802 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5803 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5804
5805 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5806 me->arch.unwind_section, table, end, gp);
5807 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5808 index f76c108..92bad82 100644
5809 --- a/arch/parisc/kernel/sys_parisc.c
5810 +++ b/arch/parisc/kernel/sys_parisc.c
5811 @@ -33,9 +33,11 @@
5812 #include <linux/utsname.h>
5813 #include <linux/personality.h>
5814
5815 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5816 +static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5817 + unsigned long flags)
5818 {
5819 struct vm_area_struct *vma;
5820 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5821
5822 addr = PAGE_ALIGN(addr);
5823
5824 @@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5825 /* At this point: (!vma || addr < vma->vm_end). */
5826 if (TASK_SIZE - len < addr)
5827 return -ENOMEM;
5828 - if (!vma || addr + len <= vma->vm_start)
5829 + if (check_heap_stack_gap(vma, addr, len, offset))
5830 return addr;
5831 addr = vma->vm_end;
5832 }
5833 @@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
5834 return offset & 0x3FF000;
5835 }
5836
5837 -static unsigned long get_shared_area(struct address_space *mapping,
5838 - unsigned long addr, unsigned long len, unsigned long pgoff)
5839 +static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5840 + unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5841 {
5842 struct vm_area_struct *vma;
5843 int offset = mapping ? get_offset(mapping) : 0;
5844 + unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5845
5846 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
5847
5848 @@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5849 /* At this point: (!vma || addr < vma->vm_end). */
5850 if (TASK_SIZE - len < addr)
5851 return -ENOMEM;
5852 - if (!vma || addr + len <= vma->vm_start)
5853 + if (check_heap_stack_gap(vma, addr, len, rand_offset))
5854 return addr;
5855 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
5856 if (addr < vma->vm_end) /* handle wraparound */
5857 @@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5858 if (flags & MAP_FIXED)
5859 return addr;
5860 if (!addr)
5861 - addr = TASK_UNMAPPED_BASE;
5862 + addr = current->mm->mmap_base;
5863
5864 if (filp) {
5865 - addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
5866 + addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
5867 } else if(flags & MAP_SHARED) {
5868 - addr = get_shared_area(NULL, addr, len, pgoff);
5869 + addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
5870 } else {
5871 - addr = get_unshared_area(addr, len);
5872 + addr = get_unshared_area(filp, addr, len, flags);
5873 }
5874 return addr;
5875 }
5876 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
5877 index 45ba99f..8e22c33 100644
5878 --- a/arch/parisc/kernel/traps.c
5879 +++ b/arch/parisc/kernel/traps.c
5880 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
5881
5882 down_read(&current->mm->mmap_sem);
5883 vma = find_vma(current->mm,regs->iaoq[0]);
5884 - if (vma && (regs->iaoq[0] >= vma->vm_start)
5885 - && (vma->vm_flags & VM_EXEC)) {
5886 -
5887 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
5888 fault_address = regs->iaoq[0];
5889 fault_space = regs->iasq[0];
5890
5891 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
5892 index 18162ce..94de376 100644
5893 --- a/arch/parisc/mm/fault.c
5894 +++ b/arch/parisc/mm/fault.c
5895 @@ -15,6 +15,7 @@
5896 #include <linux/sched.h>
5897 #include <linux/interrupt.h>
5898 #include <linux/module.h>
5899 +#include <linux/unistd.h>
5900
5901 #include <asm/uaccess.h>
5902 #include <asm/traps.h>
5903 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
5904 static unsigned long
5905 parisc_acctyp(unsigned long code, unsigned int inst)
5906 {
5907 - if (code == 6 || code == 16)
5908 + if (code == 6 || code == 7 || code == 16)
5909 return VM_EXEC;
5910
5911 switch (inst & 0xf0000000) {
5912 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
5913 }
5914 #endif
5915
5916 +#ifdef CONFIG_PAX_PAGEEXEC
5917 +/*
5918 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
5919 + *
5920 + * returns 1 when task should be killed
5921 + * 2 when rt_sigreturn trampoline was detected
5922 + * 3 when unpatched PLT trampoline was detected
5923 + */
5924 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5925 +{
5926 +
5927 +#ifdef CONFIG_PAX_EMUPLT
5928 + int err;
5929 +
5930 + do { /* PaX: unpatched PLT emulation */
5931 + unsigned int bl, depwi;
5932 +
5933 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
5934 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
5935 +
5936 + if (err)
5937 + break;
5938 +
5939 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
5940 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
5941 +
5942 + err = get_user(ldw, (unsigned int *)addr);
5943 + err |= get_user(bv, (unsigned int *)(addr+4));
5944 + err |= get_user(ldw2, (unsigned int *)(addr+8));
5945 +
5946 + if (err)
5947 + break;
5948 +
5949 + if (ldw == 0x0E801096U &&
5950 + bv == 0xEAC0C000U &&
5951 + ldw2 == 0x0E881095U)
5952 + {
5953 + unsigned int resolver, map;
5954 +
5955 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
5956 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
5957 + if (err)
5958 + break;
5959 +
5960 + regs->gr[20] = instruction_pointer(regs)+8;
5961 + regs->gr[21] = map;
5962 + regs->gr[22] = resolver;
5963 + regs->iaoq[0] = resolver | 3UL;
5964 + regs->iaoq[1] = regs->iaoq[0] + 4;
5965 + return 3;
5966 + }
5967 + }
5968 + } while (0);
5969 +#endif
5970 +
5971 +#ifdef CONFIG_PAX_EMUTRAMP
5972 +
5973 +#ifndef CONFIG_PAX_EMUSIGRT
5974 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
5975 + return 1;
5976 +#endif
5977 +
5978 + do { /* PaX: rt_sigreturn emulation */
5979 + unsigned int ldi1, ldi2, bel, nop;
5980 +
5981 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
5982 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
5983 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
5984 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
5985 +
5986 + if (err)
5987 + break;
5988 +
5989 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
5990 + ldi2 == 0x3414015AU &&
5991 + bel == 0xE4008200U &&
5992 + nop == 0x08000240U)
5993 + {
5994 + regs->gr[25] = (ldi1 & 2) >> 1;
5995 + regs->gr[20] = __NR_rt_sigreturn;
5996 + regs->gr[31] = regs->iaoq[1] + 16;
5997 + regs->sr[0] = regs->iasq[1];
5998 + regs->iaoq[0] = 0x100UL;
5999 + regs->iaoq[1] = regs->iaoq[0] + 4;
6000 + regs->iasq[0] = regs->sr[2];
6001 + regs->iasq[1] = regs->sr[2];
6002 + return 2;
6003 + }
6004 + } while (0);
6005 +#endif
6006 +
6007 + return 1;
6008 +}
6009 +
6010 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6011 +{
6012 + unsigned long i;
6013 +
6014 + printk(KERN_ERR "PAX: bytes at PC: ");
6015 + for (i = 0; i < 5; i++) {
6016 + unsigned int c;
6017 + if (get_user(c, (unsigned int *)pc+i))
6018 + printk(KERN_CONT "???????? ");
6019 + else
6020 + printk(KERN_CONT "%08x ", c);
6021 + }
6022 + printk("\n");
6023 +}
6024 +#endif
6025 +
6026 int fixup_exception(struct pt_regs *regs)
6027 {
6028 const struct exception_table_entry *fix;
6029 @@ -192,8 +303,33 @@ good_area:
6030
6031 acc_type = parisc_acctyp(code,regs->iir);
6032
6033 - if ((vma->vm_flags & acc_type) != acc_type)
6034 + if ((vma->vm_flags & acc_type) != acc_type) {
6035 +
6036 +#ifdef CONFIG_PAX_PAGEEXEC
6037 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6038 + (address & ~3UL) == instruction_pointer(regs))
6039 + {
6040 + up_read(&mm->mmap_sem);
6041 + switch (pax_handle_fetch_fault(regs)) {
6042 +
6043 +#ifdef CONFIG_PAX_EMUPLT
6044 + case 3:
6045 + return;
6046 +#endif
6047 +
6048 +#ifdef CONFIG_PAX_EMUTRAMP
6049 + case 2:
6050 + return;
6051 +#endif
6052 +
6053 + }
6054 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6055 + do_group_exit(SIGKILL);
6056 + }
6057 +#endif
6058 +
6059 goto bad_area;
6060 + }
6061
6062 /*
6063 * If for any reason at all we couldn't handle the fault, make
6064 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6065 index e3b1d41..8e81edf 100644
6066 --- a/arch/powerpc/include/asm/atomic.h
6067 +++ b/arch/powerpc/include/asm/atomic.h
6068 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6069 return t1;
6070 }
6071
6072 +#define atomic64_read_unchecked(v) atomic64_read(v)
6073 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6074 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6075 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6076 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6077 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
6078 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6079 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
6080 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6081 +
6082 #endif /* __powerpc64__ */
6083
6084 #endif /* __KERNEL__ */
6085 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6086 index 9e495c9..b6878e5 100644
6087 --- a/arch/powerpc/include/asm/cache.h
6088 +++ b/arch/powerpc/include/asm/cache.h
6089 @@ -3,6 +3,7 @@
6090
6091 #ifdef __KERNEL__
6092
6093 +#include <linux/const.h>
6094
6095 /* bytes per L1 cache line */
6096 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6097 @@ -22,7 +23,7 @@
6098 #define L1_CACHE_SHIFT 7
6099 #endif
6100
6101 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6102 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6103
6104 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6105
6106 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6107 index 6abf0a1..459d0f1 100644
6108 --- a/arch/powerpc/include/asm/elf.h
6109 +++ b/arch/powerpc/include/asm/elf.h
6110 @@ -28,8 +28,19 @@
6111 the loader. We need to make sure that it is out of the way of the program
6112 that it will "exec", and that there is sufficient room for the brk. */
6113
6114 -extern unsigned long randomize_et_dyn(unsigned long base);
6115 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6116 +#define ELF_ET_DYN_BASE (0x20000000)
6117 +
6118 +#ifdef CONFIG_PAX_ASLR
6119 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6120 +
6121 +#ifdef __powerpc64__
6122 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6123 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6124 +#else
6125 +#define PAX_DELTA_MMAP_LEN 15
6126 +#define PAX_DELTA_STACK_LEN 15
6127 +#endif
6128 +#endif
6129
6130 /*
6131 * Our registers are always unsigned longs, whether we're a 32 bit
6132 @@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6133 (0x7ff >> (PAGE_SHIFT - 12)) : \
6134 (0x3ffff >> (PAGE_SHIFT - 12)))
6135
6136 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6137 -#define arch_randomize_brk arch_randomize_brk
6138 -
6139 -
6140 #ifdef CONFIG_SPU_BASE
6141 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6142 #define NT_SPU 1
6143 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6144 index 8196e9c..d83a9f3 100644
6145 --- a/arch/powerpc/include/asm/exec.h
6146 +++ b/arch/powerpc/include/asm/exec.h
6147 @@ -4,6 +4,6 @@
6148 #ifndef _ASM_POWERPC_EXEC_H
6149 #define _ASM_POWERPC_EXEC_H
6150
6151 -extern unsigned long arch_align_stack(unsigned long sp);
6152 +#define arch_align_stack(x) ((x) & ~0xfUL)
6153
6154 #endif /* _ASM_POWERPC_EXEC_H */
6155 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6156 index 5acabbd..7ea14fa 100644
6157 --- a/arch/powerpc/include/asm/kmap_types.h
6158 +++ b/arch/powerpc/include/asm/kmap_types.h
6159 @@ -10,7 +10,7 @@
6160 * 2 of the License, or (at your option) any later version.
6161 */
6162
6163 -#define KM_TYPE_NR 16
6164 +#define KM_TYPE_NR 17
6165
6166 #endif /* __KERNEL__ */
6167 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6168 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6169 index 8565c25..2865190 100644
6170 --- a/arch/powerpc/include/asm/mman.h
6171 +++ b/arch/powerpc/include/asm/mman.h
6172 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6173 }
6174 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6175
6176 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6177 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6178 {
6179 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6180 }
6181 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6182 index f072e97..b436dee 100644
6183 --- a/arch/powerpc/include/asm/page.h
6184 +++ b/arch/powerpc/include/asm/page.h
6185 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6186 * and needs to be executable. This means the whole heap ends
6187 * up being executable.
6188 */
6189 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6190 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6191 +#define VM_DATA_DEFAULT_FLAGS32 \
6192 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6193 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6194
6195 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6196 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6197 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6198 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6199 #endif
6200
6201 +#define ktla_ktva(addr) (addr)
6202 +#define ktva_ktla(addr) (addr)
6203 +
6204 /*
6205 * Use the top bit of the higher-level page table entries to indicate whether
6206 * the entries we point to contain hugepages. This works because we know that
6207 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6208 index cd915d6..c10cee8 100644
6209 --- a/arch/powerpc/include/asm/page_64.h
6210 +++ b/arch/powerpc/include/asm/page_64.h
6211 @@ -154,15 +154,18 @@ do { \
6212 * stack by default, so in the absence of a PT_GNU_STACK program header
6213 * we turn execute permission off.
6214 */
6215 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6216 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6217 +#define VM_STACK_DEFAULT_FLAGS32 \
6218 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6219 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6220
6221 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6222 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6223
6224 +#ifndef CONFIG_PAX_PAGEEXEC
6225 #define VM_STACK_DEFAULT_FLAGS \
6226 (is_32bit_task() ? \
6227 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6228 +#endif
6229
6230 #include <asm-generic/getorder.h>
6231
6232 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6233 index 292725c..f87ae14 100644
6234 --- a/arch/powerpc/include/asm/pgalloc-64.h
6235 +++ b/arch/powerpc/include/asm/pgalloc-64.h
6236 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6237 #ifndef CONFIG_PPC_64K_PAGES
6238
6239 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6240 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6241
6242 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6243 {
6244 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6245 pud_set(pud, (unsigned long)pmd);
6246 }
6247
6248 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6249 +{
6250 + pud_populate(mm, pud, pmd);
6251 +}
6252 +
6253 #define pmd_populate(mm, pmd, pte_page) \
6254 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6255 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6256 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6257 #else /* CONFIG_PPC_64K_PAGES */
6258
6259 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6260 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6261
6262 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6263 pte_t *pte)
6264 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6265 index a9cbd3b..3b67efa 100644
6266 --- a/arch/powerpc/include/asm/pgtable.h
6267 +++ b/arch/powerpc/include/asm/pgtable.h
6268 @@ -2,6 +2,7 @@
6269 #define _ASM_POWERPC_PGTABLE_H
6270 #ifdef __KERNEL__
6271
6272 +#include <linux/const.h>
6273 #ifndef __ASSEMBLY__
6274 #include <asm/processor.h> /* For TASK_SIZE */
6275 #include <asm/mmu.h>
6276 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6277 index 4aad413..85d86bf 100644
6278 --- a/arch/powerpc/include/asm/pte-hash32.h
6279 +++ b/arch/powerpc/include/asm/pte-hash32.h
6280 @@ -21,6 +21,7 @@
6281 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6282 #define _PAGE_USER 0x004 /* usermode access allowed */
6283 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6284 +#define _PAGE_EXEC _PAGE_GUARDED
6285 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6286 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6287 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6288 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6289 index 3d5c9dc..62f8414 100644
6290 --- a/arch/powerpc/include/asm/reg.h
6291 +++ b/arch/powerpc/include/asm/reg.h
6292 @@ -215,6 +215,7 @@
6293 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6294 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6295 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6296 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6297 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6298 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6299 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6300 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6301 index 406b7b9..af63426 100644
6302 --- a/arch/powerpc/include/asm/thread_info.h
6303 +++ b/arch/powerpc/include/asm/thread_info.h
6304 @@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6305 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6306 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6307 #define TIF_SINGLESTEP 8 /* singlestepping active */
6308 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6309 #define TIF_SECCOMP 10 /* secure computing */
6310 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6311 #define TIF_NOERROR 12 /* Force successful syscall return */
6312 @@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6313 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6314 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6315 for stack store? */
6316 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6317 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6318 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6319
6320 /* as above, but as bit values */
6321 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6322 @@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6323 #define _TIF_UPROBE (1<<TIF_UPROBE)
6324 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6325 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6326 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6327 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6328 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6329 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6330 + _TIF_GRSEC_SETXID)
6331
6332 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6333 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6334 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6335 index 4db4959..335e00c 100644
6336 --- a/arch/powerpc/include/asm/uaccess.h
6337 +++ b/arch/powerpc/include/asm/uaccess.h
6338 @@ -13,6 +13,8 @@
6339 #define VERIFY_READ 0
6340 #define VERIFY_WRITE 1
6341
6342 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
6343 +
6344 /*
6345 * The fs value determines whether argument validity checking should be
6346 * performed or not. If get_fs() == USER_DS, checking is performed, with
6347 @@ -318,52 +320,6 @@ do { \
6348 extern unsigned long __copy_tofrom_user(void __user *to,
6349 const void __user *from, unsigned long size);
6350
6351 -#ifndef __powerpc64__
6352 -
6353 -static inline unsigned long copy_from_user(void *to,
6354 - const void __user *from, unsigned long n)
6355 -{
6356 - unsigned long over;
6357 -
6358 - if (access_ok(VERIFY_READ, from, n))
6359 - return __copy_tofrom_user((__force void __user *)to, from, n);
6360 - if ((unsigned long)from < TASK_SIZE) {
6361 - over = (unsigned long)from + n - TASK_SIZE;
6362 - return __copy_tofrom_user((__force void __user *)to, from,
6363 - n - over) + over;
6364 - }
6365 - return n;
6366 -}
6367 -
6368 -static inline unsigned long copy_to_user(void __user *to,
6369 - const void *from, unsigned long n)
6370 -{
6371 - unsigned long over;
6372 -
6373 - if (access_ok(VERIFY_WRITE, to, n))
6374 - return __copy_tofrom_user(to, (__force void __user *)from, n);
6375 - if ((unsigned long)to < TASK_SIZE) {
6376 - over = (unsigned long)to + n - TASK_SIZE;
6377 - return __copy_tofrom_user(to, (__force void __user *)from,
6378 - n - over) + over;
6379 - }
6380 - return n;
6381 -}
6382 -
6383 -#else /* __powerpc64__ */
6384 -
6385 -#define __copy_in_user(to, from, size) \
6386 - __copy_tofrom_user((to), (from), (size))
6387 -
6388 -extern unsigned long copy_from_user(void *to, const void __user *from,
6389 - unsigned long n);
6390 -extern unsigned long copy_to_user(void __user *to, const void *from,
6391 - unsigned long n);
6392 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
6393 - unsigned long n);
6394 -
6395 -#endif /* __powerpc64__ */
6396 -
6397 static inline unsigned long __copy_from_user_inatomic(void *to,
6398 const void __user *from, unsigned long n)
6399 {
6400 @@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6401 if (ret == 0)
6402 return 0;
6403 }
6404 +
6405 + if (!__builtin_constant_p(n))
6406 + check_object_size(to, n, false);
6407 +
6408 return __copy_tofrom_user((__force void __user *)to, from, n);
6409 }
6410
6411 @@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6412 if (ret == 0)
6413 return 0;
6414 }
6415 +
6416 + if (!__builtin_constant_p(n))
6417 + check_object_size(from, n, true);
6418 +
6419 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6420 }
6421
6422 @@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6423 return __copy_to_user_inatomic(to, from, size);
6424 }
6425
6426 +#ifndef __powerpc64__
6427 +
6428 +static inline unsigned long __must_check copy_from_user(void *to,
6429 + const void __user *from, unsigned long n)
6430 +{
6431 + unsigned long over;
6432 +
6433 + if ((long)n < 0)
6434 + return n;
6435 +
6436 + if (access_ok(VERIFY_READ, from, n)) {
6437 + if (!__builtin_constant_p(n))
6438 + check_object_size(to, n, false);
6439 + return __copy_tofrom_user((__force void __user *)to, from, n);
6440 + }
6441 + if ((unsigned long)from < TASK_SIZE) {
6442 + over = (unsigned long)from + n - TASK_SIZE;
6443 + if (!__builtin_constant_p(n - over))
6444 + check_object_size(to, n - over, false);
6445 + return __copy_tofrom_user((__force void __user *)to, from,
6446 + n - over) + over;
6447 + }
6448 + return n;
6449 +}
6450 +
6451 +static inline unsigned long __must_check copy_to_user(void __user *to,
6452 + const void *from, unsigned long n)
6453 +{
6454 + unsigned long over;
6455 +
6456 + if ((long)n < 0)
6457 + return n;
6458 +
6459 + if (access_ok(VERIFY_WRITE, to, n)) {
6460 + if (!__builtin_constant_p(n))
6461 + check_object_size(from, n, true);
6462 + return __copy_tofrom_user(to, (__force void __user *)from, n);
6463 + }
6464 + if ((unsigned long)to < TASK_SIZE) {
6465 + over = (unsigned long)to + n - TASK_SIZE;
6466 + if (!__builtin_constant_p(n))
6467 + check_object_size(from, n - over, true);
6468 + return __copy_tofrom_user(to, (__force void __user *)from,
6469 + n - over) + over;
6470 + }
6471 + return n;
6472 +}
6473 +
6474 +#else /* __powerpc64__ */
6475 +
6476 +#define __copy_in_user(to, from, size) \
6477 + __copy_tofrom_user((to), (from), (size))
6478 +
6479 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6480 +{
6481 + if ((long)n < 0 || n > INT_MAX)
6482 + return n;
6483 +
6484 + if (!__builtin_constant_p(n))
6485 + check_object_size(to, n, false);
6486 +
6487 + if (likely(access_ok(VERIFY_READ, from, n)))
6488 + n = __copy_from_user(to, from, n);
6489 + else
6490 + memset(to, 0, n);
6491 + return n;
6492 +}
6493 +
6494 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6495 +{
6496 + if ((long)n < 0 || n > INT_MAX)
6497 + return n;
6498 +
6499 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
6500 + if (!__builtin_constant_p(n))
6501 + check_object_size(from, n, true);
6502 + n = __copy_to_user(to, from, n);
6503 + }
6504 + return n;
6505 +}
6506 +
6507 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
6508 + unsigned long n);
6509 +
6510 +#endif /* __powerpc64__ */
6511 +
6512 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6513
6514 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6515 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6516 index 4684e33..acc4d19e 100644
6517 --- a/arch/powerpc/kernel/exceptions-64e.S
6518 +++ b/arch/powerpc/kernel/exceptions-64e.S
6519 @@ -715,6 +715,7 @@ storage_fault_common:
6520 std r14,_DAR(r1)
6521 std r15,_DSISR(r1)
6522 addi r3,r1,STACK_FRAME_OVERHEAD
6523 + bl .save_nvgprs
6524 mr r4,r14
6525 mr r5,r15
6526 ld r14,PACA_EXGEN+EX_R14(r13)
6527 @@ -723,8 +724,7 @@ storage_fault_common:
6528 cmpdi r3,0
6529 bne- 1f
6530 b .ret_from_except_lite
6531 -1: bl .save_nvgprs
6532 - mr r5,r3
6533 +1: mr r5,r3
6534 addi r3,r1,STACK_FRAME_OVERHEAD
6535 ld r4,_DAR(r1)
6536 bl .bad_page_fault
6537 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6538 index 4665e82..080ea99 100644
6539 --- a/arch/powerpc/kernel/exceptions-64s.S
6540 +++ b/arch/powerpc/kernel/exceptions-64s.S
6541 @@ -1206,10 +1206,10 @@ handle_page_fault:
6542 11: ld r4,_DAR(r1)
6543 ld r5,_DSISR(r1)
6544 addi r3,r1,STACK_FRAME_OVERHEAD
6545 + bl .save_nvgprs
6546 bl .do_page_fault
6547 cmpdi r3,0
6548 beq+ 12f
6549 - bl .save_nvgprs
6550 mr r5,r3
6551 addi r3,r1,STACK_FRAME_OVERHEAD
6552 lwz r4,_DAR(r1)
6553 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6554 index 2e3200c..72095ce 100644
6555 --- a/arch/powerpc/kernel/module_32.c
6556 +++ b/arch/powerpc/kernel/module_32.c
6557 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6558 me->arch.core_plt_section = i;
6559 }
6560 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6561 - printk("Module doesn't contain .plt or .init.plt sections.\n");
6562 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6563 return -ENOEXEC;
6564 }
6565
6566 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6567
6568 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6569 /* Init, or core PLT? */
6570 - if (location >= mod->module_core
6571 - && location < mod->module_core + mod->core_size)
6572 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6573 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6574 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6575 - else
6576 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6577 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6578 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6579 + else {
6580 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6581 + return ~0UL;
6582 + }
6583
6584 /* Find this entry, or if that fails, the next avail. entry */
6585 while (entry->jump[0]) {
6586 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6587 index 8143067..21ae55b 100644
6588 --- a/arch/powerpc/kernel/process.c
6589 +++ b/arch/powerpc/kernel/process.c
6590 @@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
6591 * Lookup NIP late so we have the best change of getting the
6592 * above info out without failing
6593 */
6594 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6595 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6596 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6597 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6598 #endif
6599 show_stack(current, (unsigned long *) regs->gpr[1]);
6600 if (!user_mode(regs))
6601 @@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6602 newsp = stack[0];
6603 ip = stack[STACK_FRAME_LR_SAVE];
6604 if (!firstframe || ip != lr) {
6605 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6606 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6607 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6608 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6609 - printk(" (%pS)",
6610 + printk(" (%pA)",
6611 (void *)current->ret_stack[curr_frame].ret);
6612 curr_frame--;
6613 }
6614 @@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6615 struct pt_regs *regs = (struct pt_regs *)
6616 (sp + STACK_FRAME_OVERHEAD);
6617 lr = regs->link;
6618 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
6619 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
6620 regs->trap, (void *)regs->nip, (void *)lr);
6621 firstframe = 1;
6622 }
6623 @@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
6624 mtspr(SPRN_CTRLT, ctrl);
6625 }
6626 #endif /* CONFIG_PPC64 */
6627 -
6628 -unsigned long arch_align_stack(unsigned long sp)
6629 -{
6630 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6631 - sp -= get_random_int() & ~PAGE_MASK;
6632 - return sp & ~0xf;
6633 -}
6634 -
6635 -static inline unsigned long brk_rnd(void)
6636 -{
6637 - unsigned long rnd = 0;
6638 -
6639 - /* 8MB for 32bit, 1GB for 64bit */
6640 - if (is_32bit_task())
6641 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6642 - else
6643 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6644 -
6645 - return rnd << PAGE_SHIFT;
6646 -}
6647 -
6648 -unsigned long arch_randomize_brk(struct mm_struct *mm)
6649 -{
6650 - unsigned long base = mm->brk;
6651 - unsigned long ret;
6652 -
6653 -#ifdef CONFIG_PPC_STD_MMU_64
6654 - /*
6655 - * If we are using 1TB segments and we are allowed to randomise
6656 - * the heap, we can put it above 1TB so it is backed by a 1TB
6657 - * segment. Otherwise the heap will be in the bottom 1TB
6658 - * which always uses 256MB segments and this may result in a
6659 - * performance penalty.
6660 - */
6661 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6662 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6663 -#endif
6664 -
6665 - ret = PAGE_ALIGN(base + brk_rnd());
6666 -
6667 - if (ret < mm->brk)
6668 - return mm->brk;
6669 -
6670 - return ret;
6671 -}
6672 -
6673 -unsigned long randomize_et_dyn(unsigned long base)
6674 -{
6675 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6676 -
6677 - if (ret < base)
6678 - return base;
6679 -
6680 - return ret;
6681 -}
6682 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6683 index c497000..8fde506 100644
6684 --- a/arch/powerpc/kernel/ptrace.c
6685 +++ b/arch/powerpc/kernel/ptrace.c
6686 @@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
6687 return ret;
6688 }
6689
6690 +#ifdef CONFIG_GRKERNSEC_SETXID
6691 +extern void gr_delayed_cred_worker(void);
6692 +#endif
6693 +
6694 /*
6695 * We must return the syscall number to actually look up in the table.
6696 * This can be -1L to skip running any syscall at all.
6697 @@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6698
6699 secure_computing_strict(regs->gpr[0]);
6700
6701 +#ifdef CONFIG_GRKERNSEC_SETXID
6702 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6703 + gr_delayed_cred_worker();
6704 +#endif
6705 +
6706 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6707 tracehook_report_syscall_entry(regs))
6708 /*
6709 @@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6710 {
6711 int step;
6712
6713 +#ifdef CONFIG_GRKERNSEC_SETXID
6714 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6715 + gr_delayed_cred_worker();
6716 +#endif
6717 +
6718 audit_syscall_exit(regs);
6719
6720 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6721 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6722 index 804e323..79181c1 100644
6723 --- a/arch/powerpc/kernel/signal_32.c
6724 +++ b/arch/powerpc/kernel/signal_32.c
6725 @@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6726 /* Save user registers on the stack */
6727 frame = &rt_sf->uc.uc_mcontext;
6728 addr = frame;
6729 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6730 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6731 if (save_user_regs(regs, frame, 0, 1))
6732 goto badframe;
6733 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6734 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6735 index 1ca045d..139c3f7 100644
6736 --- a/arch/powerpc/kernel/signal_64.c
6737 +++ b/arch/powerpc/kernel/signal_64.c
6738 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6739 current->thread.fpscr.val = 0;
6740
6741 /* Set up to return from userspace. */
6742 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6743 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6744 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6745 } else {
6746 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6747 diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6748 index 3ce1f86..c30e629 100644
6749 --- a/arch/powerpc/kernel/sysfs.c
6750 +++ b/arch/powerpc/kernel/sysfs.c
6751 @@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6752 return NOTIFY_OK;
6753 }
6754
6755 -static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6756 +static struct notifier_block sysfs_cpu_nb = {
6757 .notifier_call = sysfs_cpu_notify,
6758 };
6759
6760 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6761 index 3251840..3f7c77a 100644
6762 --- a/arch/powerpc/kernel/traps.c
6763 +++ b/arch/powerpc/kernel/traps.c
6764 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6765 return flags;
6766 }
6767
6768 +extern void gr_handle_kernel_exploit(void);
6769 +
6770 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6771 int signr)
6772 {
6773 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6774 panic("Fatal exception in interrupt");
6775 if (panic_on_oops)
6776 panic("Fatal exception");
6777 +
6778 + gr_handle_kernel_exploit();
6779 +
6780 do_exit(signr);
6781 }
6782
6783 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6784 index 1b2076f..835e4be 100644
6785 --- a/arch/powerpc/kernel/vdso.c
6786 +++ b/arch/powerpc/kernel/vdso.c
6787 @@ -34,6 +34,7 @@
6788 #include <asm/firmware.h>
6789 #include <asm/vdso.h>
6790 #include <asm/vdso_datapage.h>
6791 +#include <asm/mman.h>
6792
6793 #include "setup.h"
6794
6795 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6796 vdso_base = VDSO32_MBASE;
6797 #endif
6798
6799 - current->mm->context.vdso_base = 0;
6800 + current->mm->context.vdso_base = ~0UL;
6801
6802 /* vDSO has a problem and was disabled, just don't "enable" it for the
6803 * process
6804 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6805 vdso_base = get_unmapped_area(NULL, vdso_base,
6806 (vdso_pages << PAGE_SHIFT) +
6807 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6808 - 0, 0);
6809 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
6810 if (IS_ERR_VALUE(vdso_base)) {
6811 rc = vdso_base;
6812 goto fail_mmapsem;
6813 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6814 index 5eea6f3..5d10396 100644
6815 --- a/arch/powerpc/lib/usercopy_64.c
6816 +++ b/arch/powerpc/lib/usercopy_64.c
6817 @@ -9,22 +9,6 @@
6818 #include <linux/module.h>
6819 #include <asm/uaccess.h>
6820
6821 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6822 -{
6823 - if (likely(access_ok(VERIFY_READ, from, n)))
6824 - n = __copy_from_user(to, from, n);
6825 - else
6826 - memset(to, 0, n);
6827 - return n;
6828 -}
6829 -
6830 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6831 -{
6832 - if (likely(access_ok(VERIFY_WRITE, to, n)))
6833 - n = __copy_to_user(to, from, n);
6834 - return n;
6835 -}
6836 -
6837 unsigned long copy_in_user(void __user *to, const void __user *from,
6838 unsigned long n)
6839 {
6840 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6841 return n;
6842 }
6843
6844 -EXPORT_SYMBOL(copy_from_user);
6845 -EXPORT_SYMBOL(copy_to_user);
6846 EXPORT_SYMBOL(copy_in_user);
6847
6848 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6849 index 3a8489a..6a63b3b 100644
6850 --- a/arch/powerpc/mm/fault.c
6851 +++ b/arch/powerpc/mm/fault.c
6852 @@ -32,6 +32,10 @@
6853 #include <linux/perf_event.h>
6854 #include <linux/magic.h>
6855 #include <linux/ratelimit.h>
6856 +#include <linux/slab.h>
6857 +#include <linux/pagemap.h>
6858 +#include <linux/compiler.h>
6859 +#include <linux/unistd.h>
6860
6861 #include <asm/firmware.h>
6862 #include <asm/page.h>
6863 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
6864 }
6865 #endif
6866
6867 +#ifdef CONFIG_PAX_PAGEEXEC
6868 +/*
6869 + * PaX: decide what to do with offenders (regs->nip = fault address)
6870 + *
6871 + * returns 1 when task should be killed
6872 + */
6873 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6874 +{
6875 + return 1;
6876 +}
6877 +
6878 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6879 +{
6880 + unsigned long i;
6881 +
6882 + printk(KERN_ERR "PAX: bytes at PC: ");
6883 + for (i = 0; i < 5; i++) {
6884 + unsigned int c;
6885 + if (get_user(c, (unsigned int __user *)pc+i))
6886 + printk(KERN_CONT "???????? ");
6887 + else
6888 + printk(KERN_CONT "%08x ", c);
6889 + }
6890 + printk("\n");
6891 +}
6892 +#endif
6893 +
6894 /*
6895 * Check whether the instruction at regs->nip is a store using
6896 * an update addressing form which will update r1.
6897 @@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
6898 * indicate errors in DSISR but can validly be set in SRR1.
6899 */
6900 if (trap == 0x400)
6901 - error_code &= 0x48200000;
6902 + error_code &= 0x58200000;
6903 else
6904 is_write = error_code & DSISR_ISSTORE;
6905 #else
6906 @@ -364,7 +395,7 @@ good_area:
6907 * "undefined". Of those that can be set, this is the only
6908 * one which seems bad.
6909 */
6910 - if (error_code & 0x10000000)
6911 + if (error_code & DSISR_GUARDED)
6912 /* Guarded storage error. */
6913 goto bad_area;
6914 #endif /* CONFIG_8xx */
6915 @@ -379,7 +410,7 @@ good_area:
6916 * processors use the same I/D cache coherency mechanism
6917 * as embedded.
6918 */
6919 - if (error_code & DSISR_PROTFAULT)
6920 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
6921 goto bad_area;
6922 #endif /* CONFIG_PPC_STD_MMU */
6923
6924 @@ -462,6 +493,23 @@ bad_area:
6925 bad_area_nosemaphore:
6926 /* User mode accesses cause a SIGSEGV */
6927 if (user_mode(regs)) {
6928 +
6929 +#ifdef CONFIG_PAX_PAGEEXEC
6930 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
6931 +#ifdef CONFIG_PPC_STD_MMU
6932 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
6933 +#else
6934 + if (is_exec && regs->nip == address) {
6935 +#endif
6936 + switch (pax_handle_fetch_fault(regs)) {
6937 + }
6938 +
6939 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
6940 + do_group_exit(SIGKILL);
6941 + }
6942 + }
6943 +#endif
6944 +
6945 _exception(SIGSEGV, regs, code, address);
6946 return 0;
6947 }
6948 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
6949 index 67a42ed..cd463e0 100644
6950 --- a/arch/powerpc/mm/mmap_64.c
6951 +++ b/arch/powerpc/mm/mmap_64.c
6952 @@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
6953 {
6954 unsigned long rnd = 0;
6955
6956 +#ifdef CONFIG_PAX_RANDMMAP
6957 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6958 +#endif
6959 +
6960 if (current->flags & PF_RANDOMIZE) {
6961 /* 8MB for 32bit, 1GB for 64bit */
6962 if (is_32bit_task())
6963 @@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6964 */
6965 if (mmap_is_legacy()) {
6966 mm->mmap_base = TASK_UNMAPPED_BASE;
6967 +
6968 +#ifdef CONFIG_PAX_RANDMMAP
6969 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6970 + mm->mmap_base += mm->delta_mmap;
6971 +#endif
6972 +
6973 mm->get_unmapped_area = arch_get_unmapped_area;
6974 mm->unmap_area = arch_unmap_area;
6975 } else {
6976 mm->mmap_base = mmap_base();
6977 +
6978 +#ifdef CONFIG_PAX_RANDMMAP
6979 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6980 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6981 +#endif
6982 +
6983 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6984 mm->unmap_area = arch_unmap_area_topdown;
6985 }
6986 diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
6987 index e779642..e5bb889 100644
6988 --- a/arch/powerpc/mm/mmu_context_nohash.c
6989 +++ b/arch/powerpc/mm/mmu_context_nohash.c
6990 @@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
6991 return NOTIFY_OK;
6992 }
6993
6994 -static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
6995 +static struct notifier_block mmu_context_cpu_nb = {
6996 .notifier_call = mmu_context_cpu_notify,
6997 };
6998
6999 diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7000 index bba87ca..c346a33 100644
7001 --- a/arch/powerpc/mm/numa.c
7002 +++ b/arch/powerpc/mm/numa.c
7003 @@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7004 return ret;
7005 }
7006
7007 -static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7008 +static struct notifier_block ppc64_numa_nb = {
7009 .notifier_call = cpu_numa_callback,
7010 .priority = 1 /* Must run before sched domains notifier. */
7011 };
7012 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7013 index cf9dada..241529f 100644
7014 --- a/arch/powerpc/mm/slice.c
7015 +++ b/arch/powerpc/mm/slice.c
7016 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7017 if ((mm->task_size - len) < addr)
7018 return 0;
7019 vma = find_vma(mm, addr);
7020 - return (!vma || (addr + len) <= vma->vm_start);
7021 + return check_heap_stack_gap(vma, addr, len, 0);
7022 }
7023
7024 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7025 @@ -272,7 +272,7 @@ full_search:
7026 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
7027 continue;
7028 }
7029 - if (!vma || addr + len <= vma->vm_start) {
7030 + if (check_heap_stack_gap(vma, addr, len, 0)) {
7031 /*
7032 * Remember the place where we stopped the search:
7033 */
7034 @@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7035 }
7036 }
7037
7038 - addr = mm->mmap_base;
7039 - while (addr > len) {
7040 + if (mm->mmap_base < len)
7041 + addr = -ENOMEM;
7042 + else
7043 + addr = mm->mmap_base - len;
7044 +
7045 + while (!IS_ERR_VALUE(addr)) {
7046 /* Go down by chunk size */
7047 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
7048 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
7049
7050 /* Check for hit with different page size */
7051 mask = slice_range_to_mask(addr, len);
7052 @@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7053 * return with success:
7054 */
7055 vma = find_vma(mm, addr);
7056 - if (!vma || (addr + len) <= vma->vm_start) {
7057 + if (check_heap_stack_gap(vma, addr, len, 0)) {
7058 /* remember the address as a hint for next time */
7059 if (use_cache)
7060 mm->free_area_cache = addr;
7061 @@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7062 mm->cached_hole_size = vma->vm_start - addr;
7063
7064 /* try just below the current vma->vm_start */
7065 - addr = vma->vm_start;
7066 + addr = skip_heap_stack_gap(vma, len, 0);
7067 }
7068
7069 /*
7070 @@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7071 if (fixed && addr > (mm->task_size - len))
7072 return -EINVAL;
7073
7074 +#ifdef CONFIG_PAX_RANDMMAP
7075 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7076 + addr = 0;
7077 +#endif
7078 +
7079 /* If hint, make sure it matches our alignment restrictions */
7080 if (!fixed && addr) {
7081 addr = _ALIGN_UP(addr, 1ul << pshift);
7082 diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7083 index bdb738a..49c9f95 100644
7084 --- a/arch/powerpc/platforms/powermac/smp.c
7085 +++ b/arch/powerpc/platforms/powermac/smp.c
7086 @@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7087 return NOTIFY_OK;
7088 }
7089
7090 -static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7091 +static struct notifier_block smp_core99_cpu_nb = {
7092 .notifier_call = smp_core99_cpu_notify,
7093 };
7094 #endif /* CONFIG_HOTPLUG_CPU */
7095 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7096 index c797832..ce575c8 100644
7097 --- a/arch/s390/include/asm/atomic.h
7098 +++ b/arch/s390/include/asm/atomic.h
7099 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7100 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7101 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7102
7103 +#define atomic64_read_unchecked(v) atomic64_read(v)
7104 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7105 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7106 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7107 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7108 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7109 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7110 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7111 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7112 +
7113 #define smp_mb__before_atomic_dec() smp_mb()
7114 #define smp_mb__after_atomic_dec() smp_mb()
7115 #define smp_mb__before_atomic_inc() smp_mb()
7116 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7117 index 4d7ccac..d03d0ad 100644
7118 --- a/arch/s390/include/asm/cache.h
7119 +++ b/arch/s390/include/asm/cache.h
7120 @@ -9,8 +9,10 @@
7121 #ifndef __ARCH_S390_CACHE_H
7122 #define __ARCH_S390_CACHE_H
7123
7124 -#define L1_CACHE_BYTES 256
7125 +#include <linux/const.h>
7126 +
7127 #define L1_CACHE_SHIFT 8
7128 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7129 #define NET_SKB_PAD 32
7130
7131 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7132 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7133 index 178ff96..8c93bd1 100644
7134 --- a/arch/s390/include/asm/elf.h
7135 +++ b/arch/s390/include/asm/elf.h
7136 @@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
7137 the loader. We need to make sure that it is out of the way of the program
7138 that it will "exec", and that there is sufficient room for the brk. */
7139
7140 -extern unsigned long randomize_et_dyn(unsigned long base);
7141 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7142 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7143 +
7144 +#ifdef CONFIG_PAX_ASLR
7145 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7146 +
7147 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7148 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7149 +#endif
7150
7151 /* This yields a mask that user programs can use to figure out what
7152 instruction set this CPU supports. */
7153 @@ -210,9 +216,6 @@ struct linux_binprm;
7154 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7155 int arch_setup_additional_pages(struct linux_binprm *, int);
7156
7157 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7158 -#define arch_randomize_brk arch_randomize_brk
7159 -
7160 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7161
7162 #endif
7163 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7164 index c4a93d6..4d2a9b4 100644
7165 --- a/arch/s390/include/asm/exec.h
7166 +++ b/arch/s390/include/asm/exec.h
7167 @@ -7,6 +7,6 @@
7168 #ifndef __ASM_EXEC_H
7169 #define __ASM_EXEC_H
7170
7171 -extern unsigned long arch_align_stack(unsigned long sp);
7172 +#define arch_align_stack(x) ((x) & ~0xfUL)
7173
7174 #endif /* __ASM_EXEC_H */
7175 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7176 index 34268df..ea97318 100644
7177 --- a/arch/s390/include/asm/uaccess.h
7178 +++ b/arch/s390/include/asm/uaccess.h
7179 @@ -252,6 +252,10 @@ static inline unsigned long __must_check
7180 copy_to_user(void __user *to, const void *from, unsigned long n)
7181 {
7182 might_fault();
7183 +
7184 + if ((long)n < 0)
7185 + return n;
7186 +
7187 if (access_ok(VERIFY_WRITE, to, n))
7188 n = __copy_to_user(to, from, n);
7189 return n;
7190 @@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7191 static inline unsigned long __must_check
7192 __copy_from_user(void *to, const void __user *from, unsigned long n)
7193 {
7194 + if ((long)n < 0)
7195 + return n;
7196 +
7197 if (__builtin_constant_p(n) && (n <= 256))
7198 return uaccess.copy_from_user_small(n, from, to);
7199 else
7200 @@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7201 static inline unsigned long __must_check
7202 copy_from_user(void *to, const void __user *from, unsigned long n)
7203 {
7204 - unsigned int sz = __compiletime_object_size(to);
7205 + size_t sz = __compiletime_object_size(to);
7206
7207 might_fault();
7208 - if (unlikely(sz != -1 && sz < n)) {
7209 +
7210 + if ((long)n < 0)
7211 + return n;
7212 +
7213 + if (unlikely(sz != (size_t)-1 && sz < n)) {
7214 copy_from_user_overflow();
7215 return n;
7216 }
7217 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7218 index 4610dea..cf0af21 100644
7219 --- a/arch/s390/kernel/module.c
7220 +++ b/arch/s390/kernel/module.c
7221 @@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7222
7223 /* Increase core size by size of got & plt and set start
7224 offsets for got and plt. */
7225 - me->core_size = ALIGN(me->core_size, 4);
7226 - me->arch.got_offset = me->core_size;
7227 - me->core_size += me->arch.got_size;
7228 - me->arch.plt_offset = me->core_size;
7229 - me->core_size += me->arch.plt_size;
7230 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
7231 + me->arch.got_offset = me->core_size_rw;
7232 + me->core_size_rw += me->arch.got_size;
7233 + me->arch.plt_offset = me->core_size_rx;
7234 + me->core_size_rx += me->arch.plt_size;
7235 return 0;
7236 }
7237
7238 @@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7239 if (info->got_initialized == 0) {
7240 Elf_Addr *gotent;
7241
7242 - gotent = me->module_core + me->arch.got_offset +
7243 + gotent = me->module_core_rw + me->arch.got_offset +
7244 info->got_offset;
7245 *gotent = val;
7246 info->got_initialized = 1;
7247 @@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7248 else if (r_type == R_390_GOTENT ||
7249 r_type == R_390_GOTPLTENT)
7250 *(unsigned int *) loc =
7251 - (val + (Elf_Addr) me->module_core - loc) >> 1;
7252 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7253 else if (r_type == R_390_GOT64 ||
7254 r_type == R_390_GOTPLT64)
7255 *(unsigned long *) loc = val;
7256 @@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7257 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7258 if (info->plt_initialized == 0) {
7259 unsigned int *ip;
7260 - ip = me->module_core + me->arch.plt_offset +
7261 + ip = me->module_core_rx + me->arch.plt_offset +
7262 info->plt_offset;
7263 #ifndef CONFIG_64BIT
7264 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7265 @@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7266 val - loc + 0xffffUL < 0x1ffffeUL) ||
7267 (r_type == R_390_PLT32DBL &&
7268 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7269 - val = (Elf_Addr) me->module_core +
7270 + val = (Elf_Addr) me->module_core_rx +
7271 me->arch.plt_offset +
7272 info->plt_offset;
7273 val += rela->r_addend - loc;
7274 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7275 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7276 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7277 val = val + rela->r_addend -
7278 - ((Elf_Addr) me->module_core + me->arch.got_offset);
7279 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7280 if (r_type == R_390_GOTOFF16)
7281 *(unsigned short *) loc = val;
7282 else if (r_type == R_390_GOTOFF32)
7283 @@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7284 break;
7285 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7286 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7287 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
7288 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7289 rela->r_addend - loc;
7290 if (r_type == R_390_GOTPC)
7291 *(unsigned int *) loc = val;
7292 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7293 index 536d645..4a5bd9e 100644
7294 --- a/arch/s390/kernel/process.c
7295 +++ b/arch/s390/kernel/process.c
7296 @@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7297 }
7298 return 0;
7299 }
7300 -
7301 -unsigned long arch_align_stack(unsigned long sp)
7302 -{
7303 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7304 - sp -= get_random_int() & ~PAGE_MASK;
7305 - return sp & ~0xf;
7306 -}
7307 -
7308 -static inline unsigned long brk_rnd(void)
7309 -{
7310 - /* 8MB for 32bit, 1GB for 64bit */
7311 - if (is_32bit_task())
7312 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7313 - else
7314 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7315 -}
7316 -
7317 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7318 -{
7319 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7320 -
7321 - if (ret < mm->brk)
7322 - return mm->brk;
7323 - return ret;
7324 -}
7325 -
7326 -unsigned long randomize_et_dyn(unsigned long base)
7327 -{
7328 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7329 -
7330 - if (!(current->flags & PF_RANDOMIZE))
7331 - return base;
7332 - if (ret < base)
7333 - return base;
7334 - return ret;
7335 -}
7336 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7337 index c59a5ef..3fae59c 100644
7338 --- a/arch/s390/mm/mmap.c
7339 +++ b/arch/s390/mm/mmap.c
7340 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7341 */
7342 if (mmap_is_legacy()) {
7343 mm->mmap_base = TASK_UNMAPPED_BASE;
7344 +
7345 +#ifdef CONFIG_PAX_RANDMMAP
7346 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7347 + mm->mmap_base += mm->delta_mmap;
7348 +#endif
7349 +
7350 mm->get_unmapped_area = arch_get_unmapped_area;
7351 mm->unmap_area = arch_unmap_area;
7352 } else {
7353 mm->mmap_base = mmap_base();
7354 +
7355 +#ifdef CONFIG_PAX_RANDMMAP
7356 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7357 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7358 +#endif
7359 +
7360 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7361 mm->unmap_area = arch_unmap_area_topdown;
7362 }
7363 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7364 */
7365 if (mmap_is_legacy()) {
7366 mm->mmap_base = TASK_UNMAPPED_BASE;
7367 +
7368 +#ifdef CONFIG_PAX_RANDMMAP
7369 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7370 + mm->mmap_base += mm->delta_mmap;
7371 +#endif
7372 +
7373 mm->get_unmapped_area = s390_get_unmapped_area;
7374 mm->unmap_area = arch_unmap_area;
7375 } else {
7376 mm->mmap_base = mmap_base();
7377 +
7378 +#ifdef CONFIG_PAX_RANDMMAP
7379 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7380 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7381 +#endif
7382 +
7383 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7384 mm->unmap_area = arch_unmap_area_topdown;
7385 }
7386 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7387 index ae3d59f..f65f075 100644
7388 --- a/arch/score/include/asm/cache.h
7389 +++ b/arch/score/include/asm/cache.h
7390 @@ -1,7 +1,9 @@
7391 #ifndef _ASM_SCORE_CACHE_H
7392 #define _ASM_SCORE_CACHE_H
7393
7394 +#include <linux/const.h>
7395 +
7396 #define L1_CACHE_SHIFT 4
7397 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7398 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7399
7400 #endif /* _ASM_SCORE_CACHE_H */
7401 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7402 index f9f3cd5..58ff438 100644
7403 --- a/arch/score/include/asm/exec.h
7404 +++ b/arch/score/include/asm/exec.h
7405 @@ -1,6 +1,6 @@
7406 #ifndef _ASM_SCORE_EXEC_H
7407 #define _ASM_SCORE_EXEC_H
7408
7409 -extern unsigned long arch_align_stack(unsigned long sp);
7410 +#define arch_align_stack(x) (x)
7411
7412 #endif /* _ASM_SCORE_EXEC_H */
7413 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7414 index 7956846..5f37677 100644
7415 --- a/arch/score/kernel/process.c
7416 +++ b/arch/score/kernel/process.c
7417 @@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7418
7419 return task_pt_regs(task)->cp0_epc;
7420 }
7421 -
7422 -unsigned long arch_align_stack(unsigned long sp)
7423 -{
7424 - return sp;
7425 -}
7426 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7427 index ef9e555..331bd29 100644
7428 --- a/arch/sh/include/asm/cache.h
7429 +++ b/arch/sh/include/asm/cache.h
7430 @@ -9,10 +9,11 @@
7431 #define __ASM_SH_CACHE_H
7432 #ifdef __KERNEL__
7433
7434 +#include <linux/const.h>
7435 #include <linux/init.h>
7436 #include <cpu/cache.h>
7437
7438 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7439 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7440
7441 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7442
7443 diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7444 index 03f2b55..b027032 100644
7445 --- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7446 +++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7447 @@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7448 return NOTIFY_OK;
7449 }
7450
7451 -static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7452 +static struct notifier_block shx3_cpu_notifier = {
7453 .notifier_call = shx3_cpu_callback,
7454 };
7455
7456 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7457 index 6777177..cb5e44f 100644
7458 --- a/arch/sh/mm/mmap.c
7459 +++ b/arch/sh/mm/mmap.c
7460 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7461 struct mm_struct *mm = current->mm;
7462 struct vm_area_struct *vma;
7463 int do_colour_align;
7464 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7465 struct vm_unmapped_area_info info;
7466
7467 if (flags & MAP_FIXED) {
7468 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7469 if (filp || (flags & MAP_SHARED))
7470 do_colour_align = 1;
7471
7472 +#ifdef CONFIG_PAX_RANDMMAP
7473 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7474 +#endif
7475 +
7476 if (addr) {
7477 if (do_colour_align)
7478 addr = COLOUR_ALIGN(addr, pgoff);
7479 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7480 addr = PAGE_ALIGN(addr);
7481
7482 vma = find_vma(mm, addr);
7483 - if (TASK_SIZE - len >= addr &&
7484 - (!vma || addr + len <= vma->vm_start))
7485 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7486 return addr;
7487 }
7488
7489 info.flags = 0;
7490 info.length = len;
7491 - info.low_limit = TASK_UNMAPPED_BASE;
7492 + info.low_limit = mm->mmap_base;
7493 info.high_limit = TASK_SIZE;
7494 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7495 info.align_offset = pgoff << PAGE_SHIFT;
7496 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7497 struct mm_struct *mm = current->mm;
7498 unsigned long addr = addr0;
7499 int do_colour_align;
7500 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7501 struct vm_unmapped_area_info info;
7502
7503 if (flags & MAP_FIXED) {
7504 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7505 if (filp || (flags & MAP_SHARED))
7506 do_colour_align = 1;
7507
7508 +#ifdef CONFIG_PAX_RANDMMAP
7509 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7510 +#endif
7511 +
7512 /* requesting a specific address */
7513 if (addr) {
7514 if (do_colour_align)
7515 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7516 addr = PAGE_ALIGN(addr);
7517
7518 vma = find_vma(mm, addr);
7519 - if (TASK_SIZE - len >= addr &&
7520 - (!vma || addr + len <= vma->vm_start))
7521 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7522 return addr;
7523 }
7524
7525 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7526 VM_BUG_ON(addr != -ENOMEM);
7527 info.flags = 0;
7528 info.low_limit = TASK_UNMAPPED_BASE;
7529 +
7530 +#ifdef CONFIG_PAX_RANDMMAP
7531 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7532 + info.low_limit += mm->delta_mmap;
7533 +#endif
7534 +
7535 info.high_limit = TASK_SIZE;
7536 addr = vm_unmapped_area(&info);
7537 }
7538 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7539 index be56a24..443328f 100644
7540 --- a/arch/sparc/include/asm/atomic_64.h
7541 +++ b/arch/sparc/include/asm/atomic_64.h
7542 @@ -14,18 +14,40 @@
7543 #define ATOMIC64_INIT(i) { (i) }
7544
7545 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7546 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7547 +{
7548 + return v->counter;
7549 +}
7550 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7551 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7552 +{
7553 + return v->counter;
7554 +}
7555
7556 #define atomic_set(v, i) (((v)->counter) = i)
7557 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7558 +{
7559 + v->counter = i;
7560 +}
7561 #define atomic64_set(v, i) (((v)->counter) = i)
7562 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7563 +{
7564 + v->counter = i;
7565 +}
7566
7567 extern void atomic_add(int, atomic_t *);
7568 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7569 extern void atomic64_add(long, atomic64_t *);
7570 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7571 extern void atomic_sub(int, atomic_t *);
7572 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7573 extern void atomic64_sub(long, atomic64_t *);
7574 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7575
7576 extern int atomic_add_ret(int, atomic_t *);
7577 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7578 extern long atomic64_add_ret(long, atomic64_t *);
7579 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7580 extern int atomic_sub_ret(int, atomic_t *);
7581 extern long atomic64_sub_ret(long, atomic64_t *);
7582
7583 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7584 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7585
7586 #define atomic_inc_return(v) atomic_add_ret(1, v)
7587 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7588 +{
7589 + return atomic_add_ret_unchecked(1, v);
7590 +}
7591 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7592 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7593 +{
7594 + return atomic64_add_ret_unchecked(1, v);
7595 +}
7596
7597 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7598 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7599
7600 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7601 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7602 +{
7603 + return atomic_add_ret_unchecked(i, v);
7604 +}
7605 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7606 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7607 +{
7608 + return atomic64_add_ret_unchecked(i, v);
7609 +}
7610
7611 /*
7612 * atomic_inc_and_test - increment and test
7613 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7614 * other cases.
7615 */
7616 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7617 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7618 +{
7619 + return atomic_inc_return_unchecked(v) == 0;
7620 +}
7621 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7622
7623 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7624 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7625 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7626
7627 #define atomic_inc(v) atomic_add(1, v)
7628 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7629 +{
7630 + atomic_add_unchecked(1, v);
7631 +}
7632 #define atomic64_inc(v) atomic64_add(1, v)
7633 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7634 +{
7635 + atomic64_add_unchecked(1, v);
7636 +}
7637
7638 #define atomic_dec(v) atomic_sub(1, v)
7639 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7640 +{
7641 + atomic_sub_unchecked(1, v);
7642 +}
7643 #define atomic64_dec(v) atomic64_sub(1, v)
7644 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7645 +{
7646 + atomic64_sub_unchecked(1, v);
7647 +}
7648
7649 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7650 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7651
7652 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7653 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7654 +{
7655 + return cmpxchg(&v->counter, old, new);
7656 +}
7657 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7658 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7659 +{
7660 + return xchg(&v->counter, new);
7661 +}
7662
7663 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7664 {
7665 - int c, old;
7666 + int c, old, new;
7667 c = atomic_read(v);
7668 for (;;) {
7669 - if (unlikely(c == (u)))
7670 + if (unlikely(c == u))
7671 break;
7672 - old = atomic_cmpxchg((v), c, c + (a));
7673 +
7674 + asm volatile("addcc %2, %0, %0\n"
7675 +
7676 +#ifdef CONFIG_PAX_REFCOUNT
7677 + "tvs %%icc, 6\n"
7678 +#endif
7679 +
7680 + : "=r" (new)
7681 + : "0" (c), "ir" (a)
7682 + : "cc");
7683 +
7684 + old = atomic_cmpxchg(v, c, new);
7685 if (likely(old == c))
7686 break;
7687 c = old;
7688 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7689 #define atomic64_cmpxchg(v, o, n) \
7690 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7691 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7692 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7693 +{
7694 + return xchg(&v->counter, new);
7695 +}
7696
7697 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7698 {
7699 - long c, old;
7700 + long c, old, new;
7701 c = atomic64_read(v);
7702 for (;;) {
7703 - if (unlikely(c == (u)))
7704 + if (unlikely(c == u))
7705 break;
7706 - old = atomic64_cmpxchg((v), c, c + (a));
7707 +
7708 + asm volatile("addcc %2, %0, %0\n"
7709 +
7710 +#ifdef CONFIG_PAX_REFCOUNT
7711 + "tvs %%xcc, 6\n"
7712 +#endif
7713 +
7714 + : "=r" (new)
7715 + : "0" (c), "ir" (a)
7716 + : "cc");
7717 +
7718 + old = atomic64_cmpxchg(v, c, new);
7719 if (likely(old == c))
7720 break;
7721 c = old;
7722 }
7723 - return c != (u);
7724 + return c != u;
7725 }
7726
7727 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7728 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7729 index 5bb6991..5c2132e 100644
7730 --- a/arch/sparc/include/asm/cache.h
7731 +++ b/arch/sparc/include/asm/cache.h
7732 @@ -7,10 +7,12 @@
7733 #ifndef _SPARC_CACHE_H
7734 #define _SPARC_CACHE_H
7735
7736 +#include <linux/const.h>
7737 +
7738 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7739
7740 #define L1_CACHE_SHIFT 5
7741 -#define L1_CACHE_BYTES 32
7742 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7743
7744 #ifdef CONFIG_SPARC32
7745 #define SMP_CACHE_BYTES_SHIFT 5
7746 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7747 index ac74a2c..a9e58af 100644
7748 --- a/arch/sparc/include/asm/elf_32.h
7749 +++ b/arch/sparc/include/asm/elf_32.h
7750 @@ -114,6 +114,13 @@ typedef struct {
7751
7752 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7753
7754 +#ifdef CONFIG_PAX_ASLR
7755 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7756 +
7757 +#define PAX_DELTA_MMAP_LEN 16
7758 +#define PAX_DELTA_STACK_LEN 16
7759 +#endif
7760 +
7761 /* This yields a mask that user programs can use to figure out what
7762 instruction set this cpu supports. This can NOT be done in userspace
7763 on Sparc. */
7764 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7765 index 370ca1e..d4f4a98 100644
7766 --- a/arch/sparc/include/asm/elf_64.h
7767 +++ b/arch/sparc/include/asm/elf_64.h
7768 @@ -189,6 +189,13 @@ typedef struct {
7769 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7770 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7771
7772 +#ifdef CONFIG_PAX_ASLR
7773 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7774 +
7775 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7776 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7777 +#endif
7778 +
7779 extern unsigned long sparc64_elf_hwcap;
7780 #define ELF_HWCAP sparc64_elf_hwcap
7781
7782 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7783 index 9b1c36d..209298b 100644
7784 --- a/arch/sparc/include/asm/pgalloc_32.h
7785 +++ b/arch/sparc/include/asm/pgalloc_32.h
7786 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7787 }
7788
7789 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7790 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7791
7792 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7793 unsigned long address)
7794 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7795 index bcfe063..b333142 100644
7796 --- a/arch/sparc/include/asm/pgalloc_64.h
7797 +++ b/arch/sparc/include/asm/pgalloc_64.h
7798 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7799 }
7800
7801 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7802 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7803
7804 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7805 {
7806 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7807 index 6fc1348..390c50a 100644
7808 --- a/arch/sparc/include/asm/pgtable_32.h
7809 +++ b/arch/sparc/include/asm/pgtable_32.h
7810 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7811 #define PAGE_SHARED SRMMU_PAGE_SHARED
7812 #define PAGE_COPY SRMMU_PAGE_COPY
7813 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7814 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7815 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7816 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7817 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7818
7819 /* Top-level page directory - dummy used by init-mm.
7820 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7821
7822 /* xwr */
7823 #define __P000 PAGE_NONE
7824 -#define __P001 PAGE_READONLY
7825 -#define __P010 PAGE_COPY
7826 -#define __P011 PAGE_COPY
7827 +#define __P001 PAGE_READONLY_NOEXEC
7828 +#define __P010 PAGE_COPY_NOEXEC
7829 +#define __P011 PAGE_COPY_NOEXEC
7830 #define __P100 PAGE_READONLY
7831 #define __P101 PAGE_READONLY
7832 #define __P110 PAGE_COPY
7833 #define __P111 PAGE_COPY
7834
7835 #define __S000 PAGE_NONE
7836 -#define __S001 PAGE_READONLY
7837 -#define __S010 PAGE_SHARED
7838 -#define __S011 PAGE_SHARED
7839 +#define __S001 PAGE_READONLY_NOEXEC
7840 +#define __S010 PAGE_SHARED_NOEXEC
7841 +#define __S011 PAGE_SHARED_NOEXEC
7842 #define __S100 PAGE_READONLY
7843 #define __S101 PAGE_READONLY
7844 #define __S110 PAGE_SHARED
7845 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7846 index 79da178..c2eede8 100644
7847 --- a/arch/sparc/include/asm/pgtsrmmu.h
7848 +++ b/arch/sparc/include/asm/pgtsrmmu.h
7849 @@ -115,6 +115,11 @@
7850 SRMMU_EXEC | SRMMU_REF)
7851 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7852 SRMMU_EXEC | SRMMU_REF)
7853 +
7854 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7855 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7856 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7857 +
7858 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7859 SRMMU_DIRTY | SRMMU_REF)
7860
7861 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7862 index 9689176..63c18ea 100644
7863 --- a/arch/sparc/include/asm/spinlock_64.h
7864 +++ b/arch/sparc/include/asm/spinlock_64.h
7865 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7866
7867 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7868
7869 -static void inline arch_read_lock(arch_rwlock_t *lock)
7870 +static inline void arch_read_lock(arch_rwlock_t *lock)
7871 {
7872 unsigned long tmp1, tmp2;
7873
7874 __asm__ __volatile__ (
7875 "1: ldsw [%2], %0\n"
7876 " brlz,pn %0, 2f\n"
7877 -"4: add %0, 1, %1\n"
7878 +"4: addcc %0, 1, %1\n"
7879 +
7880 +#ifdef CONFIG_PAX_REFCOUNT
7881 +" tvs %%icc, 6\n"
7882 +#endif
7883 +
7884 " cas [%2], %0, %1\n"
7885 " cmp %0, %1\n"
7886 " bne,pn %%icc, 1b\n"
7887 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
7888 " .previous"
7889 : "=&r" (tmp1), "=&r" (tmp2)
7890 : "r" (lock)
7891 - : "memory");
7892 + : "memory", "cc");
7893 }
7894
7895 -static int inline arch_read_trylock(arch_rwlock_t *lock)
7896 +static inline int arch_read_trylock(arch_rwlock_t *lock)
7897 {
7898 int tmp1, tmp2;
7899
7900 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7901 "1: ldsw [%2], %0\n"
7902 " brlz,a,pn %0, 2f\n"
7903 " mov 0, %0\n"
7904 -" add %0, 1, %1\n"
7905 +" addcc %0, 1, %1\n"
7906 +
7907 +#ifdef CONFIG_PAX_REFCOUNT
7908 +" tvs %%icc, 6\n"
7909 +#endif
7910 +
7911 " cas [%2], %0, %1\n"
7912 " cmp %0, %1\n"
7913 " bne,pn %%icc, 1b\n"
7914 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7915 return tmp1;
7916 }
7917
7918 -static void inline arch_read_unlock(arch_rwlock_t *lock)
7919 +static inline void arch_read_unlock(arch_rwlock_t *lock)
7920 {
7921 unsigned long tmp1, tmp2;
7922
7923 __asm__ __volatile__(
7924 "1: lduw [%2], %0\n"
7925 -" sub %0, 1, %1\n"
7926 +" subcc %0, 1, %1\n"
7927 +
7928 +#ifdef CONFIG_PAX_REFCOUNT
7929 +" tvs %%icc, 6\n"
7930 +#endif
7931 +
7932 " cas [%2], %0, %1\n"
7933 " cmp %0, %1\n"
7934 " bne,pn %%xcc, 1b\n"
7935 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
7936 : "memory");
7937 }
7938
7939 -static void inline arch_write_lock(arch_rwlock_t *lock)
7940 +static inline void arch_write_lock(arch_rwlock_t *lock)
7941 {
7942 unsigned long mask, tmp1, tmp2;
7943
7944 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
7945 : "memory");
7946 }
7947
7948 -static void inline arch_write_unlock(arch_rwlock_t *lock)
7949 +static inline void arch_write_unlock(arch_rwlock_t *lock)
7950 {
7951 __asm__ __volatile__(
7952 " stw %%g0, [%0]"
7953 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
7954 : "memory");
7955 }
7956
7957 -static int inline arch_write_trylock(arch_rwlock_t *lock)
7958 +static inline int arch_write_trylock(arch_rwlock_t *lock)
7959 {
7960 unsigned long mask, tmp1, tmp2, result;
7961
7962 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
7963 index 25849ae..924c54b 100644
7964 --- a/arch/sparc/include/asm/thread_info_32.h
7965 +++ b/arch/sparc/include/asm/thread_info_32.h
7966 @@ -49,6 +49,8 @@ struct thread_info {
7967 unsigned long w_saved;
7968
7969 struct restart_block restart_block;
7970 +
7971 + unsigned long lowest_stack;
7972 };
7973
7974 /*
7975 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
7976 index 269bd92..e46a9b8 100644
7977 --- a/arch/sparc/include/asm/thread_info_64.h
7978 +++ b/arch/sparc/include/asm/thread_info_64.h
7979 @@ -63,6 +63,8 @@ struct thread_info {
7980 struct pt_regs *kern_una_regs;
7981 unsigned int kern_una_insn;
7982
7983 + unsigned long lowest_stack;
7984 +
7985 unsigned long fpregs[0] __attribute__ ((aligned(64)));
7986 };
7987
7988 @@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
7989 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
7990 /* flag bit 6 is available */
7991 #define TIF_32BIT 7 /* 32-bit binary */
7992 -/* flag bit 8 is available */
7993 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
7994 #define TIF_SECCOMP 9 /* secure computing */
7995 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
7996 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
7997 +
7998 /* NOTE: Thread flags >= 12 should be ones we have no interest
7999 * in using in assembly, else we can't use the mask as
8000 * an immediate value in instructions such as andcc.
8001 @@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8002 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8003 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8004 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8005 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8006
8007 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8008 _TIF_DO_NOTIFY_RESUME_MASK | \
8009 _TIF_NEED_RESCHED)
8010 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8011
8012 +#define _TIF_WORK_SYSCALL \
8013 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8014 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8015 +
8016 +
8017 /*
8018 * Thread-synchronous status.
8019 *
8020 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8021 index 0167d26..9acd8ed 100644
8022 --- a/arch/sparc/include/asm/uaccess.h
8023 +++ b/arch/sparc/include/asm/uaccess.h
8024 @@ -1,5 +1,13 @@
8025 #ifndef ___ASM_SPARC_UACCESS_H
8026 #define ___ASM_SPARC_UACCESS_H
8027 +
8028 +#ifdef __KERNEL__
8029 +#ifndef __ASSEMBLY__
8030 +#include <linux/types.h>
8031 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
8032 +#endif
8033 +#endif
8034 +
8035 #if defined(__sparc__) && defined(__arch64__)
8036 #include <asm/uaccess_64.h>
8037 #else
8038 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8039 index 53a28dd..50c38c3 100644
8040 --- a/arch/sparc/include/asm/uaccess_32.h
8041 +++ b/arch/sparc/include/asm/uaccess_32.h
8042 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8043
8044 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8045 {
8046 - if (n && __access_ok((unsigned long) to, n))
8047 + if ((long)n < 0)
8048 + return n;
8049 +
8050 + if (n && __access_ok((unsigned long) to, n)) {
8051 + if (!__builtin_constant_p(n))
8052 + check_object_size(from, n, true);
8053 return __copy_user(to, (__force void __user *) from, n);
8054 - else
8055 + } else
8056 return n;
8057 }
8058
8059 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8060 {
8061 + if ((long)n < 0)
8062 + return n;
8063 +
8064 + if (!__builtin_constant_p(n))
8065 + check_object_size(from, n, true);
8066 +
8067 return __copy_user(to, (__force void __user *) from, n);
8068 }
8069
8070 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8071 {
8072 - if (n && __access_ok((unsigned long) from, n))
8073 + if ((long)n < 0)
8074 + return n;
8075 +
8076 + if (n && __access_ok((unsigned long) from, n)) {
8077 + if (!__builtin_constant_p(n))
8078 + check_object_size(to, n, false);
8079 return __copy_user((__force void __user *) to, from, n);
8080 - else
8081 + } else
8082 return n;
8083 }
8084
8085 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8086 {
8087 + if ((long)n < 0)
8088 + return n;
8089 +
8090 return __copy_user((__force void __user *) to, from, n);
8091 }
8092
8093 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8094 index e562d3c..191f176 100644
8095 --- a/arch/sparc/include/asm/uaccess_64.h
8096 +++ b/arch/sparc/include/asm/uaccess_64.h
8097 @@ -10,6 +10,7 @@
8098 #include <linux/compiler.h>
8099 #include <linux/string.h>
8100 #include <linux/thread_info.h>
8101 +#include <linux/kernel.h>
8102 #include <asm/asi.h>
8103 #include <asm/spitfire.h>
8104 #include <asm-generic/uaccess-unaligned.h>
8105 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8106 static inline unsigned long __must_check
8107 copy_from_user(void *to, const void __user *from, unsigned long size)
8108 {
8109 - unsigned long ret = ___copy_from_user(to, from, size);
8110 + unsigned long ret;
8111
8112 + if ((long)size < 0 || size > INT_MAX)
8113 + return size;
8114 +
8115 + if (!__builtin_constant_p(size))
8116 + check_object_size(to, size, false);
8117 +
8118 + ret = ___copy_from_user(to, from, size);
8119 if (unlikely(ret))
8120 ret = copy_from_user_fixup(to, from, size);
8121
8122 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8123 static inline unsigned long __must_check
8124 copy_to_user(void __user *to, const void *from, unsigned long size)
8125 {
8126 - unsigned long ret = ___copy_to_user(to, from, size);
8127 + unsigned long ret;
8128
8129 + if ((long)size < 0 || size > INT_MAX)
8130 + return size;
8131 +
8132 + if (!__builtin_constant_p(size))
8133 + check_object_size(from, size, true);
8134 +
8135 + ret = ___copy_to_user(to, from, size);
8136 if (unlikely(ret))
8137 ret = copy_to_user_fixup(to, from, size);
8138 return ret;
8139 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8140 index 6cf591b..b49e65a 100644
8141 --- a/arch/sparc/kernel/Makefile
8142 +++ b/arch/sparc/kernel/Makefile
8143 @@ -3,7 +3,7 @@
8144 #
8145
8146 asflags-y := -ansi
8147 -ccflags-y := -Werror
8148 +#ccflags-y := -Werror
8149
8150 extra-y := head_$(BITS).o
8151
8152 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8153 index be8e862..5b50b12 100644
8154 --- a/arch/sparc/kernel/process_32.c
8155 +++ b/arch/sparc/kernel/process_32.c
8156 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
8157
8158 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8159 r->psr, r->pc, r->npc, r->y, print_tainted());
8160 - printk("PC: <%pS>\n", (void *) r->pc);
8161 + printk("PC: <%pA>\n", (void *) r->pc);
8162 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8163 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8164 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8165 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8166 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8167 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8168 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8169 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8170
8171 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8172 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8173 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8174 rw = (struct reg_window32 *) fp;
8175 pc = rw->ins[7];
8176 printk("[%08lx : ", pc);
8177 - printk("%pS ] ", (void *) pc);
8178 + printk("%pA ] ", (void *) pc);
8179 fp = rw->ins[6];
8180 } while (++count < 16);
8181 printk("\n");
8182 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8183 index cdb80b2..5ca141d 100644
8184 --- a/arch/sparc/kernel/process_64.c
8185 +++ b/arch/sparc/kernel/process_64.c
8186 @@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8187 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8188 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8189 if (regs->tstate & TSTATE_PRIV)
8190 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8191 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8192 }
8193
8194 void show_regs(struct pt_regs *regs)
8195 {
8196 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8197 regs->tpc, regs->tnpc, regs->y, print_tainted());
8198 - printk("TPC: <%pS>\n", (void *) regs->tpc);
8199 + printk("TPC: <%pA>\n", (void *) regs->tpc);
8200 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8201 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8202 regs->u_regs[3]);
8203 @@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8204 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8205 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8206 regs->u_regs[15]);
8207 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8208 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8209 show_regwindow(regs);
8210 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8211 }
8212 @@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8213 ((tp && tp->task) ? tp->task->pid : -1));
8214
8215 if (gp->tstate & TSTATE_PRIV) {
8216 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8217 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8218 (void *) gp->tpc,
8219 (void *) gp->o7,
8220 (void *) gp->i7,
8221 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8222 index 7ff45e4..a58f271 100644
8223 --- a/arch/sparc/kernel/ptrace_64.c
8224 +++ b/arch/sparc/kernel/ptrace_64.c
8225 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8226 return ret;
8227 }
8228
8229 +#ifdef CONFIG_GRKERNSEC_SETXID
8230 +extern void gr_delayed_cred_worker(void);
8231 +#endif
8232 +
8233 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8234 {
8235 int ret = 0;
8236 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8237 /* do the secure computing check first */
8238 secure_computing_strict(regs->u_regs[UREG_G1]);
8239
8240 +#ifdef CONFIG_GRKERNSEC_SETXID
8241 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8242 + gr_delayed_cred_worker();
8243 +#endif
8244 +
8245 if (test_thread_flag(TIF_SYSCALL_TRACE))
8246 ret = tracehook_report_syscall_entry(regs);
8247
8248 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8249
8250 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8251 {
8252 +#ifdef CONFIG_GRKERNSEC_SETXID
8253 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8254 + gr_delayed_cred_worker();
8255 +#endif
8256 +
8257 audit_syscall_exit(regs);
8258
8259 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8260 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8261 index 2da0bdc..79128d2 100644
8262 --- a/arch/sparc/kernel/sys_sparc_32.c
8263 +++ b/arch/sparc/kernel/sys_sparc_32.c
8264 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8265 if (len > TASK_SIZE - PAGE_SIZE)
8266 return -ENOMEM;
8267 if (!addr)
8268 - addr = TASK_UNMAPPED_BASE;
8269 + addr = current->mm->mmap_base;
8270
8271 info.flags = 0;
8272 info.length = len;
8273 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8274 index 708bc29..f0129cb 100644
8275 --- a/arch/sparc/kernel/sys_sparc_64.c
8276 +++ b/arch/sparc/kernel/sys_sparc_64.c
8277 @@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8278 struct vm_area_struct * vma;
8279 unsigned long task_size = TASK_SIZE;
8280 int do_color_align;
8281 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8282 struct vm_unmapped_area_info info;
8283
8284 if (flags & MAP_FIXED) {
8285 /* We do not accept a shared mapping if it would violate
8286 * cache aliasing constraints.
8287 */
8288 - if ((flags & MAP_SHARED) &&
8289 + if ((filp || (flags & MAP_SHARED)) &&
8290 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8291 return -EINVAL;
8292 return addr;
8293 @@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8294 if (filp || (flags & MAP_SHARED))
8295 do_color_align = 1;
8296
8297 +#ifdef CONFIG_PAX_RANDMMAP
8298 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8299 +#endif
8300 +
8301 if (addr) {
8302 if (do_color_align)
8303 addr = COLOR_ALIGN(addr, pgoff);
8304 @@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8305 addr = PAGE_ALIGN(addr);
8306
8307 vma = find_vma(mm, addr);
8308 - if (task_size - len >= addr &&
8309 - (!vma || addr + len <= vma->vm_start))
8310 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8311 return addr;
8312 }
8313
8314 info.flags = 0;
8315 info.length = len;
8316 - info.low_limit = TASK_UNMAPPED_BASE;
8317 + info.low_limit = mm->mmap_base;
8318 info.high_limit = min(task_size, VA_EXCLUDE_START);
8319 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8320 info.align_offset = pgoff << PAGE_SHIFT;
8321 @@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8322 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8323 VM_BUG_ON(addr != -ENOMEM);
8324 info.low_limit = VA_EXCLUDE_END;
8325 +
8326 +#ifdef CONFIG_PAX_RANDMMAP
8327 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8328 + info.low_limit += mm->delta_mmap;
8329 +#endif
8330 +
8331 info.high_limit = task_size;
8332 addr = vm_unmapped_area(&info);
8333 }
8334 @@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8335 unsigned long task_size = STACK_TOP32;
8336 unsigned long addr = addr0;
8337 int do_color_align;
8338 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8339 struct vm_unmapped_area_info info;
8340
8341 /* This should only ever run for 32-bit processes. */
8342 @@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8343 /* We do not accept a shared mapping if it would violate
8344 * cache aliasing constraints.
8345 */
8346 - if ((flags & MAP_SHARED) &&
8347 + if ((filp || (flags & MAP_SHARED)) &&
8348 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8349 return -EINVAL;
8350 return addr;
8351 @@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8352 if (filp || (flags & MAP_SHARED))
8353 do_color_align = 1;
8354
8355 +#ifdef CONFIG_PAX_RANDMMAP
8356 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8357 +#endif
8358 +
8359 /* requesting a specific address */
8360 if (addr) {
8361 if (do_color_align)
8362 @@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8363 addr = PAGE_ALIGN(addr);
8364
8365 vma = find_vma(mm, addr);
8366 - if (task_size - len >= addr &&
8367 - (!vma || addr + len <= vma->vm_start))
8368 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8369 return addr;
8370 }
8371
8372 @@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8373 VM_BUG_ON(addr != -ENOMEM);
8374 info.flags = 0;
8375 info.low_limit = TASK_UNMAPPED_BASE;
8376 +
8377 +#ifdef CONFIG_PAX_RANDMMAP
8378 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8379 + info.low_limit += mm->delta_mmap;
8380 +#endif
8381 +
8382 info.high_limit = STACK_TOP32;
8383 addr = vm_unmapped_area(&info);
8384 }
8385 @@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8386 {
8387 unsigned long rnd = 0UL;
8388
8389 +#ifdef CONFIG_PAX_RANDMMAP
8390 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8391 +#endif
8392 +
8393 if (current->flags & PF_RANDOMIZE) {
8394 unsigned long val = get_random_int();
8395 if (test_thread_flag(TIF_32BIT))
8396 @@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8397 gap == RLIM_INFINITY ||
8398 sysctl_legacy_va_layout) {
8399 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8400 +
8401 +#ifdef CONFIG_PAX_RANDMMAP
8402 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8403 + mm->mmap_base += mm->delta_mmap;
8404 +#endif
8405 +
8406 mm->get_unmapped_area = arch_get_unmapped_area;
8407 mm->unmap_area = arch_unmap_area;
8408 } else {
8409 @@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8410 gap = (task_size / 6 * 5);
8411
8412 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8413 +
8414 +#ifdef CONFIG_PAX_RANDMMAP
8415 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8416 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8417 +#endif
8418 +
8419 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8420 mm->unmap_area = arch_unmap_area_topdown;
8421 }
8422 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8423 index e0fed77..604a7e5 100644
8424 --- a/arch/sparc/kernel/syscalls.S
8425 +++ b/arch/sparc/kernel/syscalls.S
8426 @@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8427 #endif
8428 .align 32
8429 1: ldx [%g6 + TI_FLAGS], %l5
8430 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8431 + andcc %l5, _TIF_WORK_SYSCALL, %g0
8432 be,pt %icc, rtrap
8433 nop
8434 call syscall_trace_leave
8435 @@ -190,7 +190,7 @@ linux_sparc_syscall32:
8436
8437 srl %i5, 0, %o5 ! IEU1
8438 srl %i2, 0, %o2 ! IEU0 Group
8439 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8440 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8441 bne,pn %icc, linux_syscall_trace32 ! CTI
8442 mov %i0, %l5 ! IEU1
8443 call %l7 ! CTI Group brk forced
8444 @@ -213,7 +213,7 @@ linux_sparc_syscall:
8445
8446 mov %i3, %o3 ! IEU1
8447 mov %i4, %o4 ! IEU0 Group
8448 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8449 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8450 bne,pn %icc, linux_syscall_trace ! CTI Group
8451 mov %i0, %l5 ! IEU0
8452 2: call %l7 ! CTI Group brk forced
8453 @@ -229,7 +229,7 @@ ret_sys_call:
8454
8455 cmp %o0, -ERESTART_RESTARTBLOCK
8456 bgeu,pn %xcc, 1f
8457 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8458 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8459 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8460
8461 2:
8462 diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8463 index 654e8aa..45f431b 100644
8464 --- a/arch/sparc/kernel/sysfs.c
8465 +++ b/arch/sparc/kernel/sysfs.c
8466 @@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8467 return NOTIFY_OK;
8468 }
8469
8470 -static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8471 +static struct notifier_block sysfs_cpu_nb = {
8472 .notifier_call = sysfs_cpu_notify,
8473 };
8474
8475 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8476 index a5785ea..405c5f7 100644
8477 --- a/arch/sparc/kernel/traps_32.c
8478 +++ b/arch/sparc/kernel/traps_32.c
8479 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8480 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8481 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8482
8483 +extern void gr_handle_kernel_exploit(void);
8484 +
8485 void die_if_kernel(char *str, struct pt_regs *regs)
8486 {
8487 static int die_counter;
8488 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8489 count++ < 30 &&
8490 (((unsigned long) rw) >= PAGE_OFFSET) &&
8491 !(((unsigned long) rw) & 0x7)) {
8492 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
8493 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
8494 (void *) rw->ins[7]);
8495 rw = (struct reg_window32 *)rw->ins[6];
8496 }
8497 }
8498 printk("Instruction DUMP:");
8499 instruction_dump ((unsigned long *) regs->pc);
8500 - if(regs->psr & PSR_PS)
8501 + if(regs->psr & PSR_PS) {
8502 + gr_handle_kernel_exploit();
8503 do_exit(SIGKILL);
8504 + }
8505 do_exit(SIGSEGV);
8506 }
8507
8508 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8509 index e7ecf15..6520e65 100644
8510 --- a/arch/sparc/kernel/traps_64.c
8511 +++ b/arch/sparc/kernel/traps_64.c
8512 @@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8513 i + 1,
8514 p->trapstack[i].tstate, p->trapstack[i].tpc,
8515 p->trapstack[i].tnpc, p->trapstack[i].tt);
8516 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8517 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8518 }
8519 }
8520
8521 @@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8522
8523 lvl -= 0x100;
8524 if (regs->tstate & TSTATE_PRIV) {
8525 +
8526 +#ifdef CONFIG_PAX_REFCOUNT
8527 + if (lvl == 6)
8528 + pax_report_refcount_overflow(regs);
8529 +#endif
8530 +
8531 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8532 die_if_kernel(buffer, regs);
8533 }
8534 @@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8535 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8536 {
8537 char buffer[32];
8538 -
8539 +
8540 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8541 0, lvl, SIGTRAP) == NOTIFY_STOP)
8542 return;
8543
8544 +#ifdef CONFIG_PAX_REFCOUNT
8545 + if (lvl == 6)
8546 + pax_report_refcount_overflow(regs);
8547 +#endif
8548 +
8549 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8550
8551 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8552 @@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8553 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8554 printk("%s" "ERROR(%d): ",
8555 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8556 - printk("TPC<%pS>\n", (void *) regs->tpc);
8557 + printk("TPC<%pA>\n", (void *) regs->tpc);
8558 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8559 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8560 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8561 @@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8562 smp_processor_id(),
8563 (type & 0x1) ? 'I' : 'D',
8564 regs->tpc);
8565 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8566 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8567 panic("Irrecoverable Cheetah+ parity error.");
8568 }
8569
8570 @@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8571 smp_processor_id(),
8572 (type & 0x1) ? 'I' : 'D',
8573 regs->tpc);
8574 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8575 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8576 }
8577
8578 struct sun4v_error_entry {
8579 @@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8580
8581 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8582 regs->tpc, tl);
8583 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8584 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8585 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8586 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8587 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8588 (void *) regs->u_regs[UREG_I7]);
8589 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8590 "pte[%lx] error[%lx]\n",
8591 @@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8592
8593 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8594 regs->tpc, tl);
8595 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8596 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8597 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8598 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8599 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8600 (void *) regs->u_regs[UREG_I7]);
8601 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8602 "pte[%lx] error[%lx]\n",
8603 @@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8604 fp = (unsigned long)sf->fp + STACK_BIAS;
8605 }
8606
8607 - printk(" [%016lx] %pS\n", pc, (void *) pc);
8608 + printk(" [%016lx] %pA\n", pc, (void *) pc);
8609 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8610 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8611 int index = tsk->curr_ret_stack;
8612 if (tsk->ret_stack && index >= graph) {
8613 pc = tsk->ret_stack[index - graph].ret;
8614 - printk(" [%016lx] %pS\n", pc, (void *) pc);
8615 + printk(" [%016lx] %pA\n", pc, (void *) pc);
8616 graph++;
8617 }
8618 }
8619 @@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8620 return (struct reg_window *) (fp + STACK_BIAS);
8621 }
8622
8623 +extern void gr_handle_kernel_exploit(void);
8624 +
8625 void die_if_kernel(char *str, struct pt_regs *regs)
8626 {
8627 static int die_counter;
8628 @@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8629 while (rw &&
8630 count++ < 30 &&
8631 kstack_valid(tp, (unsigned long) rw)) {
8632 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
8633 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
8634 (void *) rw->ins[7]);
8635
8636 rw = kernel_stack_up(rw);
8637 @@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8638 }
8639 user_instruction_dump ((unsigned int __user *) regs->tpc);
8640 }
8641 - if (regs->tstate & TSTATE_PRIV)
8642 + if (regs->tstate & TSTATE_PRIV) {
8643 + gr_handle_kernel_exploit();
8644 do_exit(SIGKILL);
8645 + }
8646 do_exit(SIGSEGV);
8647 }
8648 EXPORT_SYMBOL(die_if_kernel);
8649 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8650 index 8201c25e..072a2a7 100644
8651 --- a/arch/sparc/kernel/unaligned_64.c
8652 +++ b/arch/sparc/kernel/unaligned_64.c
8653 @@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8654 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8655
8656 if (__ratelimit(&ratelimit)) {
8657 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
8658 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
8659 regs->tpc, (void *) regs->tpc);
8660 }
8661 }
8662 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8663 index 8410065f2..4fd4ca22 100644
8664 --- a/arch/sparc/lib/Makefile
8665 +++ b/arch/sparc/lib/Makefile
8666 @@ -2,7 +2,7 @@
8667 #
8668
8669 asflags-y := -ansi -DST_DIV0=0x02
8670 -ccflags-y := -Werror
8671 +#ccflags-y := -Werror
8672
8673 lib-$(CONFIG_SPARC32) += ashrdi3.o
8674 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8675 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8676 index 85c233d..68500e0 100644
8677 --- a/arch/sparc/lib/atomic_64.S
8678 +++ b/arch/sparc/lib/atomic_64.S
8679 @@ -17,7 +17,12 @@
8680 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8681 BACKOFF_SETUP(%o2)
8682 1: lduw [%o1], %g1
8683 - add %g1, %o0, %g7
8684 + addcc %g1, %o0, %g7
8685 +
8686 +#ifdef CONFIG_PAX_REFCOUNT
8687 + tvs %icc, 6
8688 +#endif
8689 +
8690 cas [%o1], %g1, %g7
8691 cmp %g1, %g7
8692 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8693 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8694 2: BACKOFF_SPIN(%o2, %o3, 1b)
8695 ENDPROC(atomic_add)
8696
8697 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8698 + BACKOFF_SETUP(%o2)
8699 +1: lduw [%o1], %g1
8700 + add %g1, %o0, %g7
8701 + cas [%o1], %g1, %g7
8702 + cmp %g1, %g7
8703 + bne,pn %icc, 2f
8704 + nop
8705 + retl
8706 + nop
8707 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8708 +ENDPROC(atomic_add_unchecked)
8709 +
8710 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8711 BACKOFF_SETUP(%o2)
8712 1: lduw [%o1], %g1
8713 - sub %g1, %o0, %g7
8714 + subcc %g1, %o0, %g7
8715 +
8716 +#ifdef CONFIG_PAX_REFCOUNT
8717 + tvs %icc, 6
8718 +#endif
8719 +
8720 cas [%o1], %g1, %g7
8721 cmp %g1, %g7
8722 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8723 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8724 2: BACKOFF_SPIN(%o2, %o3, 1b)
8725 ENDPROC(atomic_sub)
8726
8727 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8728 + BACKOFF_SETUP(%o2)
8729 +1: lduw [%o1], %g1
8730 + sub %g1, %o0, %g7
8731 + cas [%o1], %g1, %g7
8732 + cmp %g1, %g7
8733 + bne,pn %icc, 2f
8734 + nop
8735 + retl
8736 + nop
8737 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8738 +ENDPROC(atomic_sub_unchecked)
8739 +
8740 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8741 BACKOFF_SETUP(%o2)
8742 1: lduw [%o1], %g1
8743 - add %g1, %o0, %g7
8744 + addcc %g1, %o0, %g7
8745 +
8746 +#ifdef CONFIG_PAX_REFCOUNT
8747 + tvs %icc, 6
8748 +#endif
8749 +
8750 cas [%o1], %g1, %g7
8751 cmp %g1, %g7
8752 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8753 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8754 2: BACKOFF_SPIN(%o2, %o3, 1b)
8755 ENDPROC(atomic_add_ret)
8756
8757 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8758 + BACKOFF_SETUP(%o2)
8759 +1: lduw [%o1], %g1
8760 + addcc %g1, %o0, %g7
8761 + cas [%o1], %g1, %g7
8762 + cmp %g1, %g7
8763 + bne,pn %icc, 2f
8764 + add %g7, %o0, %g7
8765 + sra %g7, 0, %o0
8766 + retl
8767 + nop
8768 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8769 +ENDPROC(atomic_add_ret_unchecked)
8770 +
8771 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8772 BACKOFF_SETUP(%o2)
8773 1: lduw [%o1], %g1
8774 - sub %g1, %o0, %g7
8775 + subcc %g1, %o0, %g7
8776 +
8777 +#ifdef CONFIG_PAX_REFCOUNT
8778 + tvs %icc, 6
8779 +#endif
8780 +
8781 cas [%o1], %g1, %g7
8782 cmp %g1, %g7
8783 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8784 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8785 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8786 BACKOFF_SETUP(%o2)
8787 1: ldx [%o1], %g1
8788 - add %g1, %o0, %g7
8789 + addcc %g1, %o0, %g7
8790 +
8791 +#ifdef CONFIG_PAX_REFCOUNT
8792 + tvs %xcc, 6
8793 +#endif
8794 +
8795 casx [%o1], %g1, %g7
8796 cmp %g1, %g7
8797 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8798 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8799 2: BACKOFF_SPIN(%o2, %o3, 1b)
8800 ENDPROC(atomic64_add)
8801
8802 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8803 + BACKOFF_SETUP(%o2)
8804 +1: ldx [%o1], %g1
8805 + addcc %g1, %o0, %g7
8806 + casx [%o1], %g1, %g7
8807 + cmp %g1, %g7
8808 + bne,pn %xcc, 2f
8809 + nop
8810 + retl
8811 + nop
8812 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8813 +ENDPROC(atomic64_add_unchecked)
8814 +
8815 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8816 BACKOFF_SETUP(%o2)
8817 1: ldx [%o1], %g1
8818 - sub %g1, %o0, %g7
8819 + subcc %g1, %o0, %g7
8820 +
8821 +#ifdef CONFIG_PAX_REFCOUNT
8822 + tvs %xcc, 6
8823 +#endif
8824 +
8825 casx [%o1], %g1, %g7
8826 cmp %g1, %g7
8827 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8828 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8829 2: BACKOFF_SPIN(%o2, %o3, 1b)
8830 ENDPROC(atomic64_sub)
8831
8832 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8833 + BACKOFF_SETUP(%o2)
8834 +1: ldx [%o1], %g1
8835 + subcc %g1, %o0, %g7
8836 + casx [%o1], %g1, %g7
8837 + cmp %g1, %g7
8838 + bne,pn %xcc, 2f
8839 + nop
8840 + retl
8841 + nop
8842 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8843 +ENDPROC(atomic64_sub_unchecked)
8844 +
8845 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8846 BACKOFF_SETUP(%o2)
8847 1: ldx [%o1], %g1
8848 - add %g1, %o0, %g7
8849 + addcc %g1, %o0, %g7
8850 +
8851 +#ifdef CONFIG_PAX_REFCOUNT
8852 + tvs %xcc, 6
8853 +#endif
8854 +
8855 casx [%o1], %g1, %g7
8856 cmp %g1, %g7
8857 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8858 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8859 2: BACKOFF_SPIN(%o2, %o3, 1b)
8860 ENDPROC(atomic64_add_ret)
8861
8862 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8863 + BACKOFF_SETUP(%o2)
8864 +1: ldx [%o1], %g1
8865 + addcc %g1, %o0, %g7
8866 + casx [%o1], %g1, %g7
8867 + cmp %g1, %g7
8868 + bne,pn %xcc, 2f
8869 + add %g7, %o0, %g7
8870 + mov %g7, %o0
8871 + retl
8872 + nop
8873 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8874 +ENDPROC(atomic64_add_ret_unchecked)
8875 +
8876 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8877 BACKOFF_SETUP(%o2)
8878 1: ldx [%o1], %g1
8879 - sub %g1, %o0, %g7
8880 + subcc %g1, %o0, %g7
8881 +
8882 +#ifdef CONFIG_PAX_REFCOUNT
8883 + tvs %xcc, 6
8884 +#endif
8885 +
8886 casx [%o1], %g1, %g7
8887 cmp %g1, %g7
8888 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8889 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
8890 index 0c4e35e..745d3e4 100644
8891 --- a/arch/sparc/lib/ksyms.c
8892 +++ b/arch/sparc/lib/ksyms.c
8893 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
8894
8895 /* Atomic counter implementation. */
8896 EXPORT_SYMBOL(atomic_add);
8897 +EXPORT_SYMBOL(atomic_add_unchecked);
8898 EXPORT_SYMBOL(atomic_add_ret);
8899 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
8900 EXPORT_SYMBOL(atomic_sub);
8901 +EXPORT_SYMBOL(atomic_sub_unchecked);
8902 EXPORT_SYMBOL(atomic_sub_ret);
8903 EXPORT_SYMBOL(atomic64_add);
8904 +EXPORT_SYMBOL(atomic64_add_unchecked);
8905 EXPORT_SYMBOL(atomic64_add_ret);
8906 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
8907 EXPORT_SYMBOL(atomic64_sub);
8908 +EXPORT_SYMBOL(atomic64_sub_unchecked);
8909 EXPORT_SYMBOL(atomic64_sub_ret);
8910 EXPORT_SYMBOL(atomic64_dec_if_positive);
8911
8912 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
8913 index 30c3ecc..736f015 100644
8914 --- a/arch/sparc/mm/Makefile
8915 +++ b/arch/sparc/mm/Makefile
8916 @@ -2,7 +2,7 @@
8917 #
8918
8919 asflags-y := -ansi
8920 -ccflags-y := -Werror
8921 +#ccflags-y := -Werror
8922
8923 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
8924 obj-y += fault_$(BITS).o
8925 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
8926 index e98bfda..ea8d221 100644
8927 --- a/arch/sparc/mm/fault_32.c
8928 +++ b/arch/sparc/mm/fault_32.c
8929 @@ -21,6 +21,9 @@
8930 #include <linux/perf_event.h>
8931 #include <linux/interrupt.h>
8932 #include <linux/kdebug.h>
8933 +#include <linux/slab.h>
8934 +#include <linux/pagemap.h>
8935 +#include <linux/compiler.h>
8936
8937 #include <asm/page.h>
8938 #include <asm/pgtable.h>
8939 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
8940 return safe_compute_effective_address(regs, insn);
8941 }
8942
8943 +#ifdef CONFIG_PAX_PAGEEXEC
8944 +#ifdef CONFIG_PAX_DLRESOLVE
8945 +static void pax_emuplt_close(struct vm_area_struct *vma)
8946 +{
8947 + vma->vm_mm->call_dl_resolve = 0UL;
8948 +}
8949 +
8950 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8951 +{
8952 + unsigned int *kaddr;
8953 +
8954 + vmf->page = alloc_page(GFP_HIGHUSER);
8955 + if (!vmf->page)
8956 + return VM_FAULT_OOM;
8957 +
8958 + kaddr = kmap(vmf->page);
8959 + memset(kaddr, 0, PAGE_SIZE);
8960 + kaddr[0] = 0x9DE3BFA8U; /* save */
8961 + flush_dcache_page(vmf->page);
8962 + kunmap(vmf->page);
8963 + return VM_FAULT_MAJOR;
8964 +}
8965 +
8966 +static const struct vm_operations_struct pax_vm_ops = {
8967 + .close = pax_emuplt_close,
8968 + .fault = pax_emuplt_fault
8969 +};
8970 +
8971 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
8972 +{
8973 + int ret;
8974 +
8975 + INIT_LIST_HEAD(&vma->anon_vma_chain);
8976 + vma->vm_mm = current->mm;
8977 + vma->vm_start = addr;
8978 + vma->vm_end = addr + PAGE_SIZE;
8979 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
8980 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
8981 + vma->vm_ops = &pax_vm_ops;
8982 +
8983 + ret = insert_vm_struct(current->mm, vma);
8984 + if (ret)
8985 + return ret;
8986 +
8987 + ++current->mm->total_vm;
8988 + return 0;
8989 +}
8990 +#endif
8991 +
8992 +/*
8993 + * PaX: decide what to do with offenders (regs->pc = fault address)
8994 + *
8995 + * returns 1 when task should be killed
8996 + * 2 when patched PLT trampoline was detected
8997 + * 3 when unpatched PLT trampoline was detected
8998 + */
8999 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9000 +{
9001 +
9002 +#ifdef CONFIG_PAX_EMUPLT
9003 + int err;
9004 +
9005 + do { /* PaX: patched PLT emulation #1 */
9006 + unsigned int sethi1, sethi2, jmpl;
9007 +
9008 + err = get_user(sethi1, (unsigned int *)regs->pc);
9009 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9010 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9011 +
9012 + if (err)
9013 + break;
9014 +
9015 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9016 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
9017 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
9018 + {
9019 + unsigned int addr;
9020 +
9021 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9022 + addr = regs->u_regs[UREG_G1];
9023 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9024 + regs->pc = addr;
9025 + regs->npc = addr+4;
9026 + return 2;
9027 + }
9028 + } while (0);
9029 +
9030 + do { /* PaX: patched PLT emulation #2 */
9031 + unsigned int ba;
9032 +
9033 + err = get_user(ba, (unsigned int *)regs->pc);
9034 +
9035 + if (err)
9036 + break;
9037 +
9038 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9039 + unsigned int addr;
9040 +
9041 + if ((ba & 0xFFC00000U) == 0x30800000U)
9042 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9043 + else
9044 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9045 + regs->pc = addr;
9046 + regs->npc = addr+4;
9047 + return 2;
9048 + }
9049 + } while (0);
9050 +
9051 + do { /* PaX: patched PLT emulation #3 */
9052 + unsigned int sethi, bajmpl, nop;
9053 +
9054 + err = get_user(sethi, (unsigned int *)regs->pc);
9055 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9056 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
9057 +
9058 + if (err)
9059 + break;
9060 +
9061 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9062 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9063 + nop == 0x01000000U)
9064 + {
9065 + unsigned int addr;
9066 +
9067 + addr = (sethi & 0x003FFFFFU) << 10;
9068 + regs->u_regs[UREG_G1] = addr;
9069 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9070 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9071 + else
9072 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9073 + regs->pc = addr;
9074 + regs->npc = addr+4;
9075 + return 2;
9076 + }
9077 + } while (0);
9078 +
9079 + do { /* PaX: unpatched PLT emulation step 1 */
9080 + unsigned int sethi, ba, nop;
9081 +
9082 + err = get_user(sethi, (unsigned int *)regs->pc);
9083 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
9084 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
9085 +
9086 + if (err)
9087 + break;
9088 +
9089 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9090 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9091 + nop == 0x01000000U)
9092 + {
9093 + unsigned int addr, save, call;
9094 +
9095 + if ((ba & 0xFFC00000U) == 0x30800000U)
9096 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9097 + else
9098 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9099 +
9100 + err = get_user(save, (unsigned int *)addr);
9101 + err |= get_user(call, (unsigned int *)(addr+4));
9102 + err |= get_user(nop, (unsigned int *)(addr+8));
9103 + if (err)
9104 + break;
9105 +
9106 +#ifdef CONFIG_PAX_DLRESOLVE
9107 + if (save == 0x9DE3BFA8U &&
9108 + (call & 0xC0000000U) == 0x40000000U &&
9109 + nop == 0x01000000U)
9110 + {
9111 + struct vm_area_struct *vma;
9112 + unsigned long call_dl_resolve;
9113 +
9114 + down_read(&current->mm->mmap_sem);
9115 + call_dl_resolve = current->mm->call_dl_resolve;
9116 + up_read(&current->mm->mmap_sem);
9117 + if (likely(call_dl_resolve))
9118 + goto emulate;
9119 +
9120 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9121 +
9122 + down_write(&current->mm->mmap_sem);
9123 + if (current->mm->call_dl_resolve) {
9124 + call_dl_resolve = current->mm->call_dl_resolve;
9125 + up_write(&current->mm->mmap_sem);
9126 + if (vma)
9127 + kmem_cache_free(vm_area_cachep, vma);
9128 + goto emulate;
9129 + }
9130 +
9131 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9132 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9133 + up_write(&current->mm->mmap_sem);
9134 + if (vma)
9135 + kmem_cache_free(vm_area_cachep, vma);
9136 + return 1;
9137 + }
9138 +
9139 + if (pax_insert_vma(vma, call_dl_resolve)) {
9140 + up_write(&current->mm->mmap_sem);
9141 + kmem_cache_free(vm_area_cachep, vma);
9142 + return 1;
9143 + }
9144 +
9145 + current->mm->call_dl_resolve = call_dl_resolve;
9146 + up_write(&current->mm->mmap_sem);
9147 +
9148 +emulate:
9149 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9150 + regs->pc = call_dl_resolve;
9151 + regs->npc = addr+4;
9152 + return 3;
9153 + }
9154 +#endif
9155 +
9156 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9157 + if ((save & 0xFFC00000U) == 0x05000000U &&
9158 + (call & 0xFFFFE000U) == 0x85C0A000U &&
9159 + nop == 0x01000000U)
9160 + {
9161 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9162 + regs->u_regs[UREG_G2] = addr + 4;
9163 + addr = (save & 0x003FFFFFU) << 10;
9164 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9165 + regs->pc = addr;
9166 + regs->npc = addr+4;
9167 + return 3;
9168 + }
9169 + }
9170 + } while (0);
9171 +
9172 + do { /* PaX: unpatched PLT emulation step 2 */
9173 + unsigned int save, call, nop;
9174 +
9175 + err = get_user(save, (unsigned int *)(regs->pc-4));
9176 + err |= get_user(call, (unsigned int *)regs->pc);
9177 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
9178 + if (err)
9179 + break;
9180 +
9181 + if (save == 0x9DE3BFA8U &&
9182 + (call & 0xC0000000U) == 0x40000000U &&
9183 + nop == 0x01000000U)
9184 + {
9185 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9186 +
9187 + regs->u_regs[UREG_RETPC] = regs->pc;
9188 + regs->pc = dl_resolve;
9189 + regs->npc = dl_resolve+4;
9190 + return 3;
9191 + }
9192 + } while (0);
9193 +#endif
9194 +
9195 + return 1;
9196 +}
9197 +
9198 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9199 +{
9200 + unsigned long i;
9201 +
9202 + printk(KERN_ERR "PAX: bytes at PC: ");
9203 + for (i = 0; i < 8; i++) {
9204 + unsigned int c;
9205 + if (get_user(c, (unsigned int *)pc+i))
9206 + printk(KERN_CONT "???????? ");
9207 + else
9208 + printk(KERN_CONT "%08x ", c);
9209 + }
9210 + printk("\n");
9211 +}
9212 +#endif
9213 +
9214 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9215 int text_fault)
9216 {
9217 @@ -230,6 +504,24 @@ good_area:
9218 if (!(vma->vm_flags & VM_WRITE))
9219 goto bad_area;
9220 } else {
9221 +
9222 +#ifdef CONFIG_PAX_PAGEEXEC
9223 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9224 + up_read(&mm->mmap_sem);
9225 + switch (pax_handle_fetch_fault(regs)) {
9226 +
9227 +#ifdef CONFIG_PAX_EMUPLT
9228 + case 2:
9229 + case 3:
9230 + return;
9231 +#endif
9232 +
9233 + }
9234 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9235 + do_group_exit(SIGKILL);
9236 + }
9237 +#endif
9238 +
9239 /* Allow reads even for write-only mappings */
9240 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9241 goto bad_area;
9242 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9243 index 5062ff3..e0b75f3 100644
9244 --- a/arch/sparc/mm/fault_64.c
9245 +++ b/arch/sparc/mm/fault_64.c
9246 @@ -21,6 +21,9 @@
9247 #include <linux/kprobes.h>
9248 #include <linux/kdebug.h>
9249 #include <linux/percpu.h>
9250 +#include <linux/slab.h>
9251 +#include <linux/pagemap.h>
9252 +#include <linux/compiler.h>
9253
9254 #include <asm/page.h>
9255 #include <asm/pgtable.h>
9256 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9257 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9258 regs->tpc);
9259 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9260 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9261 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9262 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9263 dump_stack();
9264 unhandled_fault(regs->tpc, current, regs);
9265 @@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9266 show_regs(regs);
9267 }
9268
9269 +#ifdef CONFIG_PAX_PAGEEXEC
9270 +#ifdef CONFIG_PAX_DLRESOLVE
9271 +static void pax_emuplt_close(struct vm_area_struct *vma)
9272 +{
9273 + vma->vm_mm->call_dl_resolve = 0UL;
9274 +}
9275 +
9276 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9277 +{
9278 + unsigned int *kaddr;
9279 +
9280 + vmf->page = alloc_page(GFP_HIGHUSER);
9281 + if (!vmf->page)
9282 + return VM_FAULT_OOM;
9283 +
9284 + kaddr = kmap(vmf->page);
9285 + memset(kaddr, 0, PAGE_SIZE);
9286 + kaddr[0] = 0x9DE3BFA8U; /* save */
9287 + flush_dcache_page(vmf->page);
9288 + kunmap(vmf->page);
9289 + return VM_FAULT_MAJOR;
9290 +}
9291 +
9292 +static const struct vm_operations_struct pax_vm_ops = {
9293 + .close = pax_emuplt_close,
9294 + .fault = pax_emuplt_fault
9295 +};
9296 +
9297 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9298 +{
9299 + int ret;
9300 +
9301 + INIT_LIST_HEAD(&vma->anon_vma_chain);
9302 + vma->vm_mm = current->mm;
9303 + vma->vm_start = addr;
9304 + vma->vm_end = addr + PAGE_SIZE;
9305 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9306 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9307 + vma->vm_ops = &pax_vm_ops;
9308 +
9309 + ret = insert_vm_struct(current->mm, vma);
9310 + if (ret)
9311 + return ret;
9312 +
9313 + ++current->mm->total_vm;
9314 + return 0;
9315 +}
9316 +#endif
9317 +
9318 +/*
9319 + * PaX: decide what to do with offenders (regs->tpc = fault address)
9320 + *
9321 + * returns 1 when task should be killed
9322 + * 2 when patched PLT trampoline was detected
9323 + * 3 when unpatched PLT trampoline was detected
9324 + */
9325 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9326 +{
9327 +
9328 +#ifdef CONFIG_PAX_EMUPLT
9329 + int err;
9330 +
9331 + do { /* PaX: patched PLT emulation #1 */
9332 + unsigned int sethi1, sethi2, jmpl;
9333 +
9334 + err = get_user(sethi1, (unsigned int *)regs->tpc);
9335 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9336 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9337 +
9338 + if (err)
9339 + break;
9340 +
9341 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9342 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
9343 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
9344 + {
9345 + unsigned long addr;
9346 +
9347 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9348 + addr = regs->u_regs[UREG_G1];
9349 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9350 +
9351 + if (test_thread_flag(TIF_32BIT))
9352 + addr &= 0xFFFFFFFFUL;
9353 +
9354 + regs->tpc = addr;
9355 + regs->tnpc = addr+4;
9356 + return 2;
9357 + }
9358 + } while (0);
9359 +
9360 + do { /* PaX: patched PLT emulation #2 */
9361 + unsigned int ba;
9362 +
9363 + err = get_user(ba, (unsigned int *)regs->tpc);
9364 +
9365 + if (err)
9366 + break;
9367 +
9368 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9369 + unsigned long addr;
9370 +
9371 + if ((ba & 0xFFC00000U) == 0x30800000U)
9372 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9373 + else
9374 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9375 +
9376 + if (test_thread_flag(TIF_32BIT))
9377 + addr &= 0xFFFFFFFFUL;
9378 +
9379 + regs->tpc = addr;
9380 + regs->tnpc = addr+4;
9381 + return 2;
9382 + }
9383 + } while (0);
9384 +
9385 + do { /* PaX: patched PLT emulation #3 */
9386 + unsigned int sethi, bajmpl, nop;
9387 +
9388 + err = get_user(sethi, (unsigned int *)regs->tpc);
9389 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9390 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9391 +
9392 + if (err)
9393 + break;
9394 +
9395 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9396 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9397 + nop == 0x01000000U)
9398 + {
9399 + unsigned long addr;
9400 +
9401 + addr = (sethi & 0x003FFFFFU) << 10;
9402 + regs->u_regs[UREG_G1] = addr;
9403 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9404 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9405 + else
9406 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9407 +
9408 + if (test_thread_flag(TIF_32BIT))
9409 + addr &= 0xFFFFFFFFUL;
9410 +
9411 + regs->tpc = addr;
9412 + regs->tnpc = addr+4;
9413 + return 2;
9414 + }
9415 + } while (0);
9416 +
9417 + do { /* PaX: patched PLT emulation #4 */
9418 + unsigned int sethi, mov1, call, mov2;
9419 +
9420 + err = get_user(sethi, (unsigned int *)regs->tpc);
9421 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9422 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
9423 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9424 +
9425 + if (err)
9426 + break;
9427 +
9428 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9429 + mov1 == 0x8210000FU &&
9430 + (call & 0xC0000000U) == 0x40000000U &&
9431 + mov2 == 0x9E100001U)
9432 + {
9433 + unsigned long addr;
9434 +
9435 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9436 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9437 +
9438 + if (test_thread_flag(TIF_32BIT))
9439 + addr &= 0xFFFFFFFFUL;
9440 +
9441 + regs->tpc = addr;
9442 + regs->tnpc = addr+4;
9443 + return 2;
9444 + }
9445 + } while (0);
9446 +
9447 + do { /* PaX: patched PLT emulation #5 */
9448 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9449 +
9450 + err = get_user(sethi, (unsigned int *)regs->tpc);
9451 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9452 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9453 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9454 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9455 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9456 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9457 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9458 +
9459 + if (err)
9460 + break;
9461 +
9462 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9463 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
9464 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9465 + (or1 & 0xFFFFE000U) == 0x82106000U &&
9466 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
9467 + sllx == 0x83287020U &&
9468 + jmpl == 0x81C04005U &&
9469 + nop == 0x01000000U)
9470 + {
9471 + unsigned long addr;
9472 +
9473 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9474 + regs->u_regs[UREG_G1] <<= 32;
9475 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9476 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9477 + regs->tpc = addr;
9478 + regs->tnpc = addr+4;
9479 + return 2;
9480 + }
9481 + } while (0);
9482 +
9483 + do { /* PaX: patched PLT emulation #6 */
9484 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9485 +
9486 + err = get_user(sethi, (unsigned int *)regs->tpc);
9487 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9488 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9489 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9490 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
9491 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9492 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9493 +
9494 + if (err)
9495 + break;
9496 +
9497 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9498 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
9499 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9500 + sllx == 0x83287020U &&
9501 + (or & 0xFFFFE000U) == 0x8A116000U &&
9502 + jmpl == 0x81C04005U &&
9503 + nop == 0x01000000U)
9504 + {
9505 + unsigned long addr;
9506 +
9507 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9508 + regs->u_regs[UREG_G1] <<= 32;
9509 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9510 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9511 + regs->tpc = addr;
9512 + regs->tnpc = addr+4;
9513 + return 2;
9514 + }
9515 + } while (0);
9516 +
9517 + do { /* PaX: unpatched PLT emulation step 1 */
9518 + unsigned int sethi, ba, nop;
9519 +
9520 + err = get_user(sethi, (unsigned int *)regs->tpc);
9521 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9522 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9523 +
9524 + if (err)
9525 + break;
9526 +
9527 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9528 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9529 + nop == 0x01000000U)
9530 + {
9531 + unsigned long addr;
9532 + unsigned int save, call;
9533 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9534 +
9535 + if ((ba & 0xFFC00000U) == 0x30800000U)
9536 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9537 + else
9538 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9539 +
9540 + if (test_thread_flag(TIF_32BIT))
9541 + addr &= 0xFFFFFFFFUL;
9542 +
9543 + err = get_user(save, (unsigned int *)addr);
9544 + err |= get_user(call, (unsigned int *)(addr+4));
9545 + err |= get_user(nop, (unsigned int *)(addr+8));
9546 + if (err)
9547 + break;
9548 +
9549 +#ifdef CONFIG_PAX_DLRESOLVE
9550 + if (save == 0x9DE3BFA8U &&
9551 + (call & 0xC0000000U) == 0x40000000U &&
9552 + nop == 0x01000000U)
9553 + {
9554 + struct vm_area_struct *vma;
9555 + unsigned long call_dl_resolve;
9556 +
9557 + down_read(&current->mm->mmap_sem);
9558 + call_dl_resolve = current->mm->call_dl_resolve;
9559 + up_read(&current->mm->mmap_sem);
9560 + if (likely(call_dl_resolve))
9561 + goto emulate;
9562 +
9563 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9564 +
9565 + down_write(&current->mm->mmap_sem);
9566 + if (current->mm->call_dl_resolve) {
9567 + call_dl_resolve = current->mm->call_dl_resolve;
9568 + up_write(&current->mm->mmap_sem);
9569 + if (vma)
9570 + kmem_cache_free(vm_area_cachep, vma);
9571 + goto emulate;
9572 + }
9573 +
9574 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9575 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9576 + up_write(&current->mm->mmap_sem);
9577 + if (vma)
9578 + kmem_cache_free(vm_area_cachep, vma);
9579 + return 1;
9580 + }
9581 +
9582 + if (pax_insert_vma(vma, call_dl_resolve)) {
9583 + up_write(&current->mm->mmap_sem);
9584 + kmem_cache_free(vm_area_cachep, vma);
9585 + return 1;
9586 + }
9587 +
9588 + current->mm->call_dl_resolve = call_dl_resolve;
9589 + up_write(&current->mm->mmap_sem);
9590 +
9591 +emulate:
9592 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9593 + regs->tpc = call_dl_resolve;
9594 + regs->tnpc = addr+4;
9595 + return 3;
9596 + }
9597 +#endif
9598 +
9599 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9600 + if ((save & 0xFFC00000U) == 0x05000000U &&
9601 + (call & 0xFFFFE000U) == 0x85C0A000U &&
9602 + nop == 0x01000000U)
9603 + {
9604 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9605 + regs->u_regs[UREG_G2] = addr + 4;
9606 + addr = (save & 0x003FFFFFU) << 10;
9607 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9608 +
9609 + if (test_thread_flag(TIF_32BIT))
9610 + addr &= 0xFFFFFFFFUL;
9611 +
9612 + regs->tpc = addr;
9613 + regs->tnpc = addr+4;
9614 + return 3;
9615 + }
9616 +
9617 + /* PaX: 64-bit PLT stub */
9618 + err = get_user(sethi1, (unsigned int *)addr);
9619 + err |= get_user(sethi2, (unsigned int *)(addr+4));
9620 + err |= get_user(or1, (unsigned int *)(addr+8));
9621 + err |= get_user(or2, (unsigned int *)(addr+12));
9622 + err |= get_user(sllx, (unsigned int *)(addr+16));
9623 + err |= get_user(add, (unsigned int *)(addr+20));
9624 + err |= get_user(jmpl, (unsigned int *)(addr+24));
9625 + err |= get_user(nop, (unsigned int *)(addr+28));
9626 + if (err)
9627 + break;
9628 +
9629 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9630 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9631 + (or1 & 0xFFFFE000U) == 0x88112000U &&
9632 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
9633 + sllx == 0x89293020U &&
9634 + add == 0x8A010005U &&
9635 + jmpl == 0x89C14000U &&
9636 + nop == 0x01000000U)
9637 + {
9638 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9639 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9640 + regs->u_regs[UREG_G4] <<= 32;
9641 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9642 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9643 + regs->u_regs[UREG_G4] = addr + 24;
9644 + addr = regs->u_regs[UREG_G5];
9645 + regs->tpc = addr;
9646 + regs->tnpc = addr+4;
9647 + return 3;
9648 + }
9649 + }
9650 + } while (0);
9651 +
9652 +#ifdef CONFIG_PAX_DLRESOLVE
9653 + do { /* PaX: unpatched PLT emulation step 2 */
9654 + unsigned int save, call, nop;
9655 +
9656 + err = get_user(save, (unsigned int *)(regs->tpc-4));
9657 + err |= get_user(call, (unsigned int *)regs->tpc);
9658 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9659 + if (err)
9660 + break;
9661 +
9662 + if (save == 0x9DE3BFA8U &&
9663 + (call & 0xC0000000U) == 0x40000000U &&
9664 + nop == 0x01000000U)
9665 + {
9666 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9667 +
9668 + if (test_thread_flag(TIF_32BIT))
9669 + dl_resolve &= 0xFFFFFFFFUL;
9670 +
9671 + regs->u_regs[UREG_RETPC] = regs->tpc;
9672 + regs->tpc = dl_resolve;
9673 + regs->tnpc = dl_resolve+4;
9674 + return 3;
9675 + }
9676 + } while (0);
9677 +#endif
9678 +
9679 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9680 + unsigned int sethi, ba, nop;
9681 +
9682 + err = get_user(sethi, (unsigned int *)regs->tpc);
9683 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9684 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9685 +
9686 + if (err)
9687 + break;
9688 +
9689 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9690 + (ba & 0xFFF00000U) == 0x30600000U &&
9691 + nop == 0x01000000U)
9692 + {
9693 + unsigned long addr;
9694 +
9695 + addr = (sethi & 0x003FFFFFU) << 10;
9696 + regs->u_regs[UREG_G1] = addr;
9697 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9698 +
9699 + if (test_thread_flag(TIF_32BIT))
9700 + addr &= 0xFFFFFFFFUL;
9701 +
9702 + regs->tpc = addr;
9703 + regs->tnpc = addr+4;
9704 + return 2;
9705 + }
9706 + } while (0);
9707 +
9708 +#endif
9709 +
9710 + return 1;
9711 +}
9712 +
9713 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9714 +{
9715 + unsigned long i;
9716 +
9717 + printk(KERN_ERR "PAX: bytes at PC: ");
9718 + for (i = 0; i < 8; i++) {
9719 + unsigned int c;
9720 + if (get_user(c, (unsigned int *)pc+i))
9721 + printk(KERN_CONT "???????? ");
9722 + else
9723 + printk(KERN_CONT "%08x ", c);
9724 + }
9725 + printk("\n");
9726 +}
9727 +#endif
9728 +
9729 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9730 {
9731 struct mm_struct *mm = current->mm;
9732 @@ -341,6 +804,29 @@ retry:
9733 if (!vma)
9734 goto bad_area;
9735
9736 +#ifdef CONFIG_PAX_PAGEEXEC
9737 + /* PaX: detect ITLB misses on non-exec pages */
9738 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9739 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9740 + {
9741 + if (address != regs->tpc)
9742 + goto good_area;
9743 +
9744 + up_read(&mm->mmap_sem);
9745 + switch (pax_handle_fetch_fault(regs)) {
9746 +
9747 +#ifdef CONFIG_PAX_EMUPLT
9748 + case 2:
9749 + case 3:
9750 + return;
9751 +#endif
9752 +
9753 + }
9754 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9755 + do_group_exit(SIGKILL);
9756 + }
9757 +#endif
9758 +
9759 /* Pure DTLB misses do not tell us whether the fault causing
9760 * load/store/atomic was a write or not, it only says that there
9761 * was no match. So in such a case we (carefully) read the
9762 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9763 index d2b5944..bd813f2 100644
9764 --- a/arch/sparc/mm/hugetlbpage.c
9765 +++ b/arch/sparc/mm/hugetlbpage.c
9766 @@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9767
9768 info.flags = 0;
9769 info.length = len;
9770 - info.low_limit = TASK_UNMAPPED_BASE;
9771 + info.low_limit = mm->mmap_base;
9772 info.high_limit = min(task_size, VA_EXCLUDE_START);
9773 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9774 info.align_offset = 0;
9775 @@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9776 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9777 VM_BUG_ON(addr != -ENOMEM);
9778 info.low_limit = VA_EXCLUDE_END;
9779 +
9780 +#ifdef CONFIG_PAX_RANDMMAP
9781 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9782 + info.low_limit += mm->delta_mmap;
9783 +#endif
9784 +
9785 info.high_limit = task_size;
9786 addr = vm_unmapped_area(&info);
9787 }
9788 @@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9789 VM_BUG_ON(addr != -ENOMEM);
9790 info.flags = 0;
9791 info.low_limit = TASK_UNMAPPED_BASE;
9792 +
9793 +#ifdef CONFIG_PAX_RANDMMAP
9794 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9795 + info.low_limit += mm->delta_mmap;
9796 +#endif
9797 +
9798 info.high_limit = STACK_TOP32;
9799 addr = vm_unmapped_area(&info);
9800 }
9801 @@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9802 struct mm_struct *mm = current->mm;
9803 struct vm_area_struct *vma;
9804 unsigned long task_size = TASK_SIZE;
9805 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9806
9807 if (test_thread_flag(TIF_32BIT))
9808 task_size = STACK_TOP32;
9809 @@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9810 return addr;
9811 }
9812
9813 +#ifdef CONFIG_PAX_RANDMMAP
9814 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9815 +#endif
9816 +
9817 if (addr) {
9818 addr = ALIGN(addr, HPAGE_SIZE);
9819 vma = find_vma(mm, addr);
9820 - if (task_size - len >= addr &&
9821 - (!vma || addr + len <= vma->vm_start))
9822 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9823 return addr;
9824 }
9825 if (mm->get_unmapped_area == arch_get_unmapped_area)
9826 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
9827 index f4500c6..889656c 100644
9828 --- a/arch/tile/include/asm/atomic_64.h
9829 +++ b/arch/tile/include/asm/atomic_64.h
9830 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9831
9832 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9833
9834 +#define atomic64_read_unchecked(v) atomic64_read(v)
9835 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9836 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9837 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9838 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9839 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9840 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9841 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9842 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9843 +
9844 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
9845 #define smp_mb__before_atomic_dec() smp_mb()
9846 #define smp_mb__after_atomic_dec() smp_mb()
9847 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
9848 index a9a5299..0fce79e 100644
9849 --- a/arch/tile/include/asm/cache.h
9850 +++ b/arch/tile/include/asm/cache.h
9851 @@ -15,11 +15,12 @@
9852 #ifndef _ASM_TILE_CACHE_H
9853 #define _ASM_TILE_CACHE_H
9854
9855 +#include <linux/const.h>
9856 #include <arch/chip.h>
9857
9858 /* bytes per L1 data cache line */
9859 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
9860 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9861 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9862
9863 /* bytes per L2 cache line */
9864 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
9865 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
9866 index 9ab078a..d6635c2 100644
9867 --- a/arch/tile/include/asm/uaccess.h
9868 +++ b/arch/tile/include/asm/uaccess.h
9869 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
9870 const void __user *from,
9871 unsigned long n)
9872 {
9873 - int sz = __compiletime_object_size(to);
9874 + size_t sz = __compiletime_object_size(to);
9875
9876 - if (likely(sz == -1 || sz >= n))
9877 + if (likely(sz == (size_t)-1 || sz >= n))
9878 n = _copy_from_user(to, from, n);
9879 else
9880 copy_from_user_overflow();
9881 diff --git a/arch/um/Makefile b/arch/um/Makefile
9882 index 133f7de..1d6f2f1 100644
9883 --- a/arch/um/Makefile
9884 +++ b/arch/um/Makefile
9885 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
9886 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
9887 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
9888
9889 +ifdef CONSTIFY_PLUGIN
9890 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
9891 +endif
9892 +
9893 #This will adjust *FLAGS accordingly to the platform.
9894 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
9895
9896 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
9897 index 19e1bdd..3665b77 100644
9898 --- a/arch/um/include/asm/cache.h
9899 +++ b/arch/um/include/asm/cache.h
9900 @@ -1,6 +1,7 @@
9901 #ifndef __UM_CACHE_H
9902 #define __UM_CACHE_H
9903
9904 +#include <linux/const.h>
9905
9906 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
9907 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9908 @@ -12,6 +13,6 @@
9909 # define L1_CACHE_SHIFT 5
9910 #endif
9911
9912 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9913 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9914
9915 #endif
9916 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
9917 index 2e0a6b1..a64d0f5 100644
9918 --- a/arch/um/include/asm/kmap_types.h
9919 +++ b/arch/um/include/asm/kmap_types.h
9920 @@ -8,6 +8,6 @@
9921
9922 /* No more #include "asm/arch/kmap_types.h" ! */
9923
9924 -#define KM_TYPE_NR 14
9925 +#define KM_TYPE_NR 15
9926
9927 #endif
9928 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
9929 index 5ff53d9..5850cdf 100644
9930 --- a/arch/um/include/asm/page.h
9931 +++ b/arch/um/include/asm/page.h
9932 @@ -14,6 +14,9 @@
9933 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
9934 #define PAGE_MASK (~(PAGE_SIZE-1))
9935
9936 +#define ktla_ktva(addr) (addr)
9937 +#define ktva_ktla(addr) (addr)
9938 +
9939 #ifndef __ASSEMBLY__
9940
9941 struct page;
9942 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
9943 index 0032f92..cd151e0 100644
9944 --- a/arch/um/include/asm/pgtable-3level.h
9945 +++ b/arch/um/include/asm/pgtable-3level.h
9946 @@ -58,6 +58,7 @@
9947 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
9948 #define pud_populate(mm, pud, pmd) \
9949 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
9950 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9951
9952 #ifdef CONFIG_64BIT
9953 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
9954 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
9955 index b462b13..e7a19aa 100644
9956 --- a/arch/um/kernel/process.c
9957 +++ b/arch/um/kernel/process.c
9958 @@ -386,22 +386,6 @@ int singlestepping(void * t)
9959 return 2;
9960 }
9961
9962 -/*
9963 - * Only x86 and x86_64 have an arch_align_stack().
9964 - * All other arches have "#define arch_align_stack(x) (x)"
9965 - * in their asm/system.h
9966 - * As this is included in UML from asm-um/system-generic.h,
9967 - * we can use it to behave as the subarch does.
9968 - */
9969 -#ifndef arch_align_stack
9970 -unsigned long arch_align_stack(unsigned long sp)
9971 -{
9972 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9973 - sp -= get_random_int() % 8192;
9974 - return sp & ~0xf;
9975 -}
9976 -#endif
9977 -
9978 unsigned long get_wchan(struct task_struct *p)
9979 {
9980 unsigned long stack_page, sp, ip;
9981 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
9982 index ad8f795..2c7eec6 100644
9983 --- a/arch/unicore32/include/asm/cache.h
9984 +++ b/arch/unicore32/include/asm/cache.h
9985 @@ -12,8 +12,10 @@
9986 #ifndef __UNICORE_CACHE_H__
9987 #define __UNICORE_CACHE_H__
9988
9989 -#define L1_CACHE_SHIFT (5)
9990 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9991 +#include <linux/const.h>
9992 +
9993 +#define L1_CACHE_SHIFT 5
9994 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9995
9996 /*
9997 * Memory returned by kmalloc() may be used for DMA, so we must make
9998 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
9999 index 0694d09..b58b3aa 100644
10000 --- a/arch/x86/Kconfig
10001 +++ b/arch/x86/Kconfig
10002 @@ -238,7 +238,7 @@ config X86_HT
10003
10004 config X86_32_LAZY_GS
10005 def_bool y
10006 - depends on X86_32 && !CC_STACKPROTECTOR
10007 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10008
10009 config ARCH_HWEIGHT_CFLAGS
10010 string
10011 @@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
10012
10013 config X86_MSR
10014 tristate "/dev/cpu/*/msr - Model-specific register support"
10015 + depends on !GRKERNSEC_KMEM
10016 ---help---
10017 This device gives privileged processes access to the x86
10018 Model-Specific Registers (MSRs). It is a character device with
10019 @@ -1054,7 +1055,7 @@ choice
10020
10021 config NOHIGHMEM
10022 bool "off"
10023 - depends on !X86_NUMAQ
10024 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10025 ---help---
10026 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10027 However, the address space of 32-bit x86 processors is only 4
10028 @@ -1091,7 +1092,7 @@ config NOHIGHMEM
10029
10030 config HIGHMEM4G
10031 bool "4GB"
10032 - depends on !X86_NUMAQ
10033 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10034 ---help---
10035 Select this if you have a 32-bit processor and between 1 and 4
10036 gigabytes of physical RAM.
10037 @@ -1145,7 +1146,7 @@ config PAGE_OFFSET
10038 hex
10039 default 0xB0000000 if VMSPLIT_3G_OPT
10040 default 0x80000000 if VMSPLIT_2G
10041 - default 0x78000000 if VMSPLIT_2G_OPT
10042 + default 0x70000000 if VMSPLIT_2G_OPT
10043 default 0x40000000 if VMSPLIT_1G
10044 default 0xC0000000
10045 depends on X86_32
10046 @@ -1542,6 +1543,7 @@ config SECCOMP
10047
10048 config CC_STACKPROTECTOR
10049 bool "Enable -fstack-protector buffer overflow detection"
10050 + depends on X86_64 || !PAX_MEMORY_UDEREF
10051 ---help---
10052 This option turns on the -fstack-protector GCC feature. This
10053 feature puts, at the beginning of functions, a canary value on
10054 @@ -1599,6 +1601,7 @@ config KEXEC_JUMP
10055 config PHYSICAL_START
10056 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
10057 default "0x1000000"
10058 + range 0x400000 0x40000000
10059 ---help---
10060 This gives the physical address where the kernel is loaded.
10061
10062 @@ -1662,6 +1665,7 @@ config X86_NEED_RELOCS
10063 config PHYSICAL_ALIGN
10064 hex "Alignment value to which kernel should be aligned" if X86_32
10065 default "0x1000000"
10066 + range 0x400000 0x1000000 if PAX_KERNEXEC
10067 range 0x2000 0x1000000
10068 ---help---
10069 This value puts the alignment restrictions on physical address
10070 @@ -1737,9 +1741,10 @@ config DEBUG_HOTPLUG_CPU0
10071 If unsure, say N.
10072
10073 config COMPAT_VDSO
10074 - def_bool y
10075 + def_bool n
10076 prompt "Compat VDSO support"
10077 depends on X86_32 || IA32_EMULATION
10078 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10079 ---help---
10080 Map the 32-bit VDSO to the predictable old-style address too.
10081
10082 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10083 index c026cca..14657ae 100644
10084 --- a/arch/x86/Kconfig.cpu
10085 +++ b/arch/x86/Kconfig.cpu
10086 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10087
10088 config X86_F00F_BUG
10089 def_bool y
10090 - depends on M586MMX || M586TSC || M586 || M486
10091 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10092
10093 config X86_INVD_BUG
10094 def_bool y
10095 @@ -327,7 +327,7 @@ config X86_INVD_BUG
10096
10097 config X86_ALIGNMENT_16
10098 def_bool y
10099 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10100 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10101
10102 config X86_INTEL_USERCOPY
10103 def_bool y
10104 @@ -373,7 +373,7 @@ config X86_CMPXCHG64
10105 # generates cmov.
10106 config X86_CMOV
10107 def_bool y
10108 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10109 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10110
10111 config X86_MINIMUM_CPU_FAMILY
10112 int
10113 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10114 index b322f12..652d0d9 100644
10115 --- a/arch/x86/Kconfig.debug
10116 +++ b/arch/x86/Kconfig.debug
10117 @@ -84,7 +84,7 @@ config X86_PTDUMP
10118 config DEBUG_RODATA
10119 bool "Write protect kernel read-only data structures"
10120 default y
10121 - depends on DEBUG_KERNEL
10122 + depends on DEBUG_KERNEL && BROKEN
10123 ---help---
10124 Mark the kernel read-only data as write-protected in the pagetables,
10125 in order to catch accidental (and incorrect) writes to such const
10126 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10127
10128 config DEBUG_SET_MODULE_RONX
10129 bool "Set loadable kernel module data as NX and text as RO"
10130 - depends on MODULES
10131 + depends on MODULES && BROKEN
10132 ---help---
10133 This option helps catch unintended modifications to loadable
10134 kernel module's text and read-only data. It also prevents execution
10135 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
10136
10137 config DEBUG_STRICT_USER_COPY_CHECKS
10138 bool "Strict copy size checks"
10139 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
10140 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
10141 ---help---
10142 Enabling this option turns a certain set of sanity checks for user
10143 copy operations into compile time failures.
10144 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10145 index e71fc42..7829607 100644
10146 --- a/arch/x86/Makefile
10147 +++ b/arch/x86/Makefile
10148 @@ -50,6 +50,7 @@ else
10149 UTS_MACHINE := x86_64
10150 CHECKFLAGS += -D__x86_64__ -m64
10151
10152 + biarch := $(call cc-option,-m64)
10153 KBUILD_AFLAGS += -m64
10154 KBUILD_CFLAGS += -m64
10155
10156 @@ -230,3 +231,12 @@ define archhelp
10157 echo ' FDARGS="..." arguments for the booted kernel'
10158 echo ' FDINITRD=file initrd for the booted kernel'
10159 endef
10160 +
10161 +define OLD_LD
10162 +
10163 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10164 +*** Please upgrade your binutils to 2.18 or newer
10165 +endef
10166 +
10167 +archprepare:
10168 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10169 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10170 index 379814b..add62ce 100644
10171 --- a/arch/x86/boot/Makefile
10172 +++ b/arch/x86/boot/Makefile
10173 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10174 $(call cc-option, -fno-stack-protector) \
10175 $(call cc-option, -mpreferred-stack-boundary=2)
10176 KBUILD_CFLAGS += $(call cc-option, -m32)
10177 +ifdef CONSTIFY_PLUGIN
10178 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10179 +endif
10180 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10181 GCOV_PROFILE := n
10182
10183 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10184 index 878e4b9..20537ab 100644
10185 --- a/arch/x86/boot/bitops.h
10186 +++ b/arch/x86/boot/bitops.h
10187 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10188 u8 v;
10189 const u32 *p = (const u32 *)addr;
10190
10191 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10192 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10193 return v;
10194 }
10195
10196 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10197
10198 static inline void set_bit(int nr, void *addr)
10199 {
10200 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10201 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10202 }
10203
10204 #endif /* BOOT_BITOPS_H */
10205 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10206 index 18997e5..83d9c67 100644
10207 --- a/arch/x86/boot/boot.h
10208 +++ b/arch/x86/boot/boot.h
10209 @@ -85,7 +85,7 @@ static inline void io_delay(void)
10210 static inline u16 ds(void)
10211 {
10212 u16 seg;
10213 - asm("movw %%ds,%0" : "=rm" (seg));
10214 + asm volatile("movw %%ds,%0" : "=rm" (seg));
10215 return seg;
10216 }
10217
10218 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10219 static inline int memcmp(const void *s1, const void *s2, size_t len)
10220 {
10221 u8 diff;
10222 - asm("repe; cmpsb; setnz %0"
10223 + asm volatile("repe; cmpsb; setnz %0"
10224 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10225 return diff;
10226 }
10227 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10228 index 8a84501..b2d165f 100644
10229 --- a/arch/x86/boot/compressed/Makefile
10230 +++ b/arch/x86/boot/compressed/Makefile
10231 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10232 KBUILD_CFLAGS += $(cflags-y)
10233 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10234 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10235 +ifdef CONSTIFY_PLUGIN
10236 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10237 +endif
10238
10239 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10240 GCOV_PROFILE := n
10241 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10242 index c205035..5853587 100644
10243 --- a/arch/x86/boot/compressed/eboot.c
10244 +++ b/arch/x86/boot/compressed/eboot.c
10245 @@ -150,7 +150,6 @@ again:
10246 *addr = max_addr;
10247 }
10248
10249 -free_pool:
10250 efi_call_phys1(sys_table->boottime->free_pool, map);
10251
10252 fail:
10253 @@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10254 if (i == map_size / desc_size)
10255 status = EFI_NOT_FOUND;
10256
10257 -free_pool:
10258 efi_call_phys1(sys_table->boottime->free_pool, map);
10259 fail:
10260 return status;
10261 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10262 index 1e3184f..0d11e2e 100644
10263 --- a/arch/x86/boot/compressed/head_32.S
10264 +++ b/arch/x86/boot/compressed/head_32.S
10265 @@ -118,7 +118,7 @@ preferred_addr:
10266 notl %eax
10267 andl %eax, %ebx
10268 #else
10269 - movl $LOAD_PHYSICAL_ADDR, %ebx
10270 + movl $____LOAD_PHYSICAL_ADDR, %ebx
10271 #endif
10272
10273 /* Target address to relocate to for decompression */
10274 @@ -204,7 +204,7 @@ relocated:
10275 * and where it was actually loaded.
10276 */
10277 movl %ebp, %ebx
10278 - subl $LOAD_PHYSICAL_ADDR, %ebx
10279 + subl $____LOAD_PHYSICAL_ADDR, %ebx
10280 jz 2f /* Nothing to be done if loaded at compiled addr. */
10281 /*
10282 * Process relocations.
10283 @@ -212,8 +212,7 @@ relocated:
10284
10285 1: subl $4, %edi
10286 movl (%edi), %ecx
10287 - testl %ecx, %ecx
10288 - jz 2f
10289 + jecxz 2f
10290 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10291 jmp 1b
10292 2:
10293 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10294 index f5d1aaa..cce11dc 100644
10295 --- a/arch/x86/boot/compressed/head_64.S
10296 +++ b/arch/x86/boot/compressed/head_64.S
10297 @@ -91,7 +91,7 @@ ENTRY(startup_32)
10298 notl %eax
10299 andl %eax, %ebx
10300 #else
10301 - movl $LOAD_PHYSICAL_ADDR, %ebx
10302 + movl $____LOAD_PHYSICAL_ADDR, %ebx
10303 #endif
10304
10305 /* Target address to relocate to for decompression */
10306 @@ -273,7 +273,7 @@ preferred_addr:
10307 notq %rax
10308 andq %rax, %rbp
10309 #else
10310 - movq $LOAD_PHYSICAL_ADDR, %rbp
10311 + movq $____LOAD_PHYSICAL_ADDR, %rbp
10312 #endif
10313
10314 /* Target address to relocate to for decompression */
10315 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10316 index 88f7ff6..ed695dd 100644
10317 --- a/arch/x86/boot/compressed/misc.c
10318 +++ b/arch/x86/boot/compressed/misc.c
10319 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
10320 case PT_LOAD:
10321 #ifdef CONFIG_RELOCATABLE
10322 dest = output;
10323 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10324 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10325 #else
10326 dest = (void *)(phdr->p_paddr);
10327 #endif
10328 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10329 error("Destination address too large");
10330 #endif
10331 #ifndef CONFIG_RELOCATABLE
10332 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10333 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10334 error("Wrong destination address");
10335 #endif
10336
10337 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10338 index 4d3ff03..e4972ff 100644
10339 --- a/arch/x86/boot/cpucheck.c
10340 +++ b/arch/x86/boot/cpucheck.c
10341 @@ -74,7 +74,7 @@ static int has_fpu(void)
10342 u16 fcw = -1, fsw = -1;
10343 u32 cr0;
10344
10345 - asm("movl %%cr0,%0" : "=r" (cr0));
10346 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
10347 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10348 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10349 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10350 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10351 {
10352 u32 f0, f1;
10353
10354 - asm("pushfl ; "
10355 + asm volatile("pushfl ; "
10356 "pushfl ; "
10357 "popl %0 ; "
10358 "movl %0,%1 ; "
10359 @@ -115,7 +115,7 @@ static void get_flags(void)
10360 set_bit(X86_FEATURE_FPU, cpu.flags);
10361
10362 if (has_eflag(X86_EFLAGS_ID)) {
10363 - asm("cpuid"
10364 + asm volatile("cpuid"
10365 : "=a" (max_intel_level),
10366 "=b" (cpu_vendor[0]),
10367 "=d" (cpu_vendor[1]),
10368 @@ -124,7 +124,7 @@ static void get_flags(void)
10369
10370 if (max_intel_level >= 0x00000001 &&
10371 max_intel_level <= 0x0000ffff) {
10372 - asm("cpuid"
10373 + asm volatile("cpuid"
10374 : "=a" (tfms),
10375 "=c" (cpu.flags[4]),
10376 "=d" (cpu.flags[0])
10377 @@ -136,7 +136,7 @@ static void get_flags(void)
10378 cpu.model += ((tfms >> 16) & 0xf) << 4;
10379 }
10380
10381 - asm("cpuid"
10382 + asm volatile("cpuid"
10383 : "=a" (max_amd_level)
10384 : "a" (0x80000000)
10385 : "ebx", "ecx", "edx");
10386 @@ -144,7 +144,7 @@ static void get_flags(void)
10387 if (max_amd_level >= 0x80000001 &&
10388 max_amd_level <= 0x8000ffff) {
10389 u32 eax = 0x80000001;
10390 - asm("cpuid"
10391 + asm volatile("cpuid"
10392 : "+a" (eax),
10393 "=c" (cpu.flags[6]),
10394 "=d" (cpu.flags[1])
10395 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10396 u32 ecx = MSR_K7_HWCR;
10397 u32 eax, edx;
10398
10399 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10400 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10401 eax &= ~(1 << 15);
10402 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10403 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10404
10405 get_flags(); /* Make sure it really did something */
10406 err = check_flags();
10407 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10408 u32 ecx = MSR_VIA_FCR;
10409 u32 eax, edx;
10410
10411 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10412 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10413 eax |= (1<<1)|(1<<7);
10414 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10415 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10416
10417 set_bit(X86_FEATURE_CX8, cpu.flags);
10418 err = check_flags();
10419 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10420 u32 eax, edx;
10421 u32 level = 1;
10422
10423 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10424 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10425 - asm("cpuid"
10426 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10427 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10428 + asm volatile("cpuid"
10429 : "+a" (level), "=d" (cpu.flags[0])
10430 : : "ecx", "ebx");
10431 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10432 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10433
10434 err = check_flags();
10435 }
10436 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10437 index 944ce59..87ee37a 100644
10438 --- a/arch/x86/boot/header.S
10439 +++ b/arch/x86/boot/header.S
10440 @@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10441 # single linked list of
10442 # struct setup_data
10443
10444 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10445 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10446
10447 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10448 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10449 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10450 +#else
10451 #define VO_INIT_SIZE (VO__end - VO__text)
10452 +#endif
10453 #if ZO_INIT_SIZE > VO_INIT_SIZE
10454 #define INIT_SIZE ZO_INIT_SIZE
10455 #else
10456 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10457 index db75d07..8e6d0af 100644
10458 --- a/arch/x86/boot/memory.c
10459 +++ b/arch/x86/boot/memory.c
10460 @@ -19,7 +19,7 @@
10461
10462 static int detect_memory_e820(void)
10463 {
10464 - int count = 0;
10465 + unsigned int count = 0;
10466 struct biosregs ireg, oreg;
10467 struct e820entry *desc = boot_params.e820_map;
10468 static struct e820entry buf; /* static so it is zeroed */
10469 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10470 index 11e8c6e..fdbb1ed 100644
10471 --- a/arch/x86/boot/video-vesa.c
10472 +++ b/arch/x86/boot/video-vesa.c
10473 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10474
10475 boot_params.screen_info.vesapm_seg = oreg.es;
10476 boot_params.screen_info.vesapm_off = oreg.di;
10477 + boot_params.screen_info.vesapm_size = oreg.cx;
10478 }
10479
10480 /*
10481 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10482 index 43eda28..5ab5fdb 100644
10483 --- a/arch/x86/boot/video.c
10484 +++ b/arch/x86/boot/video.c
10485 @@ -96,7 +96,7 @@ static void store_mode_params(void)
10486 static unsigned int get_entry(void)
10487 {
10488 char entry_buf[4];
10489 - int i, len = 0;
10490 + unsigned int i, len = 0;
10491 int key;
10492 unsigned int v;
10493
10494 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10495 index 5b577d5..3c1fed4 100644
10496 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
10497 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10498 @@ -8,6 +8,8 @@
10499 * including this sentence is retained in full.
10500 */
10501
10502 +#include <asm/alternative-asm.h>
10503 +
10504 .extern crypto_ft_tab
10505 .extern crypto_it_tab
10506 .extern crypto_fl_tab
10507 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
10508 je B192; \
10509 leaq 32(r9),r9;
10510
10511 +#define ret pax_force_retaddr 0, 1; ret
10512 +
10513 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10514 movq r1,r2; \
10515 movq r3,r4; \
10516 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10517 index 3470624..201259d 100644
10518 --- a/arch/x86/crypto/aesni-intel_asm.S
10519 +++ b/arch/x86/crypto/aesni-intel_asm.S
10520 @@ -31,6 +31,7 @@
10521
10522 #include <linux/linkage.h>
10523 #include <asm/inst.h>
10524 +#include <asm/alternative-asm.h>
10525
10526 #ifdef __x86_64__
10527 .data
10528 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
10529 pop %r14
10530 pop %r13
10531 pop %r12
10532 + pax_force_retaddr 0, 1
10533 ret
10534 +ENDPROC(aesni_gcm_dec)
10535
10536
10537 /*****************************************************************************
10538 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
10539 pop %r14
10540 pop %r13
10541 pop %r12
10542 + pax_force_retaddr 0, 1
10543 ret
10544 +ENDPROC(aesni_gcm_enc)
10545
10546 #endif
10547
10548 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
10549 pxor %xmm1, %xmm0
10550 movaps %xmm0, (TKEYP)
10551 add $0x10, TKEYP
10552 + pax_force_retaddr_bts
10553 ret
10554
10555 .align 4
10556 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
10557 shufps $0b01001110, %xmm2, %xmm1
10558 movaps %xmm1, 0x10(TKEYP)
10559 add $0x20, TKEYP
10560 + pax_force_retaddr_bts
10561 ret
10562
10563 .align 4
10564 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
10565
10566 movaps %xmm0, (TKEYP)
10567 add $0x10, TKEYP
10568 + pax_force_retaddr_bts
10569 ret
10570
10571 .align 4
10572 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
10573 pxor %xmm1, %xmm2
10574 movaps %xmm2, (TKEYP)
10575 add $0x10, TKEYP
10576 + pax_force_retaddr_bts
10577 ret
10578
10579 /*
10580 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
10581 #ifndef __x86_64__
10582 popl KEYP
10583 #endif
10584 + pax_force_retaddr 0, 1
10585 ret
10586 +ENDPROC(aesni_set_key)
10587
10588 /*
10589 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
10590 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
10591 popl KLEN
10592 popl KEYP
10593 #endif
10594 + pax_force_retaddr 0, 1
10595 ret
10596 +ENDPROC(aesni_enc)
10597
10598 /*
10599 * _aesni_enc1: internal ABI
10600 @@ -1959,6 +1972,7 @@ _aesni_enc1:
10601 AESENC KEY STATE
10602 movaps 0x70(TKEYP), KEY
10603 AESENCLAST KEY STATE
10604 + pax_force_retaddr_bts
10605 ret
10606
10607 /*
10608 @@ -2067,6 +2081,7 @@ _aesni_enc4:
10609 AESENCLAST KEY STATE2
10610 AESENCLAST KEY STATE3
10611 AESENCLAST KEY STATE4
10612 + pax_force_retaddr_bts
10613 ret
10614
10615 /*
10616 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
10617 popl KLEN
10618 popl KEYP
10619 #endif
10620 + pax_force_retaddr 0, 1
10621 ret
10622 +ENDPROC(aesni_dec)
10623
10624 /*
10625 * _aesni_dec1: internal ABI
10626 @@ -2146,6 +2163,7 @@ _aesni_dec1:
10627 AESDEC KEY STATE
10628 movaps 0x70(TKEYP), KEY
10629 AESDECLAST KEY STATE
10630 + pax_force_retaddr_bts
10631 ret
10632
10633 /*
10634 @@ -2254,6 +2272,7 @@ _aesni_dec4:
10635 AESDECLAST KEY STATE2
10636 AESDECLAST KEY STATE3
10637 AESDECLAST KEY STATE4
10638 + pax_force_retaddr_bts
10639 ret
10640
10641 /*
10642 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
10643 popl KEYP
10644 popl LEN
10645 #endif
10646 + pax_force_retaddr 0, 1
10647 ret
10648 +ENDPROC(aesni_ecb_enc)
10649
10650 /*
10651 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10652 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
10653 popl KEYP
10654 popl LEN
10655 #endif
10656 + pax_force_retaddr 0, 1
10657 ret
10658 +ENDPROC(aesni_ecb_dec)
10659
10660 /*
10661 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10662 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
10663 popl LEN
10664 popl IVP
10665 #endif
10666 + pax_force_retaddr 0, 1
10667 ret
10668 +ENDPROC(aesni_cbc_enc)
10669
10670 /*
10671 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10672 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
10673 popl LEN
10674 popl IVP
10675 #endif
10676 + pax_force_retaddr 0, 1
10677 ret
10678 +ENDPROC(aesni_cbc_dec)
10679
10680 #ifdef __x86_64__
10681 .align 16
10682 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
10683 mov $1, TCTR_LOW
10684 MOVQ_R64_XMM TCTR_LOW INC
10685 MOVQ_R64_XMM CTR TCTR_LOW
10686 + pax_force_retaddr_bts
10687 ret
10688
10689 /*
10690 @@ -2554,6 +2582,7 @@ _aesni_inc:
10691 .Linc_low:
10692 movaps CTR, IV
10693 PSHUFB_XMM BSWAP_MASK IV
10694 + pax_force_retaddr_bts
10695 ret
10696
10697 /*
10698 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
10699 .Lctr_enc_ret:
10700 movups IV, (IVP)
10701 .Lctr_enc_just_ret:
10702 + pax_force_retaddr 0, 1
10703 ret
10704 +ENDPROC(aesni_ctr_enc)
10705 #endif
10706 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10707 index 391d245..67f35c2 100644
10708 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10709 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10710 @@ -20,6 +20,8 @@
10711 *
10712 */
10713
10714 +#include <asm/alternative-asm.h>
10715 +
10716 .file "blowfish-x86_64-asm.S"
10717 .text
10718
10719 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
10720 jnz __enc_xor;
10721
10722 write_block();
10723 + pax_force_retaddr 0, 1
10724 ret;
10725 __enc_xor:
10726 xor_block();
10727 + pax_force_retaddr 0, 1
10728 ret;
10729
10730 .align 8
10731 @@ -188,6 +192,7 @@ blowfish_dec_blk:
10732
10733 movq %r11, %rbp;
10734
10735 + pax_force_retaddr 0, 1
10736 ret;
10737
10738 /**********************************************************************
10739 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
10740
10741 popq %rbx;
10742 popq %rbp;
10743 + pax_force_retaddr 0, 1
10744 ret;
10745
10746 __enc_xor4:
10747 @@ -349,6 +355,7 @@ __enc_xor4:
10748
10749 popq %rbx;
10750 popq %rbp;
10751 + pax_force_retaddr 0, 1
10752 ret;
10753
10754 .align 8
10755 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
10756 popq %rbx;
10757 popq %rbp;
10758
10759 + pax_force_retaddr 0, 1
10760 ret;
10761
10762 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
10763 index 0b33743..7a56206 100644
10764 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
10765 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
10766 @@ -20,6 +20,8 @@
10767 *
10768 */
10769
10770 +#include <asm/alternative-asm.h>
10771 +
10772 .file "camellia-x86_64-asm_64.S"
10773 .text
10774
10775 @@ -229,12 +231,14 @@ __enc_done:
10776 enc_outunpack(mov, RT1);
10777
10778 movq RRBP, %rbp;
10779 + pax_force_retaddr 0, 1
10780 ret;
10781
10782 __enc_xor:
10783 enc_outunpack(xor, RT1);
10784
10785 movq RRBP, %rbp;
10786 + pax_force_retaddr 0, 1
10787 ret;
10788
10789 .global camellia_dec_blk;
10790 @@ -275,6 +279,7 @@ __dec_rounds16:
10791 dec_outunpack();
10792
10793 movq RRBP, %rbp;
10794 + pax_force_retaddr 0, 1
10795 ret;
10796
10797 /**********************************************************************
10798 @@ -468,6 +473,7 @@ __enc2_done:
10799
10800 movq RRBP, %rbp;
10801 popq %rbx;
10802 + pax_force_retaddr 0, 1
10803 ret;
10804
10805 __enc2_xor:
10806 @@ -475,6 +481,7 @@ __enc2_xor:
10807
10808 movq RRBP, %rbp;
10809 popq %rbx;
10810 + pax_force_retaddr 0, 1
10811 ret;
10812
10813 .global camellia_dec_blk_2way;
10814 @@ -517,4 +524,5 @@ __dec2_rounds16:
10815
10816 movq RRBP, %rbp;
10817 movq RXOR, %rbx;
10818 + pax_force_retaddr 0, 1
10819 ret;
10820 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10821 index 15b00ac..2071784 100644
10822 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10823 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10824 @@ -23,6 +23,8 @@
10825 *
10826 */
10827
10828 +#include <asm/alternative-asm.h>
10829 +
10830 .file "cast5-avx-x86_64-asm_64.S"
10831
10832 .extern cast_s1
10833 @@ -281,6 +283,7 @@ __skip_enc:
10834 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10835 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10836
10837 + pax_force_retaddr 0, 1
10838 ret;
10839
10840 .align 16
10841 @@ -353,6 +356,7 @@ __dec_tail:
10842 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10843 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10844
10845 + pax_force_retaddr 0, 1
10846 ret;
10847
10848 __skip_dec:
10849 @@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
10850 vmovdqu RR4, (6*4*4)(%r11);
10851 vmovdqu RL4, (7*4*4)(%r11);
10852
10853 + pax_force_retaddr
10854 ret;
10855
10856 .align 16
10857 @@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
10858 vmovdqu RR4, (6*4*4)(%r11);
10859 vmovdqu RL4, (7*4*4)(%r11);
10860
10861 + pax_force_retaddr
10862 ret;
10863
10864 .align 16
10865 @@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
10866
10867 popq %r12;
10868
10869 + pax_force_retaddr
10870 ret;
10871
10872 .align 16
10873 @@ -555,4 +562,5 @@ cast5_ctr_16way:
10874
10875 popq %r12;
10876
10877 + pax_force_retaddr
10878 ret;
10879 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10880 index 2569d0d..637c289 100644
10881 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10882 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10883 @@ -23,6 +23,8 @@
10884 *
10885 */
10886
10887 +#include <asm/alternative-asm.h>
10888 +
10889 #include "glue_helper-asm-avx.S"
10890
10891 .file "cast6-avx-x86_64-asm_64.S"
10892 @@ -294,6 +296,7 @@ __cast6_enc_blk8:
10893 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10894 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10895
10896 + pax_force_retaddr 0, 1
10897 ret;
10898
10899 .align 8
10900 @@ -340,6 +343,7 @@ __cast6_dec_blk8:
10901 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10902 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10903
10904 + pax_force_retaddr 0, 1
10905 ret;
10906
10907 .align 8
10908 @@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
10909
10910 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10911
10912 + pax_force_retaddr
10913 ret;
10914
10915 .align 8
10916 @@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
10917
10918 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10919
10920 + pax_force_retaddr
10921 ret;
10922
10923 .align 8
10924 @@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
10925
10926 popq %r12;
10927
10928 + pax_force_retaddr
10929 ret;
10930
10931 .align 8
10932 @@ -436,4 +443,5 @@ cast6_ctr_8way:
10933
10934 popq %r12;
10935
10936 + pax_force_retaddr
10937 ret;
10938 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10939 index 6214a9b..1f4fc9a 100644
10940 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
10941 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10942 @@ -1,3 +1,5 @@
10943 +#include <asm/alternative-asm.h>
10944 +
10945 # enter ECRYPT_encrypt_bytes
10946 .text
10947 .p2align 5
10948 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
10949 add %r11,%rsp
10950 mov %rdi,%rax
10951 mov %rsi,%rdx
10952 + pax_force_retaddr 0, 1
10953 ret
10954 # bytesatleast65:
10955 ._bytesatleast65:
10956 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
10957 add %r11,%rsp
10958 mov %rdi,%rax
10959 mov %rsi,%rdx
10960 + pax_force_retaddr
10961 ret
10962 # enter ECRYPT_ivsetup
10963 .text
10964 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
10965 add %r11,%rsp
10966 mov %rdi,%rax
10967 mov %rsi,%rdx
10968 + pax_force_retaddr
10969 ret
10970 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10971 index 02b0e9f..cf4cf5c 100644
10972 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10973 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10974 @@ -24,6 +24,8 @@
10975 *
10976 */
10977
10978 +#include <asm/alternative-asm.h>
10979 +
10980 #include "glue_helper-asm-avx.S"
10981
10982 .file "serpent-avx-x86_64-asm_64.S"
10983 @@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
10984 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10985 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10986
10987 + pax_force_retaddr
10988 ret;
10989
10990 .align 8
10991 @@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
10992 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10993 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10994
10995 + pax_force_retaddr
10996 ret;
10997
10998 .align 8
10999 @@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
11000
11001 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11002
11003 + pax_force_retaddr
11004 ret;
11005
11006 .align 8
11007 @@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
11008
11009 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11010
11011 + pax_force_retaddr
11012 ret;
11013
11014 .align 8
11015 @@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
11016
11017 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11018
11019 + pax_force_retaddr
11020 ret;
11021
11022 .align 8
11023 @@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
11024
11025 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11026
11027 + pax_force_retaddr
11028 ret;
11029 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11030 index 3ee1ff0..cbc568b 100644
11031 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11032 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11033 @@ -24,6 +24,8 @@
11034 *
11035 */
11036
11037 +#include <asm/alternative-asm.h>
11038 +
11039 .file "serpent-sse2-x86_64-asm_64.S"
11040 .text
11041
11042 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
11043 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11044 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11045
11046 + pax_force_retaddr
11047 ret;
11048
11049 __enc_xor8:
11050 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11051 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11052
11053 + pax_force_retaddr
11054 ret;
11055
11056 .align 8
11057 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
11058 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11059 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11060
11061 + pax_force_retaddr
11062 ret;
11063 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
11064 index 49d6987..df66bd4 100644
11065 --- a/arch/x86/crypto/sha1_ssse3_asm.S
11066 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
11067 @@ -28,6 +28,8 @@
11068 * (at your option) any later version.
11069 */
11070
11071 +#include <asm/alternative-asm.h>
11072 +
11073 #define CTX %rdi // arg1
11074 #define BUF %rsi // arg2
11075 #define CNT %rdx // arg3
11076 @@ -104,6 +106,7 @@
11077 pop %r12
11078 pop %rbp
11079 pop %rbx
11080 + pax_force_retaddr 0, 1
11081 ret
11082
11083 .size \name, .-\name
11084 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11085 index ebac16b..8092eb9 100644
11086 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11087 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11088 @@ -23,6 +23,8 @@
11089 *
11090 */
11091
11092 +#include <asm/alternative-asm.h>
11093 +
11094 #include "glue_helper-asm-avx.S"
11095
11096 .file "twofish-avx-x86_64-asm_64.S"
11097 @@ -283,6 +285,7 @@ __twofish_enc_blk8:
11098 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11099 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11100
11101 + pax_force_retaddr 0, 1
11102 ret;
11103
11104 .align 8
11105 @@ -324,6 +327,7 @@ __twofish_dec_blk8:
11106 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11107 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11108
11109 + pax_force_retaddr 0, 1
11110 ret;
11111
11112 .align 8
11113 @@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
11114
11115 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11116
11117 + pax_force_retaddr 0, 1
11118 ret;
11119
11120 .align 8
11121 @@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
11122
11123 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11124
11125 + pax_force_retaddr 0, 1
11126 ret;
11127
11128 .align 8
11129 @@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
11130
11131 popq %r12;
11132
11133 + pax_force_retaddr 0, 1
11134 ret;
11135
11136 .align 8
11137 @@ -420,4 +427,5 @@ twofish_ctr_8way:
11138
11139 popq %r12;
11140
11141 + pax_force_retaddr 0, 1
11142 ret;
11143 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11144 index 5b012a2..36d5364 100644
11145 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11146 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11147 @@ -20,6 +20,8 @@
11148 *
11149 */
11150
11151 +#include <asm/alternative-asm.h>
11152 +
11153 .file "twofish-x86_64-asm-3way.S"
11154 .text
11155
11156 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
11157 popq %r13;
11158 popq %r14;
11159 popq %r15;
11160 + pax_force_retaddr 0, 1
11161 ret;
11162
11163 __enc_xor3:
11164 @@ -271,6 +274,7 @@ __enc_xor3:
11165 popq %r13;
11166 popq %r14;
11167 popq %r15;
11168 + pax_force_retaddr 0, 1
11169 ret;
11170
11171 .global twofish_dec_blk_3way
11172 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11173 popq %r13;
11174 popq %r14;
11175 popq %r15;
11176 + pax_force_retaddr 0, 1
11177 ret;
11178
11179 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11180 index 7bcf3fc..f53832f 100644
11181 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11182 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11183 @@ -21,6 +21,7 @@
11184 .text
11185
11186 #include <asm/asm-offsets.h>
11187 +#include <asm/alternative-asm.h>
11188
11189 #define a_offset 0
11190 #define b_offset 4
11191 @@ -268,6 +269,7 @@ twofish_enc_blk:
11192
11193 popq R1
11194 movq $1,%rax
11195 + pax_force_retaddr 0, 1
11196 ret
11197
11198 twofish_dec_blk:
11199 @@ -319,4 +321,5 @@ twofish_dec_blk:
11200
11201 popq R1
11202 movq $1,%rax
11203 + pax_force_retaddr 0, 1
11204 ret
11205 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11206 index a703af1..f5b9c36 100644
11207 --- a/arch/x86/ia32/ia32_aout.c
11208 +++ b/arch/x86/ia32/ia32_aout.c
11209 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11210 unsigned long dump_start, dump_size;
11211 struct user32 dump;
11212
11213 + memset(&dump, 0, sizeof(dump));
11214 +
11215 fs = get_fs();
11216 set_fs(KERNEL_DS);
11217 has_dumped = 1;
11218 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11219 index a1daf4a..f8c4537 100644
11220 --- a/arch/x86/ia32/ia32_signal.c
11221 +++ b/arch/x86/ia32/ia32_signal.c
11222 @@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11223 sp -= frame_size;
11224 /* Align the stack pointer according to the i386 ABI,
11225 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11226 - sp = ((sp + 4) & -16ul) - 4;
11227 + sp = ((sp - 12) & -16ul) - 4;
11228 return (void __user *) sp;
11229 }
11230
11231 @@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11232 * These are actually not used anymore, but left because some
11233 * gdb versions depend on them as a marker.
11234 */
11235 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11236 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11237 } put_user_catch(err);
11238
11239 if (err)
11240 @@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11241 0xb8,
11242 __NR_ia32_rt_sigreturn,
11243 0x80cd,
11244 - 0,
11245 + 0
11246 };
11247
11248 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11249 @@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11250
11251 if (ka->sa.sa_flags & SA_RESTORER)
11252 restorer = ka->sa.sa_restorer;
11253 + else if (current->mm->context.vdso)
11254 + /* Return stub is in 32bit vsyscall page */
11255 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11256 else
11257 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11258 - rt_sigreturn);
11259 + restorer = &frame->retcode;
11260 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11261
11262 /*
11263 * Not actually used anymore, but left because some gdb
11264 * versions need it.
11265 */
11266 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11267 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11268 } put_user_catch(err);
11269
11270 err |= copy_siginfo_to_user32(&frame->info, info);
11271 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11272 index 142c4ce..19b683f 100644
11273 --- a/arch/x86/ia32/ia32entry.S
11274 +++ b/arch/x86/ia32/ia32entry.S
11275 @@ -15,8 +15,10 @@
11276 #include <asm/irqflags.h>
11277 #include <asm/asm.h>
11278 #include <asm/smap.h>
11279 +#include <asm/pgtable.h>
11280 #include <linux/linkage.h>
11281 #include <linux/err.h>
11282 +#include <asm/alternative-asm.h>
11283
11284 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11285 #include <linux/elf-em.h>
11286 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11287 ENDPROC(native_irq_enable_sysexit)
11288 #endif
11289
11290 + .macro pax_enter_kernel_user
11291 + pax_set_fptr_mask
11292 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11293 + call pax_enter_kernel_user
11294 +#endif
11295 + .endm
11296 +
11297 + .macro pax_exit_kernel_user
11298 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11299 + call pax_exit_kernel_user
11300 +#endif
11301 +#ifdef CONFIG_PAX_RANDKSTACK
11302 + pushq %rax
11303 + pushq %r11
11304 + call pax_randomize_kstack
11305 + popq %r11
11306 + popq %rax
11307 +#endif
11308 + .endm
11309 +
11310 +.macro pax_erase_kstack
11311 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11312 + call pax_erase_kstack
11313 +#endif
11314 +.endm
11315 +
11316 /*
11317 * 32bit SYSENTER instruction entry.
11318 *
11319 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11320 CFI_REGISTER rsp,rbp
11321 SWAPGS_UNSAFE_STACK
11322 movq PER_CPU_VAR(kernel_stack), %rsp
11323 - addq $(KERNEL_STACK_OFFSET),%rsp
11324 - /*
11325 - * No need to follow this irqs on/off section: the syscall
11326 - * disabled irqs, here we enable it straight after entry:
11327 - */
11328 - ENABLE_INTERRUPTS(CLBR_NONE)
11329 movl %ebp,%ebp /* zero extension */
11330 pushq_cfi $__USER32_DS
11331 /*CFI_REL_OFFSET ss,0*/
11332 @@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11333 CFI_REL_OFFSET rsp,0
11334 pushfq_cfi
11335 /*CFI_REL_OFFSET rflags,0*/
11336 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11337 - CFI_REGISTER rip,r10
11338 + orl $X86_EFLAGS_IF,(%rsp)
11339 + GET_THREAD_INFO(%r11)
11340 + movl TI_sysenter_return(%r11), %r11d
11341 + CFI_REGISTER rip,r11
11342 pushq_cfi $__USER32_CS
11343 /*CFI_REL_OFFSET cs,0*/
11344 movl %eax, %eax
11345 - pushq_cfi %r10
11346 + pushq_cfi %r11
11347 CFI_REL_OFFSET rip,0
11348 pushq_cfi %rax
11349 cld
11350 SAVE_ARGS 0,1,0
11351 + pax_enter_kernel_user
11352 +
11353 +#ifdef CONFIG_PAX_RANDKSTACK
11354 + pax_erase_kstack
11355 +#endif
11356 +
11357 + /*
11358 + * No need to follow this irqs on/off section: the syscall
11359 + * disabled irqs, here we enable it straight after entry:
11360 + */
11361 + ENABLE_INTERRUPTS(CLBR_NONE)
11362 /* no need to do an access_ok check here because rbp has been
11363 32bit zero extended */
11364 +
11365 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11366 + mov $PAX_USER_SHADOW_BASE,%r11
11367 + add %r11,%rbp
11368 +#endif
11369 +
11370 ASM_STAC
11371 1: movl (%rbp),%ebp
11372 _ASM_EXTABLE(1b,ia32_badarg)
11373 ASM_CLAC
11374 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11375 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11376 + GET_THREAD_INFO(%r11)
11377 + orl $TS_COMPAT,TI_status(%r11)
11378 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11379 CFI_REMEMBER_STATE
11380 jnz sysenter_tracesys
11381 cmpq $(IA32_NR_syscalls-1),%rax
11382 @@ -162,12 +204,15 @@ sysenter_do_call:
11383 sysenter_dispatch:
11384 call *ia32_sys_call_table(,%rax,8)
11385 movq %rax,RAX-ARGOFFSET(%rsp)
11386 + GET_THREAD_INFO(%r11)
11387 DISABLE_INTERRUPTS(CLBR_NONE)
11388 TRACE_IRQS_OFF
11389 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11390 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11391 jnz sysexit_audit
11392 sysexit_from_sys_call:
11393 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11394 + pax_exit_kernel_user
11395 + pax_erase_kstack
11396 + andl $~TS_COMPAT,TI_status(%r11)
11397 /* clear IF, that popfq doesn't enable interrupts early */
11398 andl $~0x200,EFLAGS-R11(%rsp)
11399 movl RIP-R11(%rsp),%edx /* User %eip */
11400 @@ -193,6 +238,9 @@ sysexit_from_sys_call:
11401 movl %eax,%esi /* 2nd arg: syscall number */
11402 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11403 call __audit_syscall_entry
11404 +
11405 + pax_erase_kstack
11406 +
11407 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11408 cmpq $(IA32_NR_syscalls-1),%rax
11409 ja ia32_badsys
11410 @@ -204,7 +252,7 @@ sysexit_from_sys_call:
11411 .endm
11412
11413 .macro auditsys_exit exit
11414 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11415 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11416 jnz ia32_ret_from_sys_call
11417 TRACE_IRQS_ON
11418 ENABLE_INTERRUPTS(CLBR_NONE)
11419 @@ -215,11 +263,12 @@ sysexit_from_sys_call:
11420 1: setbe %al /* 1 if error, 0 if not */
11421 movzbl %al,%edi /* zero-extend that into %edi */
11422 call __audit_syscall_exit
11423 + GET_THREAD_INFO(%r11)
11424 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11425 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11426 DISABLE_INTERRUPTS(CLBR_NONE)
11427 TRACE_IRQS_OFF
11428 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11429 + testl %edi,TI_flags(%r11)
11430 jz \exit
11431 CLEAR_RREGS -ARGOFFSET
11432 jmp int_with_check
11433 @@ -237,7 +286,7 @@ sysexit_audit:
11434
11435 sysenter_tracesys:
11436 #ifdef CONFIG_AUDITSYSCALL
11437 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11438 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11439 jz sysenter_auditsys
11440 #endif
11441 SAVE_REST
11442 @@ -249,6 +298,9 @@ sysenter_tracesys:
11443 RESTORE_REST
11444 cmpq $(IA32_NR_syscalls-1),%rax
11445 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11446 +
11447 + pax_erase_kstack
11448 +
11449 jmp sysenter_do_call
11450 CFI_ENDPROC
11451 ENDPROC(ia32_sysenter_target)
11452 @@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11453 ENTRY(ia32_cstar_target)
11454 CFI_STARTPROC32 simple
11455 CFI_SIGNAL_FRAME
11456 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11457 + CFI_DEF_CFA rsp,0
11458 CFI_REGISTER rip,rcx
11459 /*CFI_REGISTER rflags,r11*/
11460 SWAPGS_UNSAFE_STACK
11461 movl %esp,%r8d
11462 CFI_REGISTER rsp,r8
11463 movq PER_CPU_VAR(kernel_stack),%rsp
11464 + SAVE_ARGS 8*6,0,0
11465 + pax_enter_kernel_user
11466 +
11467 +#ifdef CONFIG_PAX_RANDKSTACK
11468 + pax_erase_kstack
11469 +#endif
11470 +
11471 /*
11472 * No need to follow this irqs on/off section: the syscall
11473 * disabled irqs and here we enable it straight after entry:
11474 */
11475 ENABLE_INTERRUPTS(CLBR_NONE)
11476 - SAVE_ARGS 8,0,0
11477 movl %eax,%eax /* zero extension */
11478 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11479 movq %rcx,RIP-ARGOFFSET(%rsp)
11480 @@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11481 /* no need to do an access_ok check here because r8 has been
11482 32bit zero extended */
11483 /* hardware stack frame is complete now */
11484 +
11485 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11486 + mov $PAX_USER_SHADOW_BASE,%r11
11487 + add %r11,%r8
11488 +#endif
11489 +
11490 ASM_STAC
11491 1: movl (%r8),%r9d
11492 _ASM_EXTABLE(1b,ia32_badarg)
11493 ASM_CLAC
11494 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11495 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11496 + GET_THREAD_INFO(%r11)
11497 + orl $TS_COMPAT,TI_status(%r11)
11498 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11499 CFI_REMEMBER_STATE
11500 jnz cstar_tracesys
11501 cmpq $IA32_NR_syscalls-1,%rax
11502 @@ -319,12 +384,15 @@ cstar_do_call:
11503 cstar_dispatch:
11504 call *ia32_sys_call_table(,%rax,8)
11505 movq %rax,RAX-ARGOFFSET(%rsp)
11506 + GET_THREAD_INFO(%r11)
11507 DISABLE_INTERRUPTS(CLBR_NONE)
11508 TRACE_IRQS_OFF
11509 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11510 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11511 jnz sysretl_audit
11512 sysretl_from_sys_call:
11513 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11514 + pax_exit_kernel_user
11515 + pax_erase_kstack
11516 + andl $~TS_COMPAT,TI_status(%r11)
11517 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11518 movl RIP-ARGOFFSET(%rsp),%ecx
11519 CFI_REGISTER rip,rcx
11520 @@ -352,7 +420,7 @@ sysretl_audit:
11521
11522 cstar_tracesys:
11523 #ifdef CONFIG_AUDITSYSCALL
11524 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11525 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11526 jz cstar_auditsys
11527 #endif
11528 xchgl %r9d,%ebp
11529 @@ -366,6 +434,9 @@ cstar_tracesys:
11530 xchgl %ebp,%r9d
11531 cmpq $(IA32_NR_syscalls-1),%rax
11532 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11533 +
11534 + pax_erase_kstack
11535 +
11536 jmp cstar_do_call
11537 END(ia32_cstar_target)
11538
11539 @@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11540 CFI_REL_OFFSET rip,RIP-RIP
11541 PARAVIRT_ADJUST_EXCEPTION_FRAME
11542 SWAPGS
11543 - /*
11544 - * No need to follow this irqs on/off section: the syscall
11545 - * disabled irqs and here we enable it straight after entry:
11546 - */
11547 - ENABLE_INTERRUPTS(CLBR_NONE)
11548 movl %eax,%eax
11549 pushq_cfi %rax
11550 cld
11551 /* note the registers are not zero extended to the sf.
11552 this could be a problem. */
11553 SAVE_ARGS 0,1,0
11554 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11555 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11556 + pax_enter_kernel_user
11557 +
11558 +#ifdef CONFIG_PAX_RANDKSTACK
11559 + pax_erase_kstack
11560 +#endif
11561 +
11562 + /*
11563 + * No need to follow this irqs on/off section: the syscall
11564 + * disabled irqs and here we enable it straight after entry:
11565 + */
11566 + ENABLE_INTERRUPTS(CLBR_NONE)
11567 + GET_THREAD_INFO(%r11)
11568 + orl $TS_COMPAT,TI_status(%r11)
11569 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11570 jnz ia32_tracesys
11571 cmpq $(IA32_NR_syscalls-1),%rax
11572 ja ia32_badsys
11573 @@ -442,6 +520,9 @@ ia32_tracesys:
11574 RESTORE_REST
11575 cmpq $(IA32_NR_syscalls-1),%rax
11576 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11577 +
11578 + pax_erase_kstack
11579 +
11580 jmp ia32_do_call
11581 END(ia32_syscall)
11582
11583 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11584 index d0b689b..34be51d 100644
11585 --- a/arch/x86/ia32/sys_ia32.c
11586 +++ b/arch/x86/ia32/sys_ia32.c
11587 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11588 */
11589 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11590 {
11591 - typeof(ubuf->st_uid) uid = 0;
11592 - typeof(ubuf->st_gid) gid = 0;
11593 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
11594 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
11595 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11596 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11597 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11598 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
11599 mm_segment_t old_fs = get_fs();
11600
11601 set_fs(KERNEL_DS);
11602 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
11603 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
11604 set_fs(old_fs);
11605 if (put_compat_timespec(&t, interval))
11606 return -EFAULT;
11607 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
11608 mm_segment_t old_fs = get_fs();
11609
11610 set_fs(KERNEL_DS);
11611 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
11612 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
11613 set_fs(old_fs);
11614 if (!ret) {
11615 switch (_NSIG_WORDS) {
11616 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
11617 if (copy_siginfo_from_user32(&info, uinfo))
11618 return -EFAULT;
11619 set_fs(KERNEL_DS);
11620 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
11621 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
11622 set_fs(old_fs);
11623 return ret;
11624 }
11625 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11626 return -EFAULT;
11627
11628 set_fs(KERNEL_DS);
11629 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11630 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11631 count);
11632 set_fs(old_fs);
11633
11634 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11635 index 372231c..a5aa1a1 100644
11636 --- a/arch/x86/include/asm/alternative-asm.h
11637 +++ b/arch/x86/include/asm/alternative-asm.h
11638 @@ -18,6 +18,45 @@
11639 .endm
11640 #endif
11641
11642 +#ifdef KERNEXEC_PLUGIN
11643 + .macro pax_force_retaddr_bts rip=0
11644 + btsq $63,\rip(%rsp)
11645 + .endm
11646 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11647 + .macro pax_force_retaddr rip=0, reload=0
11648 + btsq $63,\rip(%rsp)
11649 + .endm
11650 + .macro pax_force_fptr ptr
11651 + btsq $63,\ptr
11652 + .endm
11653 + .macro pax_set_fptr_mask
11654 + .endm
11655 +#endif
11656 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11657 + .macro pax_force_retaddr rip=0, reload=0
11658 + .if \reload
11659 + pax_set_fptr_mask
11660 + .endif
11661 + orq %r10,\rip(%rsp)
11662 + .endm
11663 + .macro pax_force_fptr ptr
11664 + orq %r10,\ptr
11665 + .endm
11666 + .macro pax_set_fptr_mask
11667 + movabs $0x8000000000000000,%r10
11668 + .endm
11669 +#endif
11670 +#else
11671 + .macro pax_force_retaddr rip=0, reload=0
11672 + .endm
11673 + .macro pax_force_fptr ptr
11674 + .endm
11675 + .macro pax_force_retaddr_bts rip=0
11676 + .endm
11677 + .macro pax_set_fptr_mask
11678 + .endm
11679 +#endif
11680 +
11681 .macro altinstruction_entry orig alt feature orig_len alt_len
11682 .long \orig - .
11683 .long \alt - .
11684 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11685 index 58ed6d9..f1cbe58 100644
11686 --- a/arch/x86/include/asm/alternative.h
11687 +++ b/arch/x86/include/asm/alternative.h
11688 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11689 ".pushsection .discard,\"aw\",@progbits\n" \
11690 DISCARD_ENTRY(1) \
11691 ".popsection\n" \
11692 - ".pushsection .altinstr_replacement, \"ax\"\n" \
11693 + ".pushsection .altinstr_replacement, \"a\"\n" \
11694 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11695 ".popsection"
11696
11697 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11698 DISCARD_ENTRY(1) \
11699 DISCARD_ENTRY(2) \
11700 ".popsection\n" \
11701 - ".pushsection .altinstr_replacement, \"ax\"\n" \
11702 + ".pushsection .altinstr_replacement, \"a\"\n" \
11703 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11704 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11705 ".popsection"
11706 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11707 index 3388034..050f0b9 100644
11708 --- a/arch/x86/include/asm/apic.h
11709 +++ b/arch/x86/include/asm/apic.h
11710 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11711
11712 #ifdef CONFIG_X86_LOCAL_APIC
11713
11714 -extern unsigned int apic_verbosity;
11715 +extern int apic_verbosity;
11716 extern int local_apic_timer_c2_ok;
11717
11718 extern int disable_apic;
11719 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11720 index 20370c6..a2eb9b0 100644
11721 --- a/arch/x86/include/asm/apm.h
11722 +++ b/arch/x86/include/asm/apm.h
11723 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11724 __asm__ __volatile__(APM_DO_ZERO_SEGS
11725 "pushl %%edi\n\t"
11726 "pushl %%ebp\n\t"
11727 - "lcall *%%cs:apm_bios_entry\n\t"
11728 + "lcall *%%ss:apm_bios_entry\n\t"
11729 "setc %%al\n\t"
11730 "popl %%ebp\n\t"
11731 "popl %%edi\n\t"
11732 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11733 __asm__ __volatile__(APM_DO_ZERO_SEGS
11734 "pushl %%edi\n\t"
11735 "pushl %%ebp\n\t"
11736 - "lcall *%%cs:apm_bios_entry\n\t"
11737 + "lcall *%%ss:apm_bios_entry\n\t"
11738 "setc %%bl\n\t"
11739 "popl %%ebp\n\t"
11740 "popl %%edi\n\t"
11741 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11742 index 722aa3b..3a0bb27 100644
11743 --- a/arch/x86/include/asm/atomic.h
11744 +++ b/arch/x86/include/asm/atomic.h
11745 @@ -22,7 +22,18 @@
11746 */
11747 static inline int atomic_read(const atomic_t *v)
11748 {
11749 - return (*(volatile int *)&(v)->counter);
11750 + return (*(volatile const int *)&(v)->counter);
11751 +}
11752 +
11753 +/**
11754 + * atomic_read_unchecked - read atomic variable
11755 + * @v: pointer of type atomic_unchecked_t
11756 + *
11757 + * Atomically reads the value of @v.
11758 + */
11759 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11760 +{
11761 + return (*(volatile const int *)&(v)->counter);
11762 }
11763
11764 /**
11765 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
11766 }
11767
11768 /**
11769 + * atomic_set_unchecked - set atomic variable
11770 + * @v: pointer of type atomic_unchecked_t
11771 + * @i: required value
11772 + *
11773 + * Atomically sets the value of @v to @i.
11774 + */
11775 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
11776 +{
11777 + v->counter = i;
11778 +}
11779 +
11780 +/**
11781 * atomic_add - add integer to atomic variable
11782 * @i: integer value to add
11783 * @v: pointer of type atomic_t
11784 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
11785 */
11786 static inline void atomic_add(int i, atomic_t *v)
11787 {
11788 - asm volatile(LOCK_PREFIX "addl %1,%0"
11789 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
11790 +
11791 +#ifdef CONFIG_PAX_REFCOUNT
11792 + "jno 0f\n"
11793 + LOCK_PREFIX "subl %1,%0\n"
11794 + "int $4\n0:\n"
11795 + _ASM_EXTABLE(0b, 0b)
11796 +#endif
11797 +
11798 + : "+m" (v->counter)
11799 + : "ir" (i));
11800 +}
11801 +
11802 +/**
11803 + * atomic_add_unchecked - add integer to atomic variable
11804 + * @i: integer value to add
11805 + * @v: pointer of type atomic_unchecked_t
11806 + *
11807 + * Atomically adds @i to @v.
11808 + */
11809 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
11810 +{
11811 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
11812 : "+m" (v->counter)
11813 : "ir" (i));
11814 }
11815 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
11816 */
11817 static inline void atomic_sub(int i, atomic_t *v)
11818 {
11819 - asm volatile(LOCK_PREFIX "subl %1,%0"
11820 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
11821 +
11822 +#ifdef CONFIG_PAX_REFCOUNT
11823 + "jno 0f\n"
11824 + LOCK_PREFIX "addl %1,%0\n"
11825 + "int $4\n0:\n"
11826 + _ASM_EXTABLE(0b, 0b)
11827 +#endif
11828 +
11829 + : "+m" (v->counter)
11830 + : "ir" (i));
11831 +}
11832 +
11833 +/**
11834 + * atomic_sub_unchecked - subtract integer from atomic variable
11835 + * @i: integer value to subtract
11836 + * @v: pointer of type atomic_unchecked_t
11837 + *
11838 + * Atomically subtracts @i from @v.
11839 + */
11840 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
11841 +{
11842 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
11843 : "+m" (v->counter)
11844 : "ir" (i));
11845 }
11846 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11847 {
11848 unsigned char c;
11849
11850 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
11851 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
11852 +
11853 +#ifdef CONFIG_PAX_REFCOUNT
11854 + "jno 0f\n"
11855 + LOCK_PREFIX "addl %2,%0\n"
11856 + "int $4\n0:\n"
11857 + _ASM_EXTABLE(0b, 0b)
11858 +#endif
11859 +
11860 + "sete %1\n"
11861 : "+m" (v->counter), "=qm" (c)
11862 : "ir" (i) : "memory");
11863 return c;
11864 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11865 */
11866 static inline void atomic_inc(atomic_t *v)
11867 {
11868 - asm volatile(LOCK_PREFIX "incl %0"
11869 + asm volatile(LOCK_PREFIX "incl %0\n"
11870 +
11871 +#ifdef CONFIG_PAX_REFCOUNT
11872 + "jno 0f\n"
11873 + LOCK_PREFIX "decl %0\n"
11874 + "int $4\n0:\n"
11875 + _ASM_EXTABLE(0b, 0b)
11876 +#endif
11877 +
11878 + : "+m" (v->counter));
11879 +}
11880 +
11881 +/**
11882 + * atomic_inc_unchecked - increment atomic variable
11883 + * @v: pointer of type atomic_unchecked_t
11884 + *
11885 + * Atomically increments @v by 1.
11886 + */
11887 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
11888 +{
11889 + asm volatile(LOCK_PREFIX "incl %0\n"
11890 : "+m" (v->counter));
11891 }
11892
11893 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
11894 */
11895 static inline void atomic_dec(atomic_t *v)
11896 {
11897 - asm volatile(LOCK_PREFIX "decl %0"
11898 + asm volatile(LOCK_PREFIX "decl %0\n"
11899 +
11900 +#ifdef CONFIG_PAX_REFCOUNT
11901 + "jno 0f\n"
11902 + LOCK_PREFIX "incl %0\n"
11903 + "int $4\n0:\n"
11904 + _ASM_EXTABLE(0b, 0b)
11905 +#endif
11906 +
11907 + : "+m" (v->counter));
11908 +}
11909 +
11910 +/**
11911 + * atomic_dec_unchecked - decrement atomic variable
11912 + * @v: pointer of type atomic_unchecked_t
11913 + *
11914 + * Atomically decrements @v by 1.
11915 + */
11916 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
11917 +{
11918 + asm volatile(LOCK_PREFIX "decl %0\n"
11919 : "+m" (v->counter));
11920 }
11921
11922 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
11923 {
11924 unsigned char c;
11925
11926 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
11927 + asm volatile(LOCK_PREFIX "decl %0\n"
11928 +
11929 +#ifdef CONFIG_PAX_REFCOUNT
11930 + "jno 0f\n"
11931 + LOCK_PREFIX "incl %0\n"
11932 + "int $4\n0:\n"
11933 + _ASM_EXTABLE(0b, 0b)
11934 +#endif
11935 +
11936 + "sete %1\n"
11937 : "+m" (v->counter), "=qm" (c)
11938 : : "memory");
11939 return c != 0;
11940 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
11941 {
11942 unsigned char c;
11943
11944 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
11945 + asm volatile(LOCK_PREFIX "incl %0\n"
11946 +
11947 +#ifdef CONFIG_PAX_REFCOUNT
11948 + "jno 0f\n"
11949 + LOCK_PREFIX "decl %0\n"
11950 + "int $4\n0:\n"
11951 + _ASM_EXTABLE(0b, 0b)
11952 +#endif
11953 +
11954 + "sete %1\n"
11955 + : "+m" (v->counter), "=qm" (c)
11956 + : : "memory");
11957 + return c != 0;
11958 +}
11959 +
11960 +/**
11961 + * atomic_inc_and_test_unchecked - increment and test
11962 + * @v: pointer of type atomic_unchecked_t
11963 + *
11964 + * Atomically increments @v by 1
11965 + * and returns true if the result is zero, or false for all
11966 + * other cases.
11967 + */
11968 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
11969 +{
11970 + unsigned char c;
11971 +
11972 + asm volatile(LOCK_PREFIX "incl %0\n"
11973 + "sete %1\n"
11974 : "+m" (v->counter), "=qm" (c)
11975 : : "memory");
11976 return c != 0;
11977 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11978 {
11979 unsigned char c;
11980
11981 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
11982 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
11983 +
11984 +#ifdef CONFIG_PAX_REFCOUNT
11985 + "jno 0f\n"
11986 + LOCK_PREFIX "subl %2,%0\n"
11987 + "int $4\n0:\n"
11988 + _ASM_EXTABLE(0b, 0b)
11989 +#endif
11990 +
11991 + "sets %1\n"
11992 : "+m" (v->counter), "=qm" (c)
11993 : "ir" (i) : "memory");
11994 return c;
11995 @@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11996 */
11997 static inline int atomic_add_return(int i, atomic_t *v)
11998 {
11999 + return i + xadd_check_overflow(&v->counter, i);
12000 +}
12001 +
12002 +/**
12003 + * atomic_add_return_unchecked - add integer and return
12004 + * @i: integer value to add
12005 + * @v: pointer of type atomic_unchecked_t
12006 + *
12007 + * Atomically adds @i to @v and returns @i + @v
12008 + */
12009 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
12010 +{
12011 return i + xadd(&v->counter, i);
12012 }
12013
12014 @@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
12015 }
12016
12017 #define atomic_inc_return(v) (atomic_add_return(1, v))
12018 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
12019 +{
12020 + return atomic_add_return_unchecked(1, v);
12021 +}
12022 #define atomic_dec_return(v) (atomic_sub_return(1, v))
12023
12024 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12025 @@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12026 return cmpxchg(&v->counter, old, new);
12027 }
12028
12029 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
12030 +{
12031 + return cmpxchg(&v->counter, old, new);
12032 +}
12033 +
12034 static inline int atomic_xchg(atomic_t *v, int new)
12035 {
12036 return xchg(&v->counter, new);
12037 }
12038
12039 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
12040 +{
12041 + return xchg(&v->counter, new);
12042 +}
12043 +
12044 /**
12045 * __atomic_add_unless - add unless the number is already a given value
12046 * @v: pointer of type atomic_t
12047 @@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
12048 */
12049 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12050 {
12051 - int c, old;
12052 + int c, old, new;
12053 c = atomic_read(v);
12054 for (;;) {
12055 - if (unlikely(c == (u)))
12056 + if (unlikely(c == u))
12057 break;
12058 - old = atomic_cmpxchg((v), c, c + (a));
12059 +
12060 + asm volatile("addl %2,%0\n"
12061 +
12062 +#ifdef CONFIG_PAX_REFCOUNT
12063 + "jno 0f\n"
12064 + "subl %2,%0\n"
12065 + "int $4\n0:\n"
12066 + _ASM_EXTABLE(0b, 0b)
12067 +#endif
12068 +
12069 + : "=r" (new)
12070 + : "0" (c), "ir" (a));
12071 +
12072 + old = atomic_cmpxchg(v, c, new);
12073 if (likely(old == c))
12074 break;
12075 c = old;
12076 @@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12077 }
12078
12079 /**
12080 + * atomic_inc_not_zero_hint - increment if not null
12081 + * @v: pointer of type atomic_t
12082 + * @hint: probable value of the atomic before the increment
12083 + *
12084 + * This version of atomic_inc_not_zero() gives a hint of probable
12085 + * value of the atomic. This helps processor to not read the memory
12086 + * before doing the atomic read/modify/write cycle, lowering
12087 + * number of bus transactions on some arches.
12088 + *
12089 + * Returns: 0 if increment was not done, 1 otherwise.
12090 + */
12091 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12092 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12093 +{
12094 + int val, c = hint, new;
12095 +
12096 + /* sanity test, should be removed by compiler if hint is a constant */
12097 + if (!hint)
12098 + return __atomic_add_unless(v, 1, 0);
12099 +
12100 + do {
12101 + asm volatile("incl %0\n"
12102 +
12103 +#ifdef CONFIG_PAX_REFCOUNT
12104 + "jno 0f\n"
12105 + "decl %0\n"
12106 + "int $4\n0:\n"
12107 + _ASM_EXTABLE(0b, 0b)
12108 +#endif
12109 +
12110 + : "=r" (new)
12111 + : "0" (c));
12112 +
12113 + val = atomic_cmpxchg(v, c, new);
12114 + if (val == c)
12115 + return 1;
12116 + c = val;
12117 + } while (c);
12118 +
12119 + return 0;
12120 +}
12121 +
12122 +/**
12123 * atomic_inc_short - increment of a short integer
12124 * @v: pointer to type int
12125 *
12126 @@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12127 #endif
12128
12129 /* These are x86-specific, used by some header files */
12130 -#define atomic_clear_mask(mask, addr) \
12131 - asm volatile(LOCK_PREFIX "andl %0,%1" \
12132 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
12133 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12134 +{
12135 + asm volatile(LOCK_PREFIX "andl %1,%0"
12136 + : "+m" (v->counter)
12137 + : "r" (~(mask))
12138 + : "memory");
12139 +}
12140
12141 -#define atomic_set_mask(mask, addr) \
12142 - asm volatile(LOCK_PREFIX "orl %0,%1" \
12143 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12144 - : "memory")
12145 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12146 +{
12147 + asm volatile(LOCK_PREFIX "andl %1,%0"
12148 + : "+m" (v->counter)
12149 + : "r" (~(mask))
12150 + : "memory");
12151 +}
12152 +
12153 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12154 +{
12155 + asm volatile(LOCK_PREFIX "orl %1,%0"
12156 + : "+m" (v->counter)
12157 + : "r" (mask)
12158 + : "memory");
12159 +}
12160 +
12161 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12162 +{
12163 + asm volatile(LOCK_PREFIX "orl %1,%0"
12164 + : "+m" (v->counter)
12165 + : "r" (mask)
12166 + : "memory");
12167 +}
12168
12169 /* Atomic operations are already serializing on x86 */
12170 #define smp_mb__before_atomic_dec() barrier()
12171 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12172 index b154de7..aadebd8 100644
12173 --- a/arch/x86/include/asm/atomic64_32.h
12174 +++ b/arch/x86/include/asm/atomic64_32.h
12175 @@ -12,6 +12,14 @@ typedef struct {
12176 u64 __aligned(8) counter;
12177 } atomic64_t;
12178
12179 +#ifdef CONFIG_PAX_REFCOUNT
12180 +typedef struct {
12181 + u64 __aligned(8) counter;
12182 +} atomic64_unchecked_t;
12183 +#else
12184 +typedef atomic64_t atomic64_unchecked_t;
12185 +#endif
12186 +
12187 #define ATOMIC64_INIT(val) { (val) }
12188
12189 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12190 @@ -37,21 +45,31 @@ typedef struct {
12191 ATOMIC64_DECL_ONE(sym##_386)
12192
12193 ATOMIC64_DECL_ONE(add_386);
12194 +ATOMIC64_DECL_ONE(add_unchecked_386);
12195 ATOMIC64_DECL_ONE(sub_386);
12196 +ATOMIC64_DECL_ONE(sub_unchecked_386);
12197 ATOMIC64_DECL_ONE(inc_386);
12198 +ATOMIC64_DECL_ONE(inc_unchecked_386);
12199 ATOMIC64_DECL_ONE(dec_386);
12200 +ATOMIC64_DECL_ONE(dec_unchecked_386);
12201 #endif
12202
12203 #define alternative_atomic64(f, out, in...) \
12204 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12205
12206 ATOMIC64_DECL(read);
12207 +ATOMIC64_DECL(read_unchecked);
12208 ATOMIC64_DECL(set);
12209 +ATOMIC64_DECL(set_unchecked);
12210 ATOMIC64_DECL(xchg);
12211 ATOMIC64_DECL(add_return);
12212 +ATOMIC64_DECL(add_return_unchecked);
12213 ATOMIC64_DECL(sub_return);
12214 +ATOMIC64_DECL(sub_return_unchecked);
12215 ATOMIC64_DECL(inc_return);
12216 +ATOMIC64_DECL(inc_return_unchecked);
12217 ATOMIC64_DECL(dec_return);
12218 +ATOMIC64_DECL(dec_return_unchecked);
12219 ATOMIC64_DECL(dec_if_positive);
12220 ATOMIC64_DECL(inc_not_zero);
12221 ATOMIC64_DECL(add_unless);
12222 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12223 }
12224
12225 /**
12226 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12227 + * @p: pointer to type atomic64_unchecked_t
12228 + * @o: expected value
12229 + * @n: new value
12230 + *
12231 + * Atomically sets @v to @n if it was equal to @o and returns
12232 + * the old value.
12233 + */
12234 +
12235 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12236 +{
12237 + return cmpxchg64(&v->counter, o, n);
12238 +}
12239 +
12240 +/**
12241 * atomic64_xchg - xchg atomic64 variable
12242 * @v: pointer to type atomic64_t
12243 * @n: value to assign
12244 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12245 }
12246
12247 /**
12248 + * atomic64_set_unchecked - set atomic64 variable
12249 + * @v: pointer to type atomic64_unchecked_t
12250 + * @n: value to assign
12251 + *
12252 + * Atomically sets the value of @v to @n.
12253 + */
12254 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12255 +{
12256 + unsigned high = (unsigned)(i >> 32);
12257 + unsigned low = (unsigned)i;
12258 + alternative_atomic64(set, /* no output */,
12259 + "S" (v), "b" (low), "c" (high)
12260 + : "eax", "edx", "memory");
12261 +}
12262 +
12263 +/**
12264 * atomic64_read - read atomic64 variable
12265 * @v: pointer to type atomic64_t
12266 *
12267 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12268 }
12269
12270 /**
12271 + * atomic64_read_unchecked - read atomic64 variable
12272 + * @v: pointer to type atomic64_unchecked_t
12273 + *
12274 + * Atomically reads the value of @v and returns it.
12275 + */
12276 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12277 +{
12278 + long long r;
12279 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12280 + return r;
12281 + }
12282 +
12283 +/**
12284 * atomic64_add_return - add and return
12285 * @i: integer value to add
12286 * @v: pointer to type atomic64_t
12287 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12288 return i;
12289 }
12290
12291 +/**
12292 + * atomic64_add_return_unchecked - add and return
12293 + * @i: integer value to add
12294 + * @v: pointer to type atomic64_unchecked_t
12295 + *
12296 + * Atomically adds @i to @v and returns @i + *@v
12297 + */
12298 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12299 +{
12300 + alternative_atomic64(add_return_unchecked,
12301 + ASM_OUTPUT2("+A" (i), "+c" (v)),
12302 + ASM_NO_INPUT_CLOBBER("memory"));
12303 + return i;
12304 +}
12305 +
12306 /*
12307 * Other variants with different arithmetic operators:
12308 */
12309 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12310 return a;
12311 }
12312
12313 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12314 +{
12315 + long long a;
12316 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
12317 + "S" (v) : "memory", "ecx");
12318 + return a;
12319 +}
12320 +
12321 static inline long long atomic64_dec_return(atomic64_t *v)
12322 {
12323 long long a;
12324 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12325 }
12326
12327 /**
12328 + * atomic64_add_unchecked - add integer to atomic64 variable
12329 + * @i: integer value to add
12330 + * @v: pointer to type atomic64_unchecked_t
12331 + *
12332 + * Atomically adds @i to @v.
12333 + */
12334 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12335 +{
12336 + __alternative_atomic64(add_unchecked, add_return_unchecked,
12337 + ASM_OUTPUT2("+A" (i), "+c" (v)),
12338 + ASM_NO_INPUT_CLOBBER("memory"));
12339 + return i;
12340 +}
12341 +
12342 +/**
12343 * atomic64_sub - subtract the atomic64 variable
12344 * @i: integer value to subtract
12345 * @v: pointer to type atomic64_t
12346 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12347 index 0e1cbfc..5623683 100644
12348 --- a/arch/x86/include/asm/atomic64_64.h
12349 +++ b/arch/x86/include/asm/atomic64_64.h
12350 @@ -18,7 +18,19 @@
12351 */
12352 static inline long atomic64_read(const atomic64_t *v)
12353 {
12354 - return (*(volatile long *)&(v)->counter);
12355 + return (*(volatile const long *)&(v)->counter);
12356 +}
12357 +
12358 +/**
12359 + * atomic64_read_unchecked - read atomic64 variable
12360 + * @v: pointer of type atomic64_unchecked_t
12361 + *
12362 + * Atomically reads the value of @v.
12363 + * Doesn't imply a read memory barrier.
12364 + */
12365 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12366 +{
12367 + return (*(volatile const long *)&(v)->counter);
12368 }
12369
12370 /**
12371 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12372 }
12373
12374 /**
12375 + * atomic64_set_unchecked - set atomic64 variable
12376 + * @v: pointer to type atomic64_unchecked_t
12377 + * @i: required value
12378 + *
12379 + * Atomically sets the value of @v to @i.
12380 + */
12381 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12382 +{
12383 + v->counter = i;
12384 +}
12385 +
12386 +/**
12387 * atomic64_add - add integer to atomic64 variable
12388 * @i: integer value to add
12389 * @v: pointer to type atomic64_t
12390 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12391 */
12392 static inline void atomic64_add(long i, atomic64_t *v)
12393 {
12394 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
12395 +
12396 +#ifdef CONFIG_PAX_REFCOUNT
12397 + "jno 0f\n"
12398 + LOCK_PREFIX "subq %1,%0\n"
12399 + "int $4\n0:\n"
12400 + _ASM_EXTABLE(0b, 0b)
12401 +#endif
12402 +
12403 + : "=m" (v->counter)
12404 + : "er" (i), "m" (v->counter));
12405 +}
12406 +
12407 +/**
12408 + * atomic64_add_unchecked - add integer to atomic64 variable
12409 + * @i: integer value to add
12410 + * @v: pointer to type atomic64_unchecked_t
12411 + *
12412 + * Atomically adds @i to @v.
12413 + */
12414 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12415 +{
12416 asm volatile(LOCK_PREFIX "addq %1,%0"
12417 : "=m" (v->counter)
12418 : "er" (i), "m" (v->counter));
12419 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12420 */
12421 static inline void atomic64_sub(long i, atomic64_t *v)
12422 {
12423 - asm volatile(LOCK_PREFIX "subq %1,%0"
12424 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
12425 +
12426 +#ifdef CONFIG_PAX_REFCOUNT
12427 + "jno 0f\n"
12428 + LOCK_PREFIX "addq %1,%0\n"
12429 + "int $4\n0:\n"
12430 + _ASM_EXTABLE(0b, 0b)
12431 +#endif
12432 +
12433 + : "=m" (v->counter)
12434 + : "er" (i), "m" (v->counter));
12435 +}
12436 +
12437 +/**
12438 + * atomic64_sub_unchecked - subtract the atomic64 variable
12439 + * @i: integer value to subtract
12440 + * @v: pointer to type atomic64_unchecked_t
12441 + *
12442 + * Atomically subtracts @i from @v.
12443 + */
12444 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12445 +{
12446 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
12447 : "=m" (v->counter)
12448 : "er" (i), "m" (v->counter));
12449 }
12450 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12451 {
12452 unsigned char c;
12453
12454 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12455 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
12456 +
12457 +#ifdef CONFIG_PAX_REFCOUNT
12458 + "jno 0f\n"
12459 + LOCK_PREFIX "addq %2,%0\n"
12460 + "int $4\n0:\n"
12461 + _ASM_EXTABLE(0b, 0b)
12462 +#endif
12463 +
12464 + "sete %1\n"
12465 : "=m" (v->counter), "=qm" (c)
12466 : "er" (i), "m" (v->counter) : "memory");
12467 return c;
12468 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12469 */
12470 static inline void atomic64_inc(atomic64_t *v)
12471 {
12472 + asm volatile(LOCK_PREFIX "incq %0\n"
12473 +
12474 +#ifdef CONFIG_PAX_REFCOUNT
12475 + "jno 0f\n"
12476 + LOCK_PREFIX "decq %0\n"
12477 + "int $4\n0:\n"
12478 + _ASM_EXTABLE(0b, 0b)
12479 +#endif
12480 +
12481 + : "=m" (v->counter)
12482 + : "m" (v->counter));
12483 +}
12484 +
12485 +/**
12486 + * atomic64_inc_unchecked - increment atomic64 variable
12487 + * @v: pointer to type atomic64_unchecked_t
12488 + *
12489 + * Atomically increments @v by 1.
12490 + */
12491 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12492 +{
12493 asm volatile(LOCK_PREFIX "incq %0"
12494 : "=m" (v->counter)
12495 : "m" (v->counter));
12496 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12497 */
12498 static inline void atomic64_dec(atomic64_t *v)
12499 {
12500 - asm volatile(LOCK_PREFIX "decq %0"
12501 + asm volatile(LOCK_PREFIX "decq %0\n"
12502 +
12503 +#ifdef CONFIG_PAX_REFCOUNT
12504 + "jno 0f\n"
12505 + LOCK_PREFIX "incq %0\n"
12506 + "int $4\n0:\n"
12507 + _ASM_EXTABLE(0b, 0b)
12508 +#endif
12509 +
12510 + : "=m" (v->counter)
12511 + : "m" (v->counter));
12512 +}
12513 +
12514 +/**
12515 + * atomic64_dec_unchecked - decrement atomic64 variable
12516 + * @v: pointer to type atomic64_t
12517 + *
12518 + * Atomically decrements @v by 1.
12519 + */
12520 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12521 +{
12522 + asm volatile(LOCK_PREFIX "decq %0\n"
12523 : "=m" (v->counter)
12524 : "m" (v->counter));
12525 }
12526 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12527 {
12528 unsigned char c;
12529
12530 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
12531 + asm volatile(LOCK_PREFIX "decq %0\n"
12532 +
12533 +#ifdef CONFIG_PAX_REFCOUNT
12534 + "jno 0f\n"
12535 + LOCK_PREFIX "incq %0\n"
12536 + "int $4\n0:\n"
12537 + _ASM_EXTABLE(0b, 0b)
12538 +#endif
12539 +
12540 + "sete %1\n"
12541 : "=m" (v->counter), "=qm" (c)
12542 : "m" (v->counter) : "memory");
12543 return c != 0;
12544 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12545 {
12546 unsigned char c;
12547
12548 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
12549 + asm volatile(LOCK_PREFIX "incq %0\n"
12550 +
12551 +#ifdef CONFIG_PAX_REFCOUNT
12552 + "jno 0f\n"
12553 + LOCK_PREFIX "decq %0\n"
12554 + "int $4\n0:\n"
12555 + _ASM_EXTABLE(0b, 0b)
12556 +#endif
12557 +
12558 + "sete %1\n"
12559 : "=m" (v->counter), "=qm" (c)
12560 : "m" (v->counter) : "memory");
12561 return c != 0;
12562 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12563 {
12564 unsigned char c;
12565
12566 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12567 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
12568 +
12569 +#ifdef CONFIG_PAX_REFCOUNT
12570 + "jno 0f\n"
12571 + LOCK_PREFIX "subq %2,%0\n"
12572 + "int $4\n0:\n"
12573 + _ASM_EXTABLE(0b, 0b)
12574 +#endif
12575 +
12576 + "sets %1\n"
12577 : "=m" (v->counter), "=qm" (c)
12578 : "er" (i), "m" (v->counter) : "memory");
12579 return c;
12580 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12581 */
12582 static inline long atomic64_add_return(long i, atomic64_t *v)
12583 {
12584 + return i + xadd_check_overflow(&v->counter, i);
12585 +}
12586 +
12587 +/**
12588 + * atomic64_add_return_unchecked - add and return
12589 + * @i: integer value to add
12590 + * @v: pointer to type atomic64_unchecked_t
12591 + *
12592 + * Atomically adds @i to @v and returns @i + @v
12593 + */
12594 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12595 +{
12596 return i + xadd(&v->counter, i);
12597 }
12598
12599 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12600 }
12601
12602 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12603 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12604 +{
12605 + return atomic64_add_return_unchecked(1, v);
12606 +}
12607 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12608
12609 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12610 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12611 return cmpxchg(&v->counter, old, new);
12612 }
12613
12614 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12615 +{
12616 + return cmpxchg(&v->counter, old, new);
12617 +}
12618 +
12619 static inline long atomic64_xchg(atomic64_t *v, long new)
12620 {
12621 return xchg(&v->counter, new);
12622 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12623 */
12624 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12625 {
12626 - long c, old;
12627 + long c, old, new;
12628 c = atomic64_read(v);
12629 for (;;) {
12630 - if (unlikely(c == (u)))
12631 + if (unlikely(c == u))
12632 break;
12633 - old = atomic64_cmpxchg((v), c, c + (a));
12634 +
12635 + asm volatile("add %2,%0\n"
12636 +
12637 +#ifdef CONFIG_PAX_REFCOUNT
12638 + "jno 0f\n"
12639 + "sub %2,%0\n"
12640 + "int $4\n0:\n"
12641 + _ASM_EXTABLE(0b, 0b)
12642 +#endif
12643 +
12644 + : "=r" (new)
12645 + : "0" (c), "ir" (a));
12646 +
12647 + old = atomic64_cmpxchg(v, c, new);
12648 if (likely(old == c))
12649 break;
12650 c = old;
12651 }
12652 - return c != (u);
12653 + return c != u;
12654 }
12655
12656 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12657 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12658 index 6dfd019..0c6699f 100644
12659 --- a/arch/x86/include/asm/bitops.h
12660 +++ b/arch/x86/include/asm/bitops.h
12661 @@ -40,7 +40,7 @@
12662 * a mask operation on a byte.
12663 */
12664 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12665 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12666 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12667 #define CONST_MASK(nr) (1 << ((nr) & 7))
12668
12669 /**
12670 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12671 index 4fa687a..60f2d39 100644
12672 --- a/arch/x86/include/asm/boot.h
12673 +++ b/arch/x86/include/asm/boot.h
12674 @@ -6,10 +6,15 @@
12675 #include <uapi/asm/boot.h>
12676
12677 /* Physical address where kernel should be loaded. */
12678 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12679 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12680 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12681 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12682
12683 +#ifndef __ASSEMBLY__
12684 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
12685 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12686 +#endif
12687 +
12688 /* Minimum kernel alignment, as a power of two */
12689 #ifdef CONFIG_X86_64
12690 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12691 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12692 index 48f99f1..d78ebf9 100644
12693 --- a/arch/x86/include/asm/cache.h
12694 +++ b/arch/x86/include/asm/cache.h
12695 @@ -5,12 +5,13 @@
12696
12697 /* L1 cache line size */
12698 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12699 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12700 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12701
12702 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12703 +#define __read_only __attribute__((__section__(".data..read_only")))
12704
12705 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12706 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12707 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12708
12709 #ifdef CONFIG_X86_VSMP
12710 #ifdef CONFIG_SMP
12711 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12712 index 9863ee3..4a1f8e1 100644
12713 --- a/arch/x86/include/asm/cacheflush.h
12714 +++ b/arch/x86/include/asm/cacheflush.h
12715 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12716 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12717
12718 if (pg_flags == _PGMT_DEFAULT)
12719 - return -1;
12720 + return ~0UL;
12721 else if (pg_flags == _PGMT_WC)
12722 return _PAGE_CACHE_WC;
12723 else if (pg_flags == _PGMT_UC_MINUS)
12724 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12725 index 46fc474..b02b0f9 100644
12726 --- a/arch/x86/include/asm/checksum_32.h
12727 +++ b/arch/x86/include/asm/checksum_32.h
12728 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12729 int len, __wsum sum,
12730 int *src_err_ptr, int *dst_err_ptr);
12731
12732 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12733 + int len, __wsum sum,
12734 + int *src_err_ptr, int *dst_err_ptr);
12735 +
12736 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12737 + int len, __wsum sum,
12738 + int *src_err_ptr, int *dst_err_ptr);
12739 +
12740 /*
12741 * Note: when you get a NULL pointer exception here this means someone
12742 * passed in an incorrect kernel address to one of these functions.
12743 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12744 int *err_ptr)
12745 {
12746 might_sleep();
12747 - return csum_partial_copy_generic((__force void *)src, dst,
12748 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
12749 len, sum, err_ptr, NULL);
12750 }
12751
12752 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12753 {
12754 might_sleep();
12755 if (access_ok(VERIFY_WRITE, dst, len))
12756 - return csum_partial_copy_generic(src, (__force void *)dst,
12757 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
12758 len, sum, NULL, err_ptr);
12759
12760 if (len)
12761 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
12762 index 8d871ea..c1a0dc9 100644
12763 --- a/arch/x86/include/asm/cmpxchg.h
12764 +++ b/arch/x86/include/asm/cmpxchg.h
12765 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
12766 __compiletime_error("Bad argument size for cmpxchg");
12767 extern void __xadd_wrong_size(void)
12768 __compiletime_error("Bad argument size for xadd");
12769 +extern void __xadd_check_overflow_wrong_size(void)
12770 + __compiletime_error("Bad argument size for xadd_check_overflow");
12771 extern void __add_wrong_size(void)
12772 __compiletime_error("Bad argument size for add");
12773 +extern void __add_check_overflow_wrong_size(void)
12774 + __compiletime_error("Bad argument size for add_check_overflow");
12775
12776 /*
12777 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
12778 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
12779 __ret; \
12780 })
12781
12782 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
12783 + ({ \
12784 + __typeof__ (*(ptr)) __ret = (arg); \
12785 + switch (sizeof(*(ptr))) { \
12786 + case __X86_CASE_L: \
12787 + asm volatile (lock #op "l %0, %1\n" \
12788 + "jno 0f\n" \
12789 + "mov %0,%1\n" \
12790 + "int $4\n0:\n" \
12791 + _ASM_EXTABLE(0b, 0b) \
12792 + : "+r" (__ret), "+m" (*(ptr)) \
12793 + : : "memory", "cc"); \
12794 + break; \
12795 + case __X86_CASE_Q: \
12796 + asm volatile (lock #op "q %q0, %1\n" \
12797 + "jno 0f\n" \
12798 + "mov %0,%1\n" \
12799 + "int $4\n0:\n" \
12800 + _ASM_EXTABLE(0b, 0b) \
12801 + : "+r" (__ret), "+m" (*(ptr)) \
12802 + : : "memory", "cc"); \
12803 + break; \
12804 + default: \
12805 + __ ## op ## _check_overflow_wrong_size(); \
12806 + } \
12807 + __ret; \
12808 + })
12809 +
12810 /*
12811 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
12812 * Since this is generally used to protect other memory information, we
12813 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
12814 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
12815 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
12816
12817 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
12818 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
12819 +
12820 #define __add(ptr, inc, lock) \
12821 ({ \
12822 __typeof__ (*(ptr)) __ret = (inc); \
12823 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
12824 index 2d9075e..b75a844 100644
12825 --- a/arch/x86/include/asm/cpufeature.h
12826 +++ b/arch/x86/include/asm/cpufeature.h
12827 @@ -206,7 +206,7 @@
12828 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
12829 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
12830 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
12831 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
12832 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
12833 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
12834 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
12835 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
12836 @@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
12837 ".section .discard,\"aw\",@progbits\n"
12838 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
12839 ".previous\n"
12840 - ".section .altinstr_replacement,\"ax\"\n"
12841 + ".section .altinstr_replacement,\"a\"\n"
12842 "3: movb $1,%0\n"
12843 "4:\n"
12844 ".previous\n"
12845 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
12846 index 8bf1c06..f723dfd 100644
12847 --- a/arch/x86/include/asm/desc.h
12848 +++ b/arch/x86/include/asm/desc.h
12849 @@ -4,6 +4,7 @@
12850 #include <asm/desc_defs.h>
12851 #include <asm/ldt.h>
12852 #include <asm/mmu.h>
12853 +#include <asm/pgtable.h>
12854
12855 #include <linux/smp.h>
12856 #include <linux/percpu.h>
12857 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12858
12859 desc->type = (info->read_exec_only ^ 1) << 1;
12860 desc->type |= info->contents << 2;
12861 + desc->type |= info->seg_not_present ^ 1;
12862
12863 desc->s = 1;
12864 desc->dpl = 0x3;
12865 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12866 }
12867
12868 extern struct desc_ptr idt_descr;
12869 -extern gate_desc idt_table[];
12870 extern struct desc_ptr nmi_idt_descr;
12871 -extern gate_desc nmi_idt_table[];
12872 -
12873 -struct gdt_page {
12874 - struct desc_struct gdt[GDT_ENTRIES];
12875 -} __attribute__((aligned(PAGE_SIZE)));
12876 -
12877 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
12878 +extern gate_desc idt_table[256];
12879 +extern gate_desc nmi_idt_table[256];
12880
12881 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
12882 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
12883 {
12884 - return per_cpu(gdt_page, cpu).gdt;
12885 + return cpu_gdt_table[cpu];
12886 }
12887
12888 #ifdef CONFIG_X86_64
12889 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
12890 unsigned long base, unsigned dpl, unsigned flags,
12891 unsigned short seg)
12892 {
12893 - gate->a = (seg << 16) | (base & 0xffff);
12894 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
12895 + gate->gate.offset_low = base;
12896 + gate->gate.seg = seg;
12897 + gate->gate.reserved = 0;
12898 + gate->gate.type = type;
12899 + gate->gate.s = 0;
12900 + gate->gate.dpl = dpl;
12901 + gate->gate.p = 1;
12902 + gate->gate.offset_high = base >> 16;
12903 }
12904
12905 #endif
12906 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
12907
12908 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
12909 {
12910 + pax_open_kernel();
12911 memcpy(&idt[entry], gate, sizeof(*gate));
12912 + pax_close_kernel();
12913 }
12914
12915 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
12916 {
12917 + pax_open_kernel();
12918 memcpy(&ldt[entry], desc, 8);
12919 + pax_close_kernel();
12920 }
12921
12922 static inline void
12923 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
12924 default: size = sizeof(*gdt); break;
12925 }
12926
12927 + pax_open_kernel();
12928 memcpy(&gdt[entry], desc, size);
12929 + pax_close_kernel();
12930 }
12931
12932 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
12933 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
12934
12935 static inline void native_load_tr_desc(void)
12936 {
12937 + pax_open_kernel();
12938 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
12939 + pax_close_kernel();
12940 }
12941
12942 static inline void native_load_gdt(const struct desc_ptr *dtr)
12943 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
12944 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
12945 unsigned int i;
12946
12947 + pax_open_kernel();
12948 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
12949 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
12950 + pax_close_kernel();
12951 }
12952
12953 #define _LDT_empty(info) \
12954 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
12955 }
12956
12957 #ifdef CONFIG_X86_64
12958 -static inline void set_nmi_gate(int gate, void *addr)
12959 +static inline void set_nmi_gate(int gate, const void *addr)
12960 {
12961 gate_desc s;
12962
12963 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
12964 }
12965 #endif
12966
12967 -static inline void _set_gate(int gate, unsigned type, void *addr,
12968 +static inline void _set_gate(int gate, unsigned type, const void *addr,
12969 unsigned dpl, unsigned ist, unsigned seg)
12970 {
12971 gate_desc s;
12972 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
12973 * Pentium F0 0F bugfix can have resulted in the mapped
12974 * IDT being write-protected.
12975 */
12976 -static inline void set_intr_gate(unsigned int n, void *addr)
12977 +static inline void set_intr_gate(unsigned int n, const void *addr)
12978 {
12979 BUG_ON((unsigned)n > 0xFF);
12980 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
12981 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
12982 /*
12983 * This routine sets up an interrupt gate at directory privilege level 3.
12984 */
12985 -static inline void set_system_intr_gate(unsigned int n, void *addr)
12986 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
12987 {
12988 BUG_ON((unsigned)n > 0xFF);
12989 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
12990 }
12991
12992 -static inline void set_system_trap_gate(unsigned int n, void *addr)
12993 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
12994 {
12995 BUG_ON((unsigned)n > 0xFF);
12996 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
12997 }
12998
12999 -static inline void set_trap_gate(unsigned int n, void *addr)
13000 +static inline void set_trap_gate(unsigned int n, const void *addr)
13001 {
13002 BUG_ON((unsigned)n > 0xFF);
13003 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
13004 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
13005 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
13006 {
13007 BUG_ON((unsigned)n > 0xFF);
13008 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
13009 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
13010 }
13011
13012 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
13013 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
13014 {
13015 BUG_ON((unsigned)n > 0xFF);
13016 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
13017 }
13018
13019 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
13020 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
13021 {
13022 BUG_ON((unsigned)n > 0xFF);
13023 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
13024 }
13025
13026 +#ifdef CONFIG_X86_32
13027 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
13028 +{
13029 + struct desc_struct d;
13030 +
13031 + if (likely(limit))
13032 + limit = (limit - 1UL) >> PAGE_SHIFT;
13033 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
13034 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
13035 +}
13036 +#endif
13037 +
13038 #endif /* _ASM_X86_DESC_H */
13039 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
13040 index 278441f..b95a174 100644
13041 --- a/arch/x86/include/asm/desc_defs.h
13042 +++ b/arch/x86/include/asm/desc_defs.h
13043 @@ -31,6 +31,12 @@ struct desc_struct {
13044 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
13045 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
13046 };
13047 + struct {
13048 + u16 offset_low;
13049 + u16 seg;
13050 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
13051 + unsigned offset_high: 16;
13052 + } gate;
13053 };
13054 } __attribute__((packed));
13055
13056 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
13057 index 9c999c1..3860cb8 100644
13058 --- a/arch/x86/include/asm/elf.h
13059 +++ b/arch/x86/include/asm/elf.h
13060 @@ -243,7 +243,25 @@ extern int force_personality32;
13061 the loader. We need to make sure that it is out of the way of the program
13062 that it will "exec", and that there is sufficient room for the brk. */
13063
13064 +#ifdef CONFIG_PAX_SEGMEXEC
13065 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
13066 +#else
13067 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
13068 +#endif
13069 +
13070 +#ifdef CONFIG_PAX_ASLR
13071 +#ifdef CONFIG_X86_32
13072 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
13073 +
13074 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13075 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13076 +#else
13077 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
13078 +
13079 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13080 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13081 +#endif
13082 +#endif
13083
13084 /* This yields a mask that user programs can use to figure out what
13085 instruction set this CPU supports. This could be done in user space,
13086 @@ -296,16 +314,12 @@ do { \
13087
13088 #define ARCH_DLINFO \
13089 do { \
13090 - if (vdso_enabled) \
13091 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13092 - (unsigned long)current->mm->context.vdso); \
13093 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13094 } while (0)
13095
13096 #define ARCH_DLINFO_X32 \
13097 do { \
13098 - if (vdso_enabled) \
13099 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13100 - (unsigned long)current->mm->context.vdso); \
13101 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13102 } while (0)
13103
13104 #define AT_SYSINFO 32
13105 @@ -320,7 +334,7 @@ else \
13106
13107 #endif /* !CONFIG_X86_32 */
13108
13109 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13110 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13111
13112 #define VDSO_ENTRY \
13113 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13114 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13115 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13116 #define compat_arch_setup_additional_pages syscall32_setup_pages
13117
13118 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13119 -#define arch_randomize_brk arch_randomize_brk
13120 -
13121 /*
13122 * True on X86_32 or when emulating IA32 on X86_64
13123 */
13124 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13125 index 75ce3f4..882e801 100644
13126 --- a/arch/x86/include/asm/emergency-restart.h
13127 +++ b/arch/x86/include/asm/emergency-restart.h
13128 @@ -13,6 +13,6 @@ enum reboot_type {
13129
13130 extern enum reboot_type reboot_type;
13131
13132 -extern void machine_emergency_restart(void);
13133 +extern void machine_emergency_restart(void) __noreturn;
13134
13135 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13136 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13137 index 41ab26e..a88c9e6 100644
13138 --- a/arch/x86/include/asm/fpu-internal.h
13139 +++ b/arch/x86/include/asm/fpu-internal.h
13140 @@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13141 ({ \
13142 int err; \
13143 asm volatile(ASM_STAC "\n" \
13144 - "1:" #insn "\n\t" \
13145 + "1:" \
13146 + __copyuser_seg \
13147 + #insn "\n\t" \
13148 "2: " ASM_CLAC "\n" \
13149 ".section .fixup,\"ax\"\n" \
13150 "3: movl $-1,%[err]\n" \
13151 @@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13152 "emms\n\t" /* clear stack tags */
13153 "fildl %P[addr]", /* set F?P to defined value */
13154 X86_FEATURE_FXSAVE_LEAK,
13155 - [addr] "m" (tsk->thread.fpu.has_fpu));
13156 + [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13157
13158 return fpu_restore_checking(&tsk->thread.fpu);
13159 }
13160 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13161 index be27ba1..8f13ff9 100644
13162 --- a/arch/x86/include/asm/futex.h
13163 +++ b/arch/x86/include/asm/futex.h
13164 @@ -12,6 +12,7 @@
13165 #include <asm/smap.h>
13166
13167 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13168 + typecheck(u32 __user *, uaddr); \
13169 asm volatile("\t" ASM_STAC "\n" \
13170 "1:\t" insn "\n" \
13171 "2:\t" ASM_CLAC "\n" \
13172 @@ -20,15 +21,16 @@
13173 "\tjmp\t2b\n" \
13174 "\t.previous\n" \
13175 _ASM_EXTABLE(1b, 3b) \
13176 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13177 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13178 : "i" (-EFAULT), "0" (oparg), "1" (0))
13179
13180 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13181 + typecheck(u32 __user *, uaddr); \
13182 asm volatile("\t" ASM_STAC "\n" \
13183 "1:\tmovl %2, %0\n" \
13184 "\tmovl\t%0, %3\n" \
13185 "\t" insn "\n" \
13186 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13187 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13188 "\tjnz\t1b\n" \
13189 "3:\t" ASM_CLAC "\n" \
13190 "\t.section .fixup,\"ax\"\n" \
13191 @@ -38,7 +40,7 @@
13192 _ASM_EXTABLE(1b, 4b) \
13193 _ASM_EXTABLE(2b, 4b) \
13194 : "=&a" (oldval), "=&r" (ret), \
13195 - "+m" (*uaddr), "=&r" (tem) \
13196 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13197 : "r" (oparg), "i" (-EFAULT), "1" (0))
13198
13199 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13200 @@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13201
13202 switch (op) {
13203 case FUTEX_OP_SET:
13204 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13205 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13206 break;
13207 case FUTEX_OP_ADD:
13208 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13209 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13210 uaddr, oparg);
13211 break;
13212 case FUTEX_OP_OR:
13213 @@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13214 return -EFAULT;
13215
13216 asm volatile("\t" ASM_STAC "\n"
13217 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13218 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13219 "2:\t" ASM_CLAC "\n"
13220 "\t.section .fixup, \"ax\"\n"
13221 "3:\tmov %3, %0\n"
13222 "\tjmp 2b\n"
13223 "\t.previous\n"
13224 _ASM_EXTABLE(1b, 3b)
13225 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13226 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13227 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13228 : "memory"
13229 );
13230 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13231 index eb92a6e..b98b2f4 100644
13232 --- a/arch/x86/include/asm/hw_irq.h
13233 +++ b/arch/x86/include/asm/hw_irq.h
13234 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13235 extern void enable_IO_APIC(void);
13236
13237 /* Statistics */
13238 -extern atomic_t irq_err_count;
13239 -extern atomic_t irq_mis_count;
13240 +extern atomic_unchecked_t irq_err_count;
13241 +extern atomic_unchecked_t irq_mis_count;
13242
13243 /* EISA */
13244 extern void eisa_set_level_irq(unsigned int irq);
13245 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13246 index a203659..9889f1c 100644
13247 --- a/arch/x86/include/asm/i8259.h
13248 +++ b/arch/x86/include/asm/i8259.h
13249 @@ -62,7 +62,7 @@ struct legacy_pic {
13250 void (*init)(int auto_eoi);
13251 int (*irq_pending)(unsigned int irq);
13252 void (*make_irq)(unsigned int irq);
13253 -};
13254 +} __do_const;
13255
13256 extern struct legacy_pic *legacy_pic;
13257 extern struct legacy_pic null_legacy_pic;
13258 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13259 index d8e8eef..15b1179 100644
13260 --- a/arch/x86/include/asm/io.h
13261 +++ b/arch/x86/include/asm/io.h
13262 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13263 return ioremap_nocache(offset, size);
13264 }
13265
13266 -extern void iounmap(volatile void __iomem *addr);
13267 +extern void iounmap(const volatile void __iomem *addr);
13268
13269 extern void set_iounmap_nonlazy(void);
13270
13271 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13272
13273 #include <linux/vmalloc.h>
13274
13275 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13276 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13277 +{
13278 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13279 +}
13280 +
13281 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13282 +{
13283 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13284 +}
13285 +
13286 /*
13287 * Convert a virtual cached pointer to an uncached pointer
13288 */
13289 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13290 index bba3cf8..06bc8da 100644
13291 --- a/arch/x86/include/asm/irqflags.h
13292 +++ b/arch/x86/include/asm/irqflags.h
13293 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13294 sti; \
13295 sysexit
13296
13297 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
13298 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13299 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
13300 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13301 +
13302 #else
13303 #define INTERRUPT_RETURN iret
13304 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13305 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13306 index d3ddd17..c9fb0cc 100644
13307 --- a/arch/x86/include/asm/kprobes.h
13308 +++ b/arch/x86/include/asm/kprobes.h
13309 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13310 #define RELATIVEJUMP_SIZE 5
13311 #define RELATIVECALL_OPCODE 0xe8
13312 #define RELATIVE_ADDR_SIZE 4
13313 -#define MAX_STACK_SIZE 64
13314 -#define MIN_STACK_SIZE(ADDR) \
13315 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13316 - THREAD_SIZE - (unsigned long)(ADDR))) \
13317 - ? (MAX_STACK_SIZE) \
13318 - : (((unsigned long)current_thread_info()) + \
13319 - THREAD_SIZE - (unsigned long)(ADDR)))
13320 +#define MAX_STACK_SIZE 64UL
13321 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13322
13323 #define flush_insn_slot(p) do { } while (0)
13324
13325 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13326 index 2d89e39..baee879 100644
13327 --- a/arch/x86/include/asm/local.h
13328 +++ b/arch/x86/include/asm/local.h
13329 @@ -10,33 +10,97 @@ typedef struct {
13330 atomic_long_t a;
13331 } local_t;
13332
13333 +typedef struct {
13334 + atomic_long_unchecked_t a;
13335 +} local_unchecked_t;
13336 +
13337 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13338
13339 #define local_read(l) atomic_long_read(&(l)->a)
13340 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13341 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13342 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13343
13344 static inline void local_inc(local_t *l)
13345 {
13346 - asm volatile(_ASM_INC "%0"
13347 + asm volatile(_ASM_INC "%0\n"
13348 +
13349 +#ifdef CONFIG_PAX_REFCOUNT
13350 + "jno 0f\n"
13351 + _ASM_DEC "%0\n"
13352 + "int $4\n0:\n"
13353 + _ASM_EXTABLE(0b, 0b)
13354 +#endif
13355 +
13356 + : "+m" (l->a.counter));
13357 +}
13358 +
13359 +static inline void local_inc_unchecked(local_unchecked_t *l)
13360 +{
13361 + asm volatile(_ASM_INC "%0\n"
13362 : "+m" (l->a.counter));
13363 }
13364
13365 static inline void local_dec(local_t *l)
13366 {
13367 - asm volatile(_ASM_DEC "%0"
13368 + asm volatile(_ASM_DEC "%0\n"
13369 +
13370 +#ifdef CONFIG_PAX_REFCOUNT
13371 + "jno 0f\n"
13372 + _ASM_INC "%0\n"
13373 + "int $4\n0:\n"
13374 + _ASM_EXTABLE(0b, 0b)
13375 +#endif
13376 +
13377 + : "+m" (l->a.counter));
13378 +}
13379 +
13380 +static inline void local_dec_unchecked(local_unchecked_t *l)
13381 +{
13382 + asm volatile(_ASM_DEC "%0\n"
13383 : "+m" (l->a.counter));
13384 }
13385
13386 static inline void local_add(long i, local_t *l)
13387 {
13388 - asm volatile(_ASM_ADD "%1,%0"
13389 + asm volatile(_ASM_ADD "%1,%0\n"
13390 +
13391 +#ifdef CONFIG_PAX_REFCOUNT
13392 + "jno 0f\n"
13393 + _ASM_SUB "%1,%0\n"
13394 + "int $4\n0:\n"
13395 + _ASM_EXTABLE(0b, 0b)
13396 +#endif
13397 +
13398 + : "+m" (l->a.counter)
13399 + : "ir" (i));
13400 +}
13401 +
13402 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
13403 +{
13404 + asm volatile(_ASM_ADD "%1,%0\n"
13405 : "+m" (l->a.counter)
13406 : "ir" (i));
13407 }
13408
13409 static inline void local_sub(long i, local_t *l)
13410 {
13411 - asm volatile(_ASM_SUB "%1,%0"
13412 + asm volatile(_ASM_SUB "%1,%0\n"
13413 +
13414 +#ifdef CONFIG_PAX_REFCOUNT
13415 + "jno 0f\n"
13416 + _ASM_ADD "%1,%0\n"
13417 + "int $4\n0:\n"
13418 + _ASM_EXTABLE(0b, 0b)
13419 +#endif
13420 +
13421 + : "+m" (l->a.counter)
13422 + : "ir" (i));
13423 +}
13424 +
13425 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13426 +{
13427 + asm volatile(_ASM_SUB "%1,%0\n"
13428 : "+m" (l->a.counter)
13429 : "ir" (i));
13430 }
13431 @@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13432 {
13433 unsigned char c;
13434
13435 - asm volatile(_ASM_SUB "%2,%0; sete %1"
13436 + asm volatile(_ASM_SUB "%2,%0\n"
13437 +
13438 +#ifdef CONFIG_PAX_REFCOUNT
13439 + "jno 0f\n"
13440 + _ASM_ADD "%2,%0\n"
13441 + "int $4\n0:\n"
13442 + _ASM_EXTABLE(0b, 0b)
13443 +#endif
13444 +
13445 + "sete %1\n"
13446 : "+m" (l->a.counter), "=qm" (c)
13447 : "ir" (i) : "memory");
13448 return c;
13449 @@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13450 {
13451 unsigned char c;
13452
13453 - asm volatile(_ASM_DEC "%0; sete %1"
13454 + asm volatile(_ASM_DEC "%0\n"
13455 +
13456 +#ifdef CONFIG_PAX_REFCOUNT
13457 + "jno 0f\n"
13458 + _ASM_INC "%0\n"
13459 + "int $4\n0:\n"
13460 + _ASM_EXTABLE(0b, 0b)
13461 +#endif
13462 +
13463 + "sete %1\n"
13464 : "+m" (l->a.counter), "=qm" (c)
13465 : : "memory");
13466 return c != 0;
13467 @@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13468 {
13469 unsigned char c;
13470
13471 - asm volatile(_ASM_INC "%0; sete %1"
13472 + asm volatile(_ASM_INC "%0\n"
13473 +
13474 +#ifdef CONFIG_PAX_REFCOUNT
13475 + "jno 0f\n"
13476 + _ASM_DEC "%0\n"
13477 + "int $4\n0:\n"
13478 + _ASM_EXTABLE(0b, 0b)
13479 +#endif
13480 +
13481 + "sete %1\n"
13482 : "+m" (l->a.counter), "=qm" (c)
13483 : : "memory");
13484 return c != 0;
13485 @@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13486 {
13487 unsigned char c;
13488
13489 - asm volatile(_ASM_ADD "%2,%0; sets %1"
13490 + asm volatile(_ASM_ADD "%2,%0\n"
13491 +
13492 +#ifdef CONFIG_PAX_REFCOUNT
13493 + "jno 0f\n"
13494 + _ASM_SUB "%2,%0\n"
13495 + "int $4\n0:\n"
13496 + _ASM_EXTABLE(0b, 0b)
13497 +#endif
13498 +
13499 + "sets %1\n"
13500 : "+m" (l->a.counter), "=qm" (c)
13501 : "ir" (i) : "memory");
13502 return c;
13503 @@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13504 static inline long local_add_return(long i, local_t *l)
13505 {
13506 long __i = i;
13507 + asm volatile(_ASM_XADD "%0, %1\n"
13508 +
13509 +#ifdef CONFIG_PAX_REFCOUNT
13510 + "jno 0f\n"
13511 + _ASM_MOV "%0,%1\n"
13512 + "int $4\n0:\n"
13513 + _ASM_EXTABLE(0b, 0b)
13514 +#endif
13515 +
13516 + : "+r" (i), "+m" (l->a.counter)
13517 + : : "memory");
13518 + return i + __i;
13519 +}
13520 +
13521 +/**
13522 + * local_add_return_unchecked - add and return
13523 + * @i: integer value to add
13524 + * @l: pointer to type local_unchecked_t
13525 + *
13526 + * Atomically adds @i to @l and returns @i + @l
13527 + */
13528 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13529 +{
13530 + long __i = i;
13531 asm volatile(_ASM_XADD "%0, %1;"
13532 : "+r" (i), "+m" (l->a.counter)
13533 : : "memory");
13534 @@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13535
13536 #define local_cmpxchg(l, o, n) \
13537 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13538 +#define local_cmpxchg_unchecked(l, o, n) \
13539 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
13540 /* Always has a lock prefix */
13541 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13542
13543 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13544 new file mode 100644
13545 index 0000000..2bfd3ba
13546 --- /dev/null
13547 +++ b/arch/x86/include/asm/mman.h
13548 @@ -0,0 +1,15 @@
13549 +#ifndef _X86_MMAN_H
13550 +#define _X86_MMAN_H
13551 +
13552 +#include <uapi/asm/mman.h>
13553 +
13554 +#ifdef __KERNEL__
13555 +#ifndef __ASSEMBLY__
13556 +#ifdef CONFIG_X86_32
13557 +#define arch_mmap_check i386_mmap_check
13558 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13559 +#endif
13560 +#endif
13561 +#endif
13562 +
13563 +#endif /* X86_MMAN_H */
13564 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13565 index 5f55e69..e20bfb1 100644
13566 --- a/arch/x86/include/asm/mmu.h
13567 +++ b/arch/x86/include/asm/mmu.h
13568 @@ -9,7 +9,7 @@
13569 * we put the segment information here.
13570 */
13571 typedef struct {
13572 - void *ldt;
13573 + struct desc_struct *ldt;
13574 int size;
13575
13576 #ifdef CONFIG_X86_64
13577 @@ -18,7 +18,19 @@ typedef struct {
13578 #endif
13579
13580 struct mutex lock;
13581 - void *vdso;
13582 + unsigned long vdso;
13583 +
13584 +#ifdef CONFIG_X86_32
13585 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13586 + unsigned long user_cs_base;
13587 + unsigned long user_cs_limit;
13588 +
13589 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13590 + cpumask_t cpu_user_cs_mask;
13591 +#endif
13592 +
13593 +#endif
13594 +#endif
13595 } mm_context_t;
13596
13597 #ifdef CONFIG_SMP
13598 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13599 index cdbf367..adb37ac 100644
13600 --- a/arch/x86/include/asm/mmu_context.h
13601 +++ b/arch/x86/include/asm/mmu_context.h
13602 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13603
13604 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13605 {
13606 +
13607 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13608 + unsigned int i;
13609 + pgd_t *pgd;
13610 +
13611 + pax_open_kernel();
13612 + pgd = get_cpu_pgd(smp_processor_id());
13613 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13614 + set_pgd_batched(pgd+i, native_make_pgd(0));
13615 + pax_close_kernel();
13616 +#endif
13617 +
13618 #ifdef CONFIG_SMP
13619 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13620 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13621 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13622 struct task_struct *tsk)
13623 {
13624 unsigned cpu = smp_processor_id();
13625 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13626 + int tlbstate = TLBSTATE_OK;
13627 +#endif
13628
13629 if (likely(prev != next)) {
13630 #ifdef CONFIG_SMP
13631 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13632 + tlbstate = this_cpu_read(cpu_tlbstate.state);
13633 +#endif
13634 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13635 this_cpu_write(cpu_tlbstate.active_mm, next);
13636 #endif
13637 cpumask_set_cpu(cpu, mm_cpumask(next));
13638
13639 /* Re-load page tables */
13640 +#ifdef CONFIG_PAX_PER_CPU_PGD
13641 + pax_open_kernel();
13642 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13643 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13644 + pax_close_kernel();
13645 + load_cr3(get_cpu_pgd(cpu));
13646 +#else
13647 load_cr3(next->pgd);
13648 +#endif
13649
13650 /* stop flush ipis for the previous mm */
13651 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13652 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13653 */
13654 if (unlikely(prev->context.ldt != next->context.ldt))
13655 load_LDT_nolock(&next->context);
13656 - }
13657 +
13658 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13659 + if (!(__supported_pte_mask & _PAGE_NX)) {
13660 + smp_mb__before_clear_bit();
13661 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13662 + smp_mb__after_clear_bit();
13663 + cpu_set(cpu, next->context.cpu_user_cs_mask);
13664 + }
13665 +#endif
13666 +
13667 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13668 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13669 + prev->context.user_cs_limit != next->context.user_cs_limit))
13670 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13671 #ifdef CONFIG_SMP
13672 + else if (unlikely(tlbstate != TLBSTATE_OK))
13673 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13674 +#endif
13675 +#endif
13676 +
13677 + }
13678 else {
13679 +
13680 +#ifdef CONFIG_PAX_PER_CPU_PGD
13681 + pax_open_kernel();
13682 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13683 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13684 + pax_close_kernel();
13685 + load_cr3(get_cpu_pgd(cpu));
13686 +#endif
13687 +
13688 +#ifdef CONFIG_SMP
13689 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13690 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13691
13692 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13693 * tlb flush IPI delivery. We must reload CR3
13694 * to make sure to use no freed page tables.
13695 */
13696 +
13697 +#ifndef CONFIG_PAX_PER_CPU_PGD
13698 load_cr3(next->pgd);
13699 +#endif
13700 +
13701 load_LDT_nolock(&next->context);
13702 +
13703 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
13704 + if (!(__supported_pte_mask & _PAGE_NX))
13705 + cpu_set(cpu, next->context.cpu_user_cs_mask);
13706 +#endif
13707 +
13708 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13709 +#ifdef CONFIG_PAX_PAGEEXEC
13710 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
13711 +#endif
13712 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13713 +#endif
13714 +
13715 }
13716 +#endif
13717 }
13718 -#endif
13719 }
13720
13721 #define activate_mm(prev, next) \
13722 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
13723 index e3b7819..b257c64 100644
13724 --- a/arch/x86/include/asm/module.h
13725 +++ b/arch/x86/include/asm/module.h
13726 @@ -5,6 +5,7 @@
13727
13728 #ifdef CONFIG_X86_64
13729 /* X86_64 does not define MODULE_PROC_FAMILY */
13730 +#define MODULE_PROC_FAMILY ""
13731 #elif defined CONFIG_M486
13732 #define MODULE_PROC_FAMILY "486 "
13733 #elif defined CONFIG_M586
13734 @@ -57,8 +58,20 @@
13735 #error unknown processor family
13736 #endif
13737
13738 -#ifdef CONFIG_X86_32
13739 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
13740 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13741 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
13742 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
13743 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
13744 +#else
13745 +#define MODULE_PAX_KERNEXEC ""
13746 #endif
13747
13748 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13749 +#define MODULE_PAX_UDEREF "UDEREF "
13750 +#else
13751 +#define MODULE_PAX_UDEREF ""
13752 +#endif
13753 +
13754 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
13755 +
13756 #endif /* _ASM_X86_MODULE_H */
13757 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
13758 index c0fa356..07a498a 100644
13759 --- a/arch/x86/include/asm/nmi.h
13760 +++ b/arch/x86/include/asm/nmi.h
13761 @@ -42,11 +42,11 @@ struct nmiaction {
13762 nmi_handler_t handler;
13763 unsigned long flags;
13764 const char *name;
13765 -};
13766 +} __do_const;
13767
13768 #define register_nmi_handler(t, fn, fg, n, init...) \
13769 ({ \
13770 - static struct nmiaction init fn##_na = { \
13771 + static const struct nmiaction init fn##_na = { \
13772 .handler = (fn), \
13773 .name = (n), \
13774 .flags = (fg), \
13775 @@ -54,7 +54,7 @@ struct nmiaction {
13776 __register_nmi_handler((t), &fn##_na); \
13777 })
13778
13779 -int __register_nmi_handler(unsigned int, struct nmiaction *);
13780 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
13781
13782 void unregister_nmi_handler(unsigned int, const char *);
13783
13784 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
13785 index 320f7bb..e89f8f8 100644
13786 --- a/arch/x86/include/asm/page_64_types.h
13787 +++ b/arch/x86/include/asm/page_64_types.h
13788 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
13789
13790 /* duplicated to the one in bootmem.h */
13791 extern unsigned long max_pfn;
13792 -extern unsigned long phys_base;
13793 +extern const unsigned long phys_base;
13794
13795 extern unsigned long __phys_addr(unsigned long);
13796 #define __phys_reloc_hide(x) (x)
13797 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
13798 index 5edd174..9cf5821 100644
13799 --- a/arch/x86/include/asm/paravirt.h
13800 +++ b/arch/x86/include/asm/paravirt.h
13801 @@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
13802 val);
13803 }
13804
13805 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
13806 +{
13807 + pgdval_t val = native_pgd_val(pgd);
13808 +
13809 + if (sizeof(pgdval_t) > sizeof(long))
13810 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
13811 + val, (u64)val >> 32);
13812 + else
13813 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
13814 + val);
13815 +}
13816 +
13817 static inline void pgd_clear(pgd_t *pgdp)
13818 {
13819 set_pgd(pgdp, __pgd(0));
13820 @@ -711,6 +723,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
13821 pv_mmu_ops.set_fixmap(idx, phys, flags);
13822 }
13823
13824 +#ifdef CONFIG_PAX_KERNEXEC
13825 +static inline unsigned long pax_open_kernel(void)
13826 +{
13827 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
13828 +}
13829 +
13830 +static inline unsigned long pax_close_kernel(void)
13831 +{
13832 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
13833 +}
13834 +#else
13835 +static inline unsigned long pax_open_kernel(void) { return 0; }
13836 +static inline unsigned long pax_close_kernel(void) { return 0; }
13837 +#endif
13838 +
13839 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
13840
13841 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
13842 @@ -927,7 +954,7 @@ extern void default_banner(void);
13843
13844 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
13845 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
13846 -#define PARA_INDIRECT(addr) *%cs:addr
13847 +#define PARA_INDIRECT(addr) *%ss:addr
13848 #endif
13849
13850 #define INTERRUPT_RETURN \
13851 @@ -1002,6 +1029,21 @@ extern void default_banner(void);
13852 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
13853 CLBR_NONE, \
13854 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
13855 +
13856 +#define GET_CR0_INTO_RDI \
13857 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
13858 + mov %rax,%rdi
13859 +
13860 +#define SET_RDI_INTO_CR0 \
13861 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13862 +
13863 +#define GET_CR3_INTO_RDI \
13864 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
13865 + mov %rax,%rdi
13866 +
13867 +#define SET_RDI_INTO_CR3 \
13868 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
13869 +
13870 #endif /* CONFIG_X86_32 */
13871
13872 #endif /* __ASSEMBLY__ */
13873 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
13874 index 142236e..5446ffbc 100644
13875 --- a/arch/x86/include/asm/paravirt_types.h
13876 +++ b/arch/x86/include/asm/paravirt_types.h
13877 @@ -84,7 +84,7 @@ struct pv_init_ops {
13878 */
13879 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
13880 unsigned long addr, unsigned len);
13881 -};
13882 +} __no_const;
13883
13884
13885 struct pv_lazy_ops {
13886 @@ -97,7 +97,7 @@ struct pv_time_ops {
13887 unsigned long long (*sched_clock)(void);
13888 unsigned long long (*steal_clock)(int cpu);
13889 unsigned long (*get_tsc_khz)(void);
13890 -};
13891 +} __no_const;
13892
13893 struct pv_cpu_ops {
13894 /* hooks for various privileged instructions */
13895 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
13896
13897 void (*start_context_switch)(struct task_struct *prev);
13898 void (*end_context_switch)(struct task_struct *next);
13899 -};
13900 +} __no_const;
13901
13902 struct pv_irq_ops {
13903 /*
13904 @@ -222,7 +222,7 @@ struct pv_apic_ops {
13905 unsigned long start_eip,
13906 unsigned long start_esp);
13907 #endif
13908 -};
13909 +} __no_const;
13910
13911 struct pv_mmu_ops {
13912 unsigned long (*read_cr2)(void);
13913 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
13914 struct paravirt_callee_save make_pud;
13915
13916 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
13917 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
13918 #endif /* PAGETABLE_LEVELS == 4 */
13919 #endif /* PAGETABLE_LEVELS >= 3 */
13920
13921 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
13922 an mfn. We can tell which is which from the index. */
13923 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
13924 phys_addr_t phys, pgprot_t flags);
13925 +
13926 +#ifdef CONFIG_PAX_KERNEXEC
13927 + unsigned long (*pax_open_kernel)(void);
13928 + unsigned long (*pax_close_kernel)(void);
13929 +#endif
13930 +
13931 };
13932
13933 struct arch_spinlock;
13934 @@ -333,7 +340,7 @@ struct pv_lock_ops {
13935 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
13936 int (*spin_trylock)(struct arch_spinlock *lock);
13937 void (*spin_unlock)(struct arch_spinlock *lock);
13938 -};
13939 +} __no_const;
13940
13941 /* This contains all the paravirt structures: we get a convenient
13942 * number for each function using the offset which we use to indicate
13943 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
13944 index b4389a4..7024269 100644
13945 --- a/arch/x86/include/asm/pgalloc.h
13946 +++ b/arch/x86/include/asm/pgalloc.h
13947 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
13948 pmd_t *pmd, pte_t *pte)
13949 {
13950 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13951 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
13952 +}
13953 +
13954 +static inline void pmd_populate_user(struct mm_struct *mm,
13955 + pmd_t *pmd, pte_t *pte)
13956 +{
13957 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13958 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
13959 }
13960
13961 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
13962
13963 #ifdef CONFIG_X86_PAE
13964 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
13965 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
13966 +{
13967 + pud_populate(mm, pudp, pmd);
13968 +}
13969 #else /* !CONFIG_X86_PAE */
13970 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13971 {
13972 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13973 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
13974 }
13975 +
13976 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13977 +{
13978 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13979 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
13980 +}
13981 #endif /* CONFIG_X86_PAE */
13982
13983 #if PAGETABLE_LEVELS > 3
13984 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13985 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
13986 }
13987
13988 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13989 +{
13990 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
13991 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
13992 +}
13993 +
13994 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
13995 {
13996 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
13997 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
13998 index f2b489c..4f7e2e5 100644
13999 --- a/arch/x86/include/asm/pgtable-2level.h
14000 +++ b/arch/x86/include/asm/pgtable-2level.h
14001 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
14002
14003 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14004 {
14005 + pax_open_kernel();
14006 *pmdp = pmd;
14007 + pax_close_kernel();
14008 }
14009
14010 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14011 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
14012 index 4cc9f2b..5fd9226 100644
14013 --- a/arch/x86/include/asm/pgtable-3level.h
14014 +++ b/arch/x86/include/asm/pgtable-3level.h
14015 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14016
14017 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14018 {
14019 + pax_open_kernel();
14020 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
14021 + pax_close_kernel();
14022 }
14023
14024 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14025 {
14026 + pax_open_kernel();
14027 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
14028 + pax_close_kernel();
14029 }
14030
14031 /*
14032 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
14033 index 1c1a955..50f828c 100644
14034 --- a/arch/x86/include/asm/pgtable.h
14035 +++ b/arch/x86/include/asm/pgtable.h
14036 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14037
14038 #ifndef __PAGETABLE_PUD_FOLDED
14039 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
14040 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
14041 #define pgd_clear(pgd) native_pgd_clear(pgd)
14042 #endif
14043
14044 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14045
14046 #define arch_end_context_switch(prev) do {} while(0)
14047
14048 +#define pax_open_kernel() native_pax_open_kernel()
14049 +#define pax_close_kernel() native_pax_close_kernel()
14050 #endif /* CONFIG_PARAVIRT */
14051
14052 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
14053 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
14054 +
14055 +#ifdef CONFIG_PAX_KERNEXEC
14056 +static inline unsigned long native_pax_open_kernel(void)
14057 +{
14058 + unsigned long cr0;
14059 +
14060 + preempt_disable();
14061 + barrier();
14062 + cr0 = read_cr0() ^ X86_CR0_WP;
14063 + BUG_ON(cr0 & X86_CR0_WP);
14064 + write_cr0(cr0);
14065 + return cr0 ^ X86_CR0_WP;
14066 +}
14067 +
14068 +static inline unsigned long native_pax_close_kernel(void)
14069 +{
14070 + unsigned long cr0;
14071 +
14072 + cr0 = read_cr0() ^ X86_CR0_WP;
14073 + BUG_ON(!(cr0 & X86_CR0_WP));
14074 + write_cr0(cr0);
14075 + barrier();
14076 + preempt_enable_no_resched();
14077 + return cr0 ^ X86_CR0_WP;
14078 +}
14079 +#else
14080 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
14081 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
14082 +#endif
14083 +
14084 /*
14085 * The following only work if pte_present() is true.
14086 * Undefined behaviour if not..
14087 */
14088 +static inline int pte_user(pte_t pte)
14089 +{
14090 + return pte_val(pte) & _PAGE_USER;
14091 +}
14092 +
14093 static inline int pte_dirty(pte_t pte)
14094 {
14095 return pte_flags(pte) & _PAGE_DIRTY;
14096 @@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14097 return pte_clear_flags(pte, _PAGE_RW);
14098 }
14099
14100 +static inline pte_t pte_mkread(pte_t pte)
14101 +{
14102 + return __pte(pte_val(pte) | _PAGE_USER);
14103 +}
14104 +
14105 static inline pte_t pte_mkexec(pte_t pte)
14106 {
14107 - return pte_clear_flags(pte, _PAGE_NX);
14108 +#ifdef CONFIG_X86_PAE
14109 + if (__supported_pte_mask & _PAGE_NX)
14110 + return pte_clear_flags(pte, _PAGE_NX);
14111 + else
14112 +#endif
14113 + return pte_set_flags(pte, _PAGE_USER);
14114 +}
14115 +
14116 +static inline pte_t pte_exprotect(pte_t pte)
14117 +{
14118 +#ifdef CONFIG_X86_PAE
14119 + if (__supported_pte_mask & _PAGE_NX)
14120 + return pte_set_flags(pte, _PAGE_NX);
14121 + else
14122 +#endif
14123 + return pte_clear_flags(pte, _PAGE_USER);
14124 }
14125
14126 static inline pte_t pte_mkdirty(pte_t pte)
14127 @@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14128 #endif
14129
14130 #ifndef __ASSEMBLY__
14131 +
14132 +#ifdef CONFIG_PAX_PER_CPU_PGD
14133 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14134 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14135 +{
14136 + return cpu_pgd[cpu];
14137 +}
14138 +#endif
14139 +
14140 #include <linux/mm_types.h>
14141
14142 static inline int pte_none(pte_t pte)
14143 @@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14144
14145 static inline int pgd_bad(pgd_t pgd)
14146 {
14147 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14148 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14149 }
14150
14151 static inline int pgd_none(pgd_t pgd)
14152 @@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
14153 * pgd_offset() returns a (pgd_t *)
14154 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14155 */
14156 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14157 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14158 +
14159 +#ifdef CONFIG_PAX_PER_CPU_PGD
14160 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14161 +#endif
14162 +
14163 /*
14164 * a shortcut which implies the use of the kernel's pgd, instead
14165 * of a process's
14166 @@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
14167 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14168 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14169
14170 +#ifdef CONFIG_X86_32
14171 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14172 +#else
14173 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14174 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14175 +
14176 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14177 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
14178 +#else
14179 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
14180 +#endif
14181 +
14182 +#endif
14183 +
14184 #ifndef __ASSEMBLY__
14185
14186 extern int direct_gbpages;
14187 @@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14188 * dst and src can be on the same page, but the range must not overlap,
14189 * and must not cross a page boundary.
14190 */
14191 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14192 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14193 {
14194 - memcpy(dst, src, count * sizeof(pgd_t));
14195 + pax_open_kernel();
14196 + while (count--)
14197 + *dst++ = *src++;
14198 + pax_close_kernel();
14199 }
14200
14201 +#ifdef CONFIG_PAX_PER_CPU_PGD
14202 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14203 +#endif
14204 +
14205 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14206 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14207 +#else
14208 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14209 +#endif
14210
14211 #include <asm-generic/pgtable.h>
14212 #endif /* __ASSEMBLY__ */
14213 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14214 index 8faa215..a8a17ea 100644
14215 --- a/arch/x86/include/asm/pgtable_32.h
14216 +++ b/arch/x86/include/asm/pgtable_32.h
14217 @@ -25,9 +25,6 @@
14218 struct mm_struct;
14219 struct vm_area_struct;
14220
14221 -extern pgd_t swapper_pg_dir[1024];
14222 -extern pgd_t initial_page_table[1024];
14223 -
14224 static inline void pgtable_cache_init(void) { }
14225 static inline void check_pgt_cache(void) { }
14226 void paging_init(void);
14227 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14228 # include <asm/pgtable-2level.h>
14229 #endif
14230
14231 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14232 +extern pgd_t initial_page_table[PTRS_PER_PGD];
14233 +#ifdef CONFIG_X86_PAE
14234 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14235 +#endif
14236 +
14237 #if defined(CONFIG_HIGHPTE)
14238 #define pte_offset_map(dir, address) \
14239 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14240 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14241 /* Clear a kernel PTE and flush it from the TLB */
14242 #define kpte_clear_flush(ptep, vaddr) \
14243 do { \
14244 + pax_open_kernel(); \
14245 pte_clear(&init_mm, (vaddr), (ptep)); \
14246 + pax_close_kernel(); \
14247 __flush_tlb_one((vaddr)); \
14248 } while (0)
14249
14250 @@ -75,6 +80,9 @@ do { \
14251
14252 #endif /* !__ASSEMBLY__ */
14253
14254 +#define HAVE_ARCH_UNMAPPED_AREA
14255 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14256 +
14257 /*
14258 * kern_addr_valid() is (1) for FLATMEM and (0) for
14259 * SPARSEMEM and DISCONTIGMEM
14260 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14261 index ed5903b..c7fe163 100644
14262 --- a/arch/x86/include/asm/pgtable_32_types.h
14263 +++ b/arch/x86/include/asm/pgtable_32_types.h
14264 @@ -8,7 +8,7 @@
14265 */
14266 #ifdef CONFIG_X86_PAE
14267 # include <asm/pgtable-3level_types.h>
14268 -# define PMD_SIZE (1UL << PMD_SHIFT)
14269 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14270 # define PMD_MASK (~(PMD_SIZE - 1))
14271 #else
14272 # include <asm/pgtable-2level_types.h>
14273 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14274 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14275 #endif
14276
14277 +#ifdef CONFIG_PAX_KERNEXEC
14278 +#ifndef __ASSEMBLY__
14279 +extern unsigned char MODULES_EXEC_VADDR[];
14280 +extern unsigned char MODULES_EXEC_END[];
14281 +#endif
14282 +#include <asm/boot.h>
14283 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14284 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14285 +#else
14286 +#define ktla_ktva(addr) (addr)
14287 +#define ktva_ktla(addr) (addr)
14288 +#endif
14289 +
14290 #define MODULES_VADDR VMALLOC_START
14291 #define MODULES_END VMALLOC_END
14292 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14293 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14294 index 47356f9..deb94a2 100644
14295 --- a/arch/x86/include/asm/pgtable_64.h
14296 +++ b/arch/x86/include/asm/pgtable_64.h
14297 @@ -16,10 +16,14 @@
14298
14299 extern pud_t level3_kernel_pgt[512];
14300 extern pud_t level3_ident_pgt[512];
14301 +extern pud_t level3_vmalloc_start_pgt[512];
14302 +extern pud_t level3_vmalloc_end_pgt[512];
14303 +extern pud_t level3_vmemmap_pgt[512];
14304 +extern pud_t level2_vmemmap_pgt[512];
14305 extern pmd_t level2_kernel_pgt[512];
14306 extern pmd_t level2_fixmap_pgt[512];
14307 -extern pmd_t level2_ident_pgt[512];
14308 -extern pgd_t init_level4_pgt[];
14309 +extern pmd_t level2_ident_pgt[512*2];
14310 +extern pgd_t init_level4_pgt[512];
14311
14312 #define swapper_pg_dir init_level4_pgt
14313
14314 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14315
14316 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14317 {
14318 + pax_open_kernel();
14319 *pmdp = pmd;
14320 + pax_close_kernel();
14321 }
14322
14323 static inline void native_pmd_clear(pmd_t *pmd)
14324 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14325
14326 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14327 {
14328 + pax_open_kernel();
14329 *pudp = pud;
14330 + pax_close_kernel();
14331 }
14332
14333 static inline void native_pud_clear(pud_t *pud)
14334 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14335
14336 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14337 {
14338 + pax_open_kernel();
14339 + *pgdp = pgd;
14340 + pax_close_kernel();
14341 +}
14342 +
14343 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14344 +{
14345 *pgdp = pgd;
14346 }
14347
14348 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14349 index 766ea16..5b96cb3 100644
14350 --- a/arch/x86/include/asm/pgtable_64_types.h
14351 +++ b/arch/x86/include/asm/pgtable_64_types.h
14352 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
14353 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14354 #define MODULES_END _AC(0xffffffffff000000, UL)
14355 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14356 +#define MODULES_EXEC_VADDR MODULES_VADDR
14357 +#define MODULES_EXEC_END MODULES_END
14358 +
14359 +#define ktla_ktva(addr) (addr)
14360 +#define ktva_ktla(addr) (addr)
14361
14362 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
14363 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14364 index 3c32db8..1ddccf5 100644
14365 --- a/arch/x86/include/asm/pgtable_types.h
14366 +++ b/arch/x86/include/asm/pgtable_types.h
14367 @@ -16,13 +16,12 @@
14368 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14369 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14370 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14371 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14372 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14373 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14374 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14375 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14376 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14377 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14378 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14379 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14380 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14381 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14382
14383 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14384 @@ -40,7 +39,6 @@
14385 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14386 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14387 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14388 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14389 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14390 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14391 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14392 @@ -57,8 +55,10 @@
14393
14394 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14395 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14396 -#else
14397 +#elif defined(CONFIG_KMEMCHECK)
14398 #define _PAGE_NX (_AT(pteval_t, 0))
14399 +#else
14400 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14401 #endif
14402
14403 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14404 @@ -116,6 +116,9 @@
14405 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14406 _PAGE_ACCESSED)
14407
14408 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
14409 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
14410 +
14411 #define __PAGE_KERNEL_EXEC \
14412 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14413 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14414 @@ -126,7 +129,7 @@
14415 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14416 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14417 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14418 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14419 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14420 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14421 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14422 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14423 @@ -188,8 +191,8 @@
14424 * bits are combined, this will alow user to access the high address mapped
14425 * VDSO in the presence of CONFIG_COMPAT_VDSO
14426 */
14427 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14428 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14429 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14430 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14431 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14432 #endif
14433
14434 @@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14435 {
14436 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14437 }
14438 +#endif
14439
14440 +#if PAGETABLE_LEVELS == 3
14441 +#include <asm-generic/pgtable-nopud.h>
14442 +#endif
14443 +
14444 +#if PAGETABLE_LEVELS == 2
14445 +#include <asm-generic/pgtable-nopmd.h>
14446 +#endif
14447 +
14448 +#ifndef __ASSEMBLY__
14449 #if PAGETABLE_LEVELS > 3
14450 typedef struct { pudval_t pud; } pud_t;
14451
14452 @@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14453 return pud.pud;
14454 }
14455 #else
14456 -#include <asm-generic/pgtable-nopud.h>
14457 -
14458 static inline pudval_t native_pud_val(pud_t pud)
14459 {
14460 return native_pgd_val(pud.pgd);
14461 @@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14462 return pmd.pmd;
14463 }
14464 #else
14465 -#include <asm-generic/pgtable-nopmd.h>
14466 -
14467 static inline pmdval_t native_pmd_val(pmd_t pmd)
14468 {
14469 return native_pgd_val(pmd.pud.pgd);
14470 @@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14471
14472 extern pteval_t __supported_pte_mask;
14473 extern void set_nx(void);
14474 -extern int nx_enabled;
14475
14476 #define pgprot_writecombine pgprot_writecombine
14477 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14478 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14479 index 888184b..a07ac89 100644
14480 --- a/arch/x86/include/asm/processor.h
14481 +++ b/arch/x86/include/asm/processor.h
14482 @@ -287,7 +287,7 @@ struct tss_struct {
14483
14484 } ____cacheline_aligned;
14485
14486 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14487 +extern struct tss_struct init_tss[NR_CPUS];
14488
14489 /*
14490 * Save the original ist values for checking stack pointers during debugging
14491 @@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
14492 */
14493 #define TASK_SIZE PAGE_OFFSET
14494 #define TASK_SIZE_MAX TASK_SIZE
14495 +
14496 +#ifdef CONFIG_PAX_SEGMEXEC
14497 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14498 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14499 +#else
14500 #define STACK_TOP TASK_SIZE
14501 -#define STACK_TOP_MAX STACK_TOP
14502 +#endif
14503 +
14504 +#define STACK_TOP_MAX TASK_SIZE
14505
14506 #define INIT_THREAD { \
14507 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
14508 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14509 .vm86_info = NULL, \
14510 .sysenter_cs = __KERNEL_CS, \
14511 .io_bitmap_ptr = NULL, \
14512 @@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
14513 */
14514 #define INIT_TSS { \
14515 .x86_tss = { \
14516 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
14517 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14518 .ss0 = __KERNEL_DS, \
14519 .ss1 = __KERNEL_CS, \
14520 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14521 @@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
14522 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14523
14524 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14525 -#define KSTK_TOP(info) \
14526 -({ \
14527 - unsigned long *__ptr = (unsigned long *)(info); \
14528 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14529 -})
14530 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14531
14532 /*
14533 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14534 @@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14535 #define task_pt_regs(task) \
14536 ({ \
14537 struct pt_regs *__regs__; \
14538 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14539 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14540 __regs__ - 1; \
14541 })
14542
14543 @@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14544 /*
14545 * User space process size. 47bits minus one guard page.
14546 */
14547 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14548 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14549
14550 /* This decides where the kernel will search for a free chunk of vm
14551 * space during mmap's.
14552 */
14553 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14554 - 0xc0000000 : 0xFFFFe000)
14555 + 0xc0000000 : 0xFFFFf000)
14556
14557 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14558 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14559 @@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14560 #define STACK_TOP_MAX TASK_SIZE_MAX
14561
14562 #define INIT_THREAD { \
14563 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14564 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14565 }
14566
14567 #define INIT_TSS { \
14568 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14569 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14570 }
14571
14572 /*
14573 @@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14574 */
14575 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14576
14577 +#ifdef CONFIG_PAX_SEGMEXEC
14578 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14579 +#endif
14580 +
14581 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14582
14583 /* Get/set a process' ability to use the timestamp counter instruction */
14584 @@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
14585 #define cpu_has_amd_erratum(x) (false)
14586 #endif /* CONFIG_CPU_SUP_AMD */
14587
14588 -extern unsigned long arch_align_stack(unsigned long sp);
14589 +#define arch_align_stack(x) ((x) & ~0xfUL)
14590 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14591
14592 void default_idle(void);
14593 bool set_pm_idle_to_default(void);
14594
14595 -void stop_this_cpu(void *dummy);
14596 +void stop_this_cpu(void *dummy) __noreturn;
14597
14598 #endif /* _ASM_X86_PROCESSOR_H */
14599 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14600 index 942a086..6c26446 100644
14601 --- a/arch/x86/include/asm/ptrace.h
14602 +++ b/arch/x86/include/asm/ptrace.h
14603 @@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14604 }
14605
14606 /*
14607 - * user_mode_vm(regs) determines whether a register set came from user mode.
14608 + * user_mode(regs) determines whether a register set came from user mode.
14609 * This is true if V8086 mode was enabled OR if the register set was from
14610 * protected mode with RPL-3 CS value. This tricky test checks that with
14611 * one comparison. Many places in the kernel can bypass this full check
14612 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14613 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14614 + * be used.
14615 */
14616 -static inline int user_mode(struct pt_regs *regs)
14617 +static inline int user_mode_novm(struct pt_regs *regs)
14618 {
14619 #ifdef CONFIG_X86_32
14620 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14621 #else
14622 - return !!(regs->cs & 3);
14623 + return !!(regs->cs & SEGMENT_RPL_MASK);
14624 #endif
14625 }
14626
14627 -static inline int user_mode_vm(struct pt_regs *regs)
14628 +static inline int user_mode(struct pt_regs *regs)
14629 {
14630 #ifdef CONFIG_X86_32
14631 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14632 USER_RPL;
14633 #else
14634 - return user_mode(regs);
14635 + return user_mode_novm(regs);
14636 #endif
14637 }
14638
14639 @@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14640 #ifdef CONFIG_X86_64
14641 static inline bool user_64bit_mode(struct pt_regs *regs)
14642 {
14643 + unsigned long cs = regs->cs & 0xffff;
14644 #ifndef CONFIG_PARAVIRT
14645 /*
14646 * On non-paravirt systems, this is the only long mode CPL 3
14647 * selector. We do not allow long mode selectors in the LDT.
14648 */
14649 - return regs->cs == __USER_CS;
14650 + return cs == __USER_CS;
14651 #else
14652 /* Headers are too twisted for this to go in paravirt.h. */
14653 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
14654 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
14655 #endif
14656 }
14657
14658 @@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
14659 * Traps from the kernel do not save sp and ss.
14660 * Use the helper function to retrieve sp.
14661 */
14662 - if (offset == offsetof(struct pt_regs, sp) &&
14663 - regs->cs == __KERNEL_CS)
14664 - return kernel_stack_pointer(regs);
14665 + if (offset == offsetof(struct pt_regs, sp)) {
14666 + unsigned long cs = regs->cs & 0xffff;
14667 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
14668 + return kernel_stack_pointer(regs);
14669 + }
14670 #endif
14671 return *(unsigned long *)((unsigned long)regs + offset);
14672 }
14673 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
14674 index fe1ec5b..dc5c3fe 100644
14675 --- a/arch/x86/include/asm/realmode.h
14676 +++ b/arch/x86/include/asm/realmode.h
14677 @@ -22,16 +22,14 @@ struct real_mode_header {
14678 #endif
14679 /* APM/BIOS reboot */
14680 u32 machine_real_restart_asm;
14681 -#ifdef CONFIG_X86_64
14682 u32 machine_real_restart_seg;
14683 -#endif
14684 };
14685
14686 /* This must match data at trampoline_32/64.S */
14687 struct trampoline_header {
14688 #ifdef CONFIG_X86_32
14689 u32 start;
14690 - u16 gdt_pad;
14691 + u16 boot_cs;
14692 u16 gdt_limit;
14693 u32 gdt_base;
14694 #else
14695 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
14696 index a82c4f1..ac45053 100644
14697 --- a/arch/x86/include/asm/reboot.h
14698 +++ b/arch/x86/include/asm/reboot.h
14699 @@ -6,13 +6,13 @@
14700 struct pt_regs;
14701
14702 struct machine_ops {
14703 - void (*restart)(char *cmd);
14704 - void (*halt)(void);
14705 - void (*power_off)(void);
14706 + void (* __noreturn restart)(char *cmd);
14707 + void (* __noreturn halt)(void);
14708 + void (* __noreturn power_off)(void);
14709 void (*shutdown)(void);
14710 void (*crash_shutdown)(struct pt_regs *);
14711 - void (*emergency_restart)(void);
14712 -};
14713 + void (* __noreturn emergency_restart)(void);
14714 +} __no_const;
14715
14716 extern struct machine_ops machine_ops;
14717
14718 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
14719 index 2dbe4a7..ce1db00 100644
14720 --- a/arch/x86/include/asm/rwsem.h
14721 +++ b/arch/x86/include/asm/rwsem.h
14722 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
14723 {
14724 asm volatile("# beginning down_read\n\t"
14725 LOCK_PREFIX _ASM_INC "(%1)\n\t"
14726 +
14727 +#ifdef CONFIG_PAX_REFCOUNT
14728 + "jno 0f\n"
14729 + LOCK_PREFIX _ASM_DEC "(%1)\n"
14730 + "int $4\n0:\n"
14731 + _ASM_EXTABLE(0b, 0b)
14732 +#endif
14733 +
14734 /* adds 0x00000001 */
14735 " jns 1f\n"
14736 " call call_rwsem_down_read_failed\n"
14737 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
14738 "1:\n\t"
14739 " mov %1,%2\n\t"
14740 " add %3,%2\n\t"
14741 +
14742 +#ifdef CONFIG_PAX_REFCOUNT
14743 + "jno 0f\n"
14744 + "sub %3,%2\n"
14745 + "int $4\n0:\n"
14746 + _ASM_EXTABLE(0b, 0b)
14747 +#endif
14748 +
14749 " jle 2f\n\t"
14750 LOCK_PREFIX " cmpxchg %2,%0\n\t"
14751 " jnz 1b\n\t"
14752 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
14753 long tmp;
14754 asm volatile("# beginning down_write\n\t"
14755 LOCK_PREFIX " xadd %1,(%2)\n\t"
14756 +
14757 +#ifdef CONFIG_PAX_REFCOUNT
14758 + "jno 0f\n"
14759 + "mov %1,(%2)\n"
14760 + "int $4\n0:\n"
14761 + _ASM_EXTABLE(0b, 0b)
14762 +#endif
14763 +
14764 /* adds 0xffff0001, returns the old value */
14765 " test %1,%1\n\t"
14766 /* was the count 0 before? */
14767 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
14768 long tmp;
14769 asm volatile("# beginning __up_read\n\t"
14770 LOCK_PREFIX " xadd %1,(%2)\n\t"
14771 +
14772 +#ifdef CONFIG_PAX_REFCOUNT
14773 + "jno 0f\n"
14774 + "mov %1,(%2)\n"
14775 + "int $4\n0:\n"
14776 + _ASM_EXTABLE(0b, 0b)
14777 +#endif
14778 +
14779 /* subtracts 1, returns the old value */
14780 " jns 1f\n\t"
14781 " call call_rwsem_wake\n" /* expects old value in %edx */
14782 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
14783 long tmp;
14784 asm volatile("# beginning __up_write\n\t"
14785 LOCK_PREFIX " xadd %1,(%2)\n\t"
14786 +
14787 +#ifdef CONFIG_PAX_REFCOUNT
14788 + "jno 0f\n"
14789 + "mov %1,(%2)\n"
14790 + "int $4\n0:\n"
14791 + _ASM_EXTABLE(0b, 0b)
14792 +#endif
14793 +
14794 /* subtracts 0xffff0001, returns the old value */
14795 " jns 1f\n\t"
14796 " call call_rwsem_wake\n" /* expects old value in %edx */
14797 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14798 {
14799 asm volatile("# beginning __downgrade_write\n\t"
14800 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
14801 +
14802 +#ifdef CONFIG_PAX_REFCOUNT
14803 + "jno 0f\n"
14804 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
14805 + "int $4\n0:\n"
14806 + _ASM_EXTABLE(0b, 0b)
14807 +#endif
14808 +
14809 /*
14810 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
14811 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
14812 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14813 */
14814 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14815 {
14816 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
14817 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
14818 +
14819 +#ifdef CONFIG_PAX_REFCOUNT
14820 + "jno 0f\n"
14821 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
14822 + "int $4\n0:\n"
14823 + _ASM_EXTABLE(0b, 0b)
14824 +#endif
14825 +
14826 : "+m" (sem->count)
14827 : "er" (delta));
14828 }
14829 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14830 */
14831 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
14832 {
14833 - return delta + xadd(&sem->count, delta);
14834 + return delta + xadd_check_overflow(&sem->count, delta);
14835 }
14836
14837 #endif /* __KERNEL__ */
14838 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
14839 index c48a950..c6d7468 100644
14840 --- a/arch/x86/include/asm/segment.h
14841 +++ b/arch/x86/include/asm/segment.h
14842 @@ -64,10 +64,15 @@
14843 * 26 - ESPFIX small SS
14844 * 27 - per-cpu [ offset to per-cpu data area ]
14845 * 28 - stack_canary-20 [ for stack protector ]
14846 - * 29 - unused
14847 - * 30 - unused
14848 + * 29 - PCI BIOS CS
14849 + * 30 - PCI BIOS DS
14850 * 31 - TSS for double fault handler
14851 */
14852 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
14853 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
14854 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
14855 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
14856 +
14857 #define GDT_ENTRY_TLS_MIN 6
14858 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
14859
14860 @@ -79,6 +84,8 @@
14861
14862 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
14863
14864 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
14865 +
14866 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
14867
14868 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
14869 @@ -104,6 +111,12 @@
14870 #define __KERNEL_STACK_CANARY 0
14871 #endif
14872
14873 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
14874 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
14875 +
14876 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
14877 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
14878 +
14879 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
14880
14881 /*
14882 @@ -141,7 +154,7 @@
14883 */
14884
14885 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
14886 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
14887 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
14888
14889
14890 #else
14891 @@ -165,6 +178,8 @@
14892 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
14893 #define __USER32_DS __USER_DS
14894
14895 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
14896 +
14897 #define GDT_ENTRY_TSS 8 /* needs two entries */
14898 #define GDT_ENTRY_LDT 10 /* needs two entries */
14899 #define GDT_ENTRY_TLS_MIN 12
14900 @@ -185,6 +200,7 @@
14901 #endif
14902
14903 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
14904 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
14905 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
14906 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
14907 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
14908 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
14909 {
14910 unsigned long __limit;
14911 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
14912 - return __limit + 1;
14913 + return __limit;
14914 }
14915
14916 #endif /* !__ASSEMBLY__ */
14917 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
14918 index b073aae..39f9bdd 100644
14919 --- a/arch/x86/include/asm/smp.h
14920 +++ b/arch/x86/include/asm/smp.h
14921 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
14922 /* cpus sharing the last level cache: */
14923 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
14924 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
14925 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
14926 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
14927
14928 static inline struct cpumask *cpu_sibling_mask(int cpu)
14929 {
14930 @@ -79,7 +79,7 @@ struct smp_ops {
14931
14932 void (*send_call_func_ipi)(const struct cpumask *mask);
14933 void (*send_call_func_single_ipi)(int cpu);
14934 -};
14935 +} __no_const;
14936
14937 /* Globals due to paravirt */
14938 extern void set_cpu_sibling_map(int cpu);
14939 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
14940 extern int safe_smp_processor_id(void);
14941
14942 #elif defined(CONFIG_X86_64_SMP)
14943 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14944 -
14945 -#define stack_smp_processor_id() \
14946 -({ \
14947 - struct thread_info *ti; \
14948 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
14949 - ti->cpu; \
14950 -})
14951 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14952 +#define stack_smp_processor_id() raw_smp_processor_id()
14953 #define safe_smp_processor_id() smp_processor_id()
14954
14955 #endif
14956 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
14957 index 33692ea..350a534 100644
14958 --- a/arch/x86/include/asm/spinlock.h
14959 +++ b/arch/x86/include/asm/spinlock.h
14960 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
14961 static inline void arch_read_lock(arch_rwlock_t *rw)
14962 {
14963 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
14964 +
14965 +#ifdef CONFIG_PAX_REFCOUNT
14966 + "jno 0f\n"
14967 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
14968 + "int $4\n0:\n"
14969 + _ASM_EXTABLE(0b, 0b)
14970 +#endif
14971 +
14972 "jns 1f\n"
14973 "call __read_lock_failed\n\t"
14974 "1:\n"
14975 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
14976 static inline void arch_write_lock(arch_rwlock_t *rw)
14977 {
14978 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
14979 +
14980 +#ifdef CONFIG_PAX_REFCOUNT
14981 + "jno 0f\n"
14982 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
14983 + "int $4\n0:\n"
14984 + _ASM_EXTABLE(0b, 0b)
14985 +#endif
14986 +
14987 "jz 1f\n"
14988 "call __write_lock_failed\n\t"
14989 "1:\n"
14990 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
14991
14992 static inline void arch_read_unlock(arch_rwlock_t *rw)
14993 {
14994 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
14995 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
14996 +
14997 +#ifdef CONFIG_PAX_REFCOUNT
14998 + "jno 0f\n"
14999 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15000 + "int $4\n0:\n"
15001 + _ASM_EXTABLE(0b, 0b)
15002 +#endif
15003 +
15004 :"+m" (rw->lock) : : "memory");
15005 }
15006
15007 static inline void arch_write_unlock(arch_rwlock_t *rw)
15008 {
15009 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15010 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15011 +
15012 +#ifdef CONFIG_PAX_REFCOUNT
15013 + "jno 0f\n"
15014 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15015 + "int $4\n0:\n"
15016 + _ASM_EXTABLE(0b, 0b)
15017 +#endif
15018 +
15019 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15020 }
15021
15022 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15023 index 6a99859..03cb807 100644
15024 --- a/arch/x86/include/asm/stackprotector.h
15025 +++ b/arch/x86/include/asm/stackprotector.h
15026 @@ -47,7 +47,7 @@
15027 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15028 */
15029 #define GDT_STACK_CANARY_INIT \
15030 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15031 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15032
15033 /*
15034 * Initialize the stackprotector canary value.
15035 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15036
15037 static inline void load_stack_canary_segment(void)
15038 {
15039 -#ifdef CONFIG_X86_32
15040 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15041 asm volatile ("mov %0, %%gs" : : "r" (0));
15042 #endif
15043 }
15044 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15045 index 70bbe39..4ae2bd4 100644
15046 --- a/arch/x86/include/asm/stacktrace.h
15047 +++ b/arch/x86/include/asm/stacktrace.h
15048 @@ -11,28 +11,20 @@
15049
15050 extern int kstack_depth_to_print;
15051
15052 -struct thread_info;
15053 +struct task_struct;
15054 struct stacktrace_ops;
15055
15056 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15057 - unsigned long *stack,
15058 - unsigned long bp,
15059 - const struct stacktrace_ops *ops,
15060 - void *data,
15061 - unsigned long *end,
15062 - int *graph);
15063 +typedef unsigned long walk_stack_t(struct task_struct *task,
15064 + void *stack_start,
15065 + unsigned long *stack,
15066 + unsigned long bp,
15067 + const struct stacktrace_ops *ops,
15068 + void *data,
15069 + unsigned long *end,
15070 + int *graph);
15071
15072 -extern unsigned long
15073 -print_context_stack(struct thread_info *tinfo,
15074 - unsigned long *stack, unsigned long bp,
15075 - const struct stacktrace_ops *ops, void *data,
15076 - unsigned long *end, int *graph);
15077 -
15078 -extern unsigned long
15079 -print_context_stack_bp(struct thread_info *tinfo,
15080 - unsigned long *stack, unsigned long bp,
15081 - const struct stacktrace_ops *ops, void *data,
15082 - unsigned long *end, int *graph);
15083 +extern walk_stack_t print_context_stack;
15084 +extern walk_stack_t print_context_stack_bp;
15085
15086 /* Generic stack tracer with callbacks */
15087
15088 @@ -40,7 +32,7 @@ struct stacktrace_ops {
15089 void (*address)(void *data, unsigned long address, int reliable);
15090 /* On negative return stop dumping */
15091 int (*stack)(void *data, char *name);
15092 - walk_stack_t walk_stack;
15093 + walk_stack_t *walk_stack;
15094 };
15095
15096 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15097 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15098 index 4ec45b3..a4f0a8a 100644
15099 --- a/arch/x86/include/asm/switch_to.h
15100 +++ b/arch/x86/include/asm/switch_to.h
15101 @@ -108,7 +108,7 @@ do { \
15102 "call __switch_to\n\t" \
15103 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15104 __switch_canary \
15105 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
15106 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15107 "movq %%rax,%%rdi\n\t" \
15108 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15109 "jnz ret_from_fork\n\t" \
15110 @@ -119,7 +119,7 @@ do { \
15111 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15112 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15113 [_tif_fork] "i" (_TIF_FORK), \
15114 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
15115 + [thread_info] "m" (current_tinfo), \
15116 [current_task] "m" (current_task) \
15117 __switch_canary_iparam \
15118 : "memory", "cc" __EXTRA_CLOBBER)
15119 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15120 index 2d946e6..e453ec4 100644
15121 --- a/arch/x86/include/asm/thread_info.h
15122 +++ b/arch/x86/include/asm/thread_info.h
15123 @@ -10,6 +10,7 @@
15124 #include <linux/compiler.h>
15125 #include <asm/page.h>
15126 #include <asm/types.h>
15127 +#include <asm/percpu.h>
15128
15129 /*
15130 * low level task data that entry.S needs immediate access to
15131 @@ -24,7 +25,6 @@ struct exec_domain;
15132 #include <linux/atomic.h>
15133
15134 struct thread_info {
15135 - struct task_struct *task; /* main task structure */
15136 struct exec_domain *exec_domain; /* execution domain */
15137 __u32 flags; /* low level flags */
15138 __u32 status; /* thread synchronous flags */
15139 @@ -34,19 +34,13 @@ struct thread_info {
15140 mm_segment_t addr_limit;
15141 struct restart_block restart_block;
15142 void __user *sysenter_return;
15143 -#ifdef CONFIG_X86_32
15144 - unsigned long previous_esp; /* ESP of the previous stack in
15145 - case of nested (IRQ) stacks
15146 - */
15147 - __u8 supervisor_stack[0];
15148 -#endif
15149 + unsigned long lowest_stack;
15150 unsigned int sig_on_uaccess_error:1;
15151 unsigned int uaccess_err:1; /* uaccess failed */
15152 };
15153
15154 -#define INIT_THREAD_INFO(tsk) \
15155 +#define INIT_THREAD_INFO \
15156 { \
15157 - .task = &tsk, \
15158 .exec_domain = &default_exec_domain, \
15159 .flags = 0, \
15160 .cpu = 0, \
15161 @@ -57,7 +51,7 @@ struct thread_info {
15162 }, \
15163 }
15164
15165 -#define init_thread_info (init_thread_union.thread_info)
15166 +#define init_thread_info (init_thread_union.stack)
15167 #define init_stack (init_thread_union.stack)
15168
15169 #else /* !__ASSEMBLY__ */
15170 @@ -98,6 +92,7 @@ struct thread_info {
15171 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15172 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15173 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15174 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15175
15176 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15177 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15178 @@ -122,17 +117,18 @@ struct thread_info {
15179 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15180 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15181 #define _TIF_X32 (1 << TIF_X32)
15182 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15183
15184 /* work to do in syscall_trace_enter() */
15185 #define _TIF_WORK_SYSCALL_ENTRY \
15186 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15187 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15188 - _TIF_NOHZ)
15189 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
15190
15191 /* work to do in syscall_trace_leave() */
15192 #define _TIF_WORK_SYSCALL_EXIT \
15193 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15194 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15195 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15196
15197 /* work to do on interrupt/exception return */
15198 #define _TIF_WORK_MASK \
15199 @@ -143,7 +139,7 @@ struct thread_info {
15200 /* work to do on any return to user space */
15201 #define _TIF_ALLWORK_MASK \
15202 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15203 - _TIF_NOHZ)
15204 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
15205
15206 /* Only used for 64 bit */
15207 #define _TIF_DO_NOTIFY_MASK \
15208 @@ -159,45 +155,40 @@ struct thread_info {
15209
15210 #define PREEMPT_ACTIVE 0x10000000
15211
15212 -#ifdef CONFIG_X86_32
15213 -
15214 -#define STACK_WARN (THREAD_SIZE/8)
15215 -/*
15216 - * macros/functions for gaining access to the thread information structure
15217 - *
15218 - * preempt_count needs to be 1 initially, until the scheduler is functional.
15219 - */
15220 -#ifndef __ASSEMBLY__
15221 -
15222 -
15223 -/* how to get the current stack pointer from C */
15224 -register unsigned long current_stack_pointer asm("esp") __used;
15225 -
15226 -/* how to get the thread information struct from C */
15227 -static inline struct thread_info *current_thread_info(void)
15228 -{
15229 - return (struct thread_info *)
15230 - (current_stack_pointer & ~(THREAD_SIZE - 1));
15231 -}
15232 -
15233 -#else /* !__ASSEMBLY__ */
15234 -
15235 +#ifdef __ASSEMBLY__
15236 /* how to get the thread information struct from ASM */
15237 #define GET_THREAD_INFO(reg) \
15238 - movl $-THREAD_SIZE, reg; \
15239 - andl %esp, reg
15240 + mov PER_CPU_VAR(current_tinfo), reg
15241
15242 /* use this one if reg already contains %esp */
15243 -#define GET_THREAD_INFO_WITH_ESP(reg) \
15244 - andl $-THREAD_SIZE, reg
15245 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15246 +#else
15247 +/* how to get the thread information struct from C */
15248 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15249 +
15250 +static __always_inline struct thread_info *current_thread_info(void)
15251 +{
15252 + return this_cpu_read_stable(current_tinfo);
15253 +}
15254 +#endif
15255 +
15256 +#ifdef CONFIG_X86_32
15257 +
15258 +#define STACK_WARN (THREAD_SIZE/8)
15259 +/*
15260 + * macros/functions for gaining access to the thread information structure
15261 + *
15262 + * preempt_count needs to be 1 initially, until the scheduler is functional.
15263 + */
15264 +#ifndef __ASSEMBLY__
15265 +
15266 +/* how to get the current stack pointer from C */
15267 +register unsigned long current_stack_pointer asm("esp") __used;
15268
15269 #endif
15270
15271 #else /* X86_32 */
15272
15273 -#include <asm/percpu.h>
15274 -#define KERNEL_STACK_OFFSET (5*8)
15275 -
15276 /*
15277 * macros/functions for gaining access to the thread information structure
15278 * preempt_count needs to be 1 initially, until the scheduler is functional.
15279 @@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15280 #ifndef __ASSEMBLY__
15281 DECLARE_PER_CPU(unsigned long, kernel_stack);
15282
15283 -static inline struct thread_info *current_thread_info(void)
15284 -{
15285 - struct thread_info *ti;
15286 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
15287 - KERNEL_STACK_OFFSET - THREAD_SIZE);
15288 - return ti;
15289 -}
15290 -
15291 -#else /* !__ASSEMBLY__ */
15292 -
15293 -/* how to get the thread information struct from ASM */
15294 -#define GET_THREAD_INFO(reg) \
15295 - movq PER_CPU_VAR(kernel_stack),reg ; \
15296 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15297 -
15298 -/*
15299 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15300 - * a certain register (to be used in assembler memory operands).
15301 - */
15302 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15303 -
15304 +/* how to get the current stack pointer from C */
15305 +register unsigned long current_stack_pointer asm("rsp") __used;
15306 #endif
15307
15308 #endif /* !X86_32 */
15309 @@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15310 extern void arch_task_cache_init(void);
15311 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15312 extern void arch_release_task_struct(struct task_struct *tsk);
15313 +
15314 +#define __HAVE_THREAD_FUNCTIONS
15315 +#define task_thread_info(task) (&(task)->tinfo)
15316 +#define task_stack_page(task) ((task)->stack)
15317 +#define setup_thread_stack(p, org) do {} while (0)
15318 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15319 +
15320 #endif
15321 #endif /* _ASM_X86_THREAD_INFO_H */
15322 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15323 index 1709801..0a60f2f 100644
15324 --- a/arch/x86/include/asm/uaccess.h
15325 +++ b/arch/x86/include/asm/uaccess.h
15326 @@ -7,6 +7,7 @@
15327 #include <linux/compiler.h>
15328 #include <linux/thread_info.h>
15329 #include <linux/string.h>
15330 +#include <linux/sched.h>
15331 #include <asm/asm.h>
15332 #include <asm/page.h>
15333 #include <asm/smap.h>
15334 @@ -29,7 +30,12 @@
15335
15336 #define get_ds() (KERNEL_DS)
15337 #define get_fs() (current_thread_info()->addr_limit)
15338 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15339 +void __set_fs(mm_segment_t x);
15340 +void set_fs(mm_segment_t x);
15341 +#else
15342 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15343 +#endif
15344
15345 #define segment_eq(a, b) ((a).seg == (b).seg)
15346
15347 @@ -77,8 +83,33 @@
15348 * checks that the pointer is in the user space range - after calling
15349 * this function, memory access functions may still return -EFAULT.
15350 */
15351 -#define access_ok(type, addr, size) \
15352 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15353 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15354 +#define access_ok(type, addr, size) \
15355 +({ \
15356 + long __size = size; \
15357 + unsigned long __addr = (unsigned long)addr; \
15358 + unsigned long __addr_ao = __addr & PAGE_MASK; \
15359 + unsigned long __end_ao = __addr + __size - 1; \
15360 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15361 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15362 + while(__addr_ao <= __end_ao) { \
15363 + char __c_ao; \
15364 + __addr_ao += PAGE_SIZE; \
15365 + if (__size > PAGE_SIZE) \
15366 + cond_resched(); \
15367 + if (__get_user(__c_ao, (char __user *)__addr)) \
15368 + break; \
15369 + if (type != VERIFY_WRITE) { \
15370 + __addr = __addr_ao; \
15371 + continue; \
15372 + } \
15373 + if (__put_user(__c_ao, (char __user *)__addr)) \
15374 + break; \
15375 + __addr = __addr_ao; \
15376 + } \
15377 + } \
15378 + __ret_ao; \
15379 +})
15380
15381 /*
15382 * The exception table consists of pairs of addresses relative to the
15383 @@ -189,13 +220,21 @@ extern int __get_user_bad(void);
15384 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15385 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15386
15387 -
15388 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15389 +#define __copyuser_seg "gs;"
15390 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15391 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15392 +#else
15393 +#define __copyuser_seg
15394 +#define __COPYUSER_SET_ES
15395 +#define __COPYUSER_RESTORE_ES
15396 +#endif
15397
15398 #ifdef CONFIG_X86_32
15399 #define __put_user_asm_u64(x, addr, err, errret) \
15400 asm volatile(ASM_STAC "\n" \
15401 - "1: movl %%eax,0(%2)\n" \
15402 - "2: movl %%edx,4(%2)\n" \
15403 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15404 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15405 "3: " ASM_CLAC "\n" \
15406 ".section .fixup,\"ax\"\n" \
15407 "4: movl %3,%0\n" \
15408 @@ -208,8 +247,8 @@ extern int __get_user_bad(void);
15409
15410 #define __put_user_asm_ex_u64(x, addr) \
15411 asm volatile(ASM_STAC "\n" \
15412 - "1: movl %%eax,0(%1)\n" \
15413 - "2: movl %%edx,4(%1)\n" \
15414 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15415 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15416 "3: " ASM_CLAC "\n" \
15417 _ASM_EXTABLE_EX(1b, 2b) \
15418 _ASM_EXTABLE_EX(2b, 3b) \
15419 @@ -259,7 +298,7 @@ extern void __put_user_8(void);
15420 __typeof__(*(ptr)) __pu_val; \
15421 __chk_user_ptr(ptr); \
15422 might_fault(); \
15423 - __pu_val = x; \
15424 + __pu_val = (x); \
15425 switch (sizeof(*(ptr))) { \
15426 case 1: \
15427 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15428 @@ -358,7 +397,7 @@ do { \
15429
15430 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15431 asm volatile(ASM_STAC "\n" \
15432 - "1: mov"itype" %2,%"rtype"1\n" \
15433 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15434 "2: " ASM_CLAC "\n" \
15435 ".section .fixup,\"ax\"\n" \
15436 "3: mov %3,%0\n" \
15437 @@ -366,7 +405,7 @@ do { \
15438 " jmp 2b\n" \
15439 ".previous\n" \
15440 _ASM_EXTABLE(1b, 3b) \
15441 - : "=r" (err), ltype(x) \
15442 + : "=r" (err), ltype (x) \
15443 : "m" (__m(addr)), "i" (errret), "0" (err))
15444
15445 #define __get_user_size_ex(x, ptr, size) \
15446 @@ -391,7 +430,7 @@ do { \
15447 } while (0)
15448
15449 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15450 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15451 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15452 "2:\n" \
15453 _ASM_EXTABLE_EX(1b, 2b) \
15454 : ltype(x) : "m" (__m(addr)))
15455 @@ -408,13 +447,24 @@ do { \
15456 int __gu_err; \
15457 unsigned long __gu_val; \
15458 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15459 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
15460 + (x) = (__typeof__(*(ptr)))__gu_val; \
15461 __gu_err; \
15462 })
15463
15464 /* FIXME: this hack is definitely wrong -AK */
15465 struct __large_struct { unsigned long buf[100]; };
15466 -#define __m(x) (*(struct __large_struct __user *)(x))
15467 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15468 +#define ____m(x) \
15469 +({ \
15470 + unsigned long ____x = (unsigned long)(x); \
15471 + if (____x < PAX_USER_SHADOW_BASE) \
15472 + ____x += PAX_USER_SHADOW_BASE; \
15473 + (void __user *)____x; \
15474 +})
15475 +#else
15476 +#define ____m(x) (x)
15477 +#endif
15478 +#define __m(x) (*(struct __large_struct __user *)____m(x))
15479
15480 /*
15481 * Tell gcc we read from memory instead of writing: this is because
15482 @@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
15483 */
15484 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15485 asm volatile(ASM_STAC "\n" \
15486 - "1: mov"itype" %"rtype"1,%2\n" \
15487 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15488 "2: " ASM_CLAC "\n" \
15489 ".section .fixup,\"ax\"\n" \
15490 "3: mov %3,%0\n" \
15491 @@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
15492 ".previous\n" \
15493 _ASM_EXTABLE(1b, 3b) \
15494 : "=r"(err) \
15495 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15496 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15497
15498 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15499 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15500 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15501 "2:\n" \
15502 _ASM_EXTABLE_EX(1b, 2b) \
15503 : : ltype(x), "m" (__m(addr)))
15504 @@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
15505 * On error, the variable @x is set to zero.
15506 */
15507
15508 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15509 +#define __get_user(x, ptr) get_user((x), (ptr))
15510 +#else
15511 #define __get_user(x, ptr) \
15512 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15513 +#endif
15514
15515 /**
15516 * __put_user: - Write a simple value into user space, with less checking.
15517 @@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
15518 * Returns zero on success, or -EFAULT on error.
15519 */
15520
15521 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15522 +#define __put_user(x, ptr) put_user((x), (ptr))
15523 +#else
15524 #define __put_user(x, ptr) \
15525 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15526 +#endif
15527
15528 #define __get_user_unaligned __get_user
15529 #define __put_user_unaligned __put_user
15530 @@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
15531 #define get_user_ex(x, ptr) do { \
15532 unsigned long __gue_val; \
15533 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15534 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
15535 + (x) = (__typeof__(*(ptr)))__gue_val; \
15536 } while (0)
15537
15538 #define put_user_try uaccess_try
15539 @@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15540 extern __must_check long strlen_user(const char __user *str);
15541 extern __must_check long strnlen_user(const char __user *str, long n);
15542
15543 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15544 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15545 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15546 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15547
15548 /*
15549 * movsl can be slow when source and dest are not both 8-byte aligned
15550 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15551 index 7f760a9..04b1c65 100644
15552 --- a/arch/x86/include/asm/uaccess_32.h
15553 +++ b/arch/x86/include/asm/uaccess_32.h
15554 @@ -11,15 +11,15 @@
15555 #include <asm/page.h>
15556
15557 unsigned long __must_check __copy_to_user_ll
15558 - (void __user *to, const void *from, unsigned long n);
15559 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15560 unsigned long __must_check __copy_from_user_ll
15561 - (void *to, const void __user *from, unsigned long n);
15562 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15563 unsigned long __must_check __copy_from_user_ll_nozero
15564 - (void *to, const void __user *from, unsigned long n);
15565 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15566 unsigned long __must_check __copy_from_user_ll_nocache
15567 - (void *to, const void __user *from, unsigned long n);
15568 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15569 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15570 - (void *to, const void __user *from, unsigned long n);
15571 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15572
15573 /**
15574 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15575 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15576 static __always_inline unsigned long __must_check
15577 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15578 {
15579 + if ((long)n < 0)
15580 + return n;
15581 +
15582 + check_object_size(from, n, true);
15583 +
15584 if (__builtin_constant_p(n)) {
15585 unsigned long ret;
15586
15587 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15588 __copy_to_user(void __user *to, const void *from, unsigned long n)
15589 {
15590 might_fault();
15591 +
15592 return __copy_to_user_inatomic(to, from, n);
15593 }
15594
15595 static __always_inline unsigned long
15596 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15597 {
15598 + if ((long)n < 0)
15599 + return n;
15600 +
15601 /* Avoid zeroing the tail if the copy fails..
15602 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15603 * but as the zeroing behaviour is only significant when n is not
15604 @@ -137,6 +146,12 @@ static __always_inline unsigned long
15605 __copy_from_user(void *to, const void __user *from, unsigned long n)
15606 {
15607 might_fault();
15608 +
15609 + if ((long)n < 0)
15610 + return n;
15611 +
15612 + check_object_size(to, n, false);
15613 +
15614 if (__builtin_constant_p(n)) {
15615 unsigned long ret;
15616
15617 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15618 const void __user *from, unsigned long n)
15619 {
15620 might_fault();
15621 +
15622 + if ((long)n < 0)
15623 + return n;
15624 +
15625 if (__builtin_constant_p(n)) {
15626 unsigned long ret;
15627
15628 @@ -181,15 +200,19 @@ static __always_inline unsigned long
15629 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15630 unsigned long n)
15631 {
15632 - return __copy_from_user_ll_nocache_nozero(to, from, n);
15633 + if ((long)n < 0)
15634 + return n;
15635 +
15636 + return __copy_from_user_ll_nocache_nozero(to, from, n);
15637 }
15638
15639 -unsigned long __must_check copy_to_user(void __user *to,
15640 - const void *from, unsigned long n);
15641 -unsigned long __must_check _copy_from_user(void *to,
15642 - const void __user *from,
15643 - unsigned long n);
15644 -
15645 +extern void copy_to_user_overflow(void)
15646 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15647 + __compiletime_error("copy_to_user() buffer size is not provably correct")
15648 +#else
15649 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
15650 +#endif
15651 +;
15652
15653 extern void copy_from_user_overflow(void)
15654 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15655 @@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
15656 #endif
15657 ;
15658
15659 -static inline unsigned long __must_check copy_from_user(void *to,
15660 - const void __user *from,
15661 - unsigned long n)
15662 +/**
15663 + * copy_to_user: - Copy a block of data into user space.
15664 + * @to: Destination address, in user space.
15665 + * @from: Source address, in kernel space.
15666 + * @n: Number of bytes to copy.
15667 + *
15668 + * Context: User context only. This function may sleep.
15669 + *
15670 + * Copy data from kernel space to user space.
15671 + *
15672 + * Returns number of bytes that could not be copied.
15673 + * On success, this will be zero.
15674 + */
15675 +static inline unsigned long __must_check
15676 +copy_to_user(void __user *to, const void *from, unsigned long n)
15677 {
15678 - int sz = __compiletime_object_size(to);
15679 + size_t sz = __compiletime_object_size(from);
15680
15681 - if (likely(sz == -1 || sz >= n))
15682 - n = _copy_from_user(to, from, n);
15683 - else
15684 + if (unlikely(sz != (size_t)-1 && sz < n))
15685 + copy_to_user_overflow();
15686 + else if (access_ok(VERIFY_WRITE, to, n))
15687 + n = __copy_to_user(to, from, n);
15688 + return n;
15689 +}
15690 +
15691 +/**
15692 + * copy_from_user: - Copy a block of data from user space.
15693 + * @to: Destination address, in kernel space.
15694 + * @from: Source address, in user space.
15695 + * @n: Number of bytes to copy.
15696 + *
15697 + * Context: User context only. This function may sleep.
15698 + *
15699 + * Copy data from user space to kernel space.
15700 + *
15701 + * Returns number of bytes that could not be copied.
15702 + * On success, this will be zero.
15703 + *
15704 + * If some data could not be copied, this function will pad the copied
15705 + * data to the requested size using zero bytes.
15706 + */
15707 +static inline unsigned long __must_check
15708 +copy_from_user(void *to, const void __user *from, unsigned long n)
15709 +{
15710 + size_t sz = __compiletime_object_size(to);
15711 +
15712 + check_object_size(to, n, false);
15713 +
15714 + if (unlikely(sz != (size_t)-1 && sz < n))
15715 copy_from_user_overflow();
15716 -
15717 + else if (access_ok(VERIFY_READ, from, n))
15718 + n = __copy_from_user(to, from, n);
15719 + else if ((long)n > 0)
15720 + memset(to, 0, n);
15721 return n;
15722 }
15723
15724 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
15725 index 142810c..747941a 100644
15726 --- a/arch/x86/include/asm/uaccess_64.h
15727 +++ b/arch/x86/include/asm/uaccess_64.h
15728 @@ -10,6 +10,9 @@
15729 #include <asm/alternative.h>
15730 #include <asm/cpufeature.h>
15731 #include <asm/page.h>
15732 +#include <asm/pgtable.h>
15733 +
15734 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
15735
15736 /*
15737 * Copy To/From Userspace
15738 @@ -17,13 +20,13 @@
15739
15740 /* Handles exceptions in both to and from, but doesn't do access_ok */
15741 __must_check unsigned long
15742 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
15743 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
15744 __must_check unsigned long
15745 -copy_user_generic_string(void *to, const void *from, unsigned len);
15746 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
15747 __must_check unsigned long
15748 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
15749 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
15750
15751 -static __always_inline __must_check unsigned long
15752 +static __always_inline __must_check __size_overflow(3) unsigned long
15753 copy_user_generic(void *to, const void *from, unsigned len)
15754 {
15755 unsigned ret;
15756 @@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
15757 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
15758 "=d" (len)),
15759 "1" (to), "2" (from), "3" (len)
15760 - : "memory", "rcx", "r8", "r9", "r10", "r11");
15761 + : "memory", "rcx", "r8", "r9", "r11");
15762 return ret;
15763 }
15764
15765 +static __always_inline __must_check unsigned long
15766 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
15767 +static __always_inline __must_check unsigned long
15768 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
15769 __must_check unsigned long
15770 -_copy_to_user(void __user *to, const void *from, unsigned len);
15771 -__must_check unsigned long
15772 -_copy_from_user(void *to, const void __user *from, unsigned len);
15773 -__must_check unsigned long
15774 -copy_in_user(void __user *to, const void __user *from, unsigned len);
15775 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
15776 +
15777 +extern void copy_to_user_overflow(void)
15778 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15779 + __compiletime_error("copy_to_user() buffer size is not provably correct")
15780 +#else
15781 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
15782 +#endif
15783 +;
15784 +
15785 +extern void copy_from_user_overflow(void)
15786 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15787 + __compiletime_error("copy_from_user() buffer size is not provably correct")
15788 +#else
15789 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
15790 +#endif
15791 +;
15792
15793 static inline unsigned long __must_check copy_from_user(void *to,
15794 const void __user *from,
15795 unsigned long n)
15796 {
15797 - int sz = __compiletime_object_size(to);
15798 -
15799 might_fault();
15800 - if (likely(sz == -1 || sz >= n))
15801 - n = _copy_from_user(to, from, n);
15802 -#ifdef CONFIG_DEBUG_VM
15803 - else
15804 - WARN(1, "Buffer overflow detected!\n");
15805 -#endif
15806 +
15807 + check_object_size(to, n, false);
15808 +
15809 + if (access_ok(VERIFY_READ, from, n))
15810 + n = __copy_from_user(to, from, n);
15811 + else if (n < INT_MAX)
15812 + memset(to, 0, n);
15813 return n;
15814 }
15815
15816 static __always_inline __must_check
15817 -int copy_to_user(void __user *dst, const void *src, unsigned size)
15818 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
15819 {
15820 might_fault();
15821
15822 - return _copy_to_user(dst, src, size);
15823 + if (access_ok(VERIFY_WRITE, dst, size))
15824 + size = __copy_to_user(dst, src, size);
15825 + return size;
15826 }
15827
15828 static __always_inline __must_check
15829 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
15830 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
15831 {
15832 - int ret = 0;
15833 + size_t sz = __compiletime_object_size(dst);
15834 + unsigned ret = 0;
15835
15836 might_fault();
15837 +
15838 + if (size > INT_MAX)
15839 + return size;
15840 +
15841 + check_object_size(dst, size, false);
15842 +
15843 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15844 + if (!__access_ok(VERIFY_READ, src, size))
15845 + return size;
15846 +#endif
15847 +
15848 + if (unlikely(sz != (size_t)-1 && sz < size)) {
15849 + copy_from_user_overflow();
15850 + return size;
15851 + }
15852 +
15853 if (!__builtin_constant_p(size))
15854 - return copy_user_generic(dst, (__force void *)src, size);
15855 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15856 switch (size) {
15857 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
15858 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
15859 ret, "b", "b", "=q", 1);
15860 return ret;
15861 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
15862 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
15863 ret, "w", "w", "=r", 2);
15864 return ret;
15865 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
15866 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
15867 ret, "l", "k", "=r", 4);
15868 return ret;
15869 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
15870 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15871 ret, "q", "", "=r", 8);
15872 return ret;
15873 case 10:
15874 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15875 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15876 ret, "q", "", "=r", 10);
15877 if (unlikely(ret))
15878 return ret;
15879 __get_user_asm(*(u16 *)(8 + (char *)dst),
15880 - (u16 __user *)(8 + (char __user *)src),
15881 + (const u16 __user *)(8 + (const char __user *)src),
15882 ret, "w", "w", "=r", 2);
15883 return ret;
15884 case 16:
15885 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15886 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15887 ret, "q", "", "=r", 16);
15888 if (unlikely(ret))
15889 return ret;
15890 __get_user_asm(*(u64 *)(8 + (char *)dst),
15891 - (u64 __user *)(8 + (char __user *)src),
15892 + (const u64 __user *)(8 + (const char __user *)src),
15893 ret, "q", "", "=r", 8);
15894 return ret;
15895 default:
15896 - return copy_user_generic(dst, (__force void *)src, size);
15897 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15898 }
15899 }
15900
15901 static __always_inline __must_check
15902 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
15903 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
15904 {
15905 - int ret = 0;
15906 + size_t sz = __compiletime_object_size(src);
15907 + unsigned ret = 0;
15908
15909 might_fault();
15910 +
15911 + if (size > INT_MAX)
15912 + return size;
15913 +
15914 + check_object_size(src, size, true);
15915 +
15916 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15917 + if (!__access_ok(VERIFY_WRITE, dst, size))
15918 + return size;
15919 +#endif
15920 +
15921 + if (unlikely(sz != (size_t)-1 && sz < size)) {
15922 + copy_to_user_overflow();
15923 + return size;
15924 + }
15925 +
15926 if (!__builtin_constant_p(size))
15927 - return copy_user_generic((__force void *)dst, src, size);
15928 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15929 switch (size) {
15930 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
15931 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
15932 ret, "b", "b", "iq", 1);
15933 return ret;
15934 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
15935 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
15936 ret, "w", "w", "ir", 2);
15937 return ret;
15938 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
15939 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
15940 ret, "l", "k", "ir", 4);
15941 return ret;
15942 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
15943 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15944 ret, "q", "", "er", 8);
15945 return ret;
15946 case 10:
15947 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15948 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15949 ret, "q", "", "er", 10);
15950 if (unlikely(ret))
15951 return ret;
15952 asm("":::"memory");
15953 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
15954 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
15955 ret, "w", "w", "ir", 2);
15956 return ret;
15957 case 16:
15958 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15959 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15960 ret, "q", "", "er", 16);
15961 if (unlikely(ret))
15962 return ret;
15963 asm("":::"memory");
15964 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
15965 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
15966 ret, "q", "", "er", 8);
15967 return ret;
15968 default:
15969 - return copy_user_generic((__force void *)dst, src, size);
15970 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15971 }
15972 }
15973
15974 static __always_inline __must_check
15975 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15976 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
15977 {
15978 - int ret = 0;
15979 + unsigned ret = 0;
15980
15981 might_fault();
15982 +
15983 + if (size > INT_MAX)
15984 + return size;
15985 +
15986 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15987 + if (!__access_ok(VERIFY_READ, src, size))
15988 + return size;
15989 + if (!__access_ok(VERIFY_WRITE, dst, size))
15990 + return size;
15991 +#endif
15992 +
15993 if (!__builtin_constant_p(size))
15994 - return copy_user_generic((__force void *)dst,
15995 - (__force void *)src, size);
15996 + return copy_user_generic((__force_kernel void *)____m(dst),
15997 + (__force_kernel const void *)____m(src), size);
15998 switch (size) {
15999 case 1: {
16000 u8 tmp;
16001 - __get_user_asm(tmp, (u8 __user *)src,
16002 + __get_user_asm(tmp, (const u8 __user *)src,
16003 ret, "b", "b", "=q", 1);
16004 if (likely(!ret))
16005 __put_user_asm(tmp, (u8 __user *)dst,
16006 @@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16007 }
16008 case 2: {
16009 u16 tmp;
16010 - __get_user_asm(tmp, (u16 __user *)src,
16011 + __get_user_asm(tmp, (const u16 __user *)src,
16012 ret, "w", "w", "=r", 2);
16013 if (likely(!ret))
16014 __put_user_asm(tmp, (u16 __user *)dst,
16015 @@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16016
16017 case 4: {
16018 u32 tmp;
16019 - __get_user_asm(tmp, (u32 __user *)src,
16020 + __get_user_asm(tmp, (const u32 __user *)src,
16021 ret, "l", "k", "=r", 4);
16022 if (likely(!ret))
16023 __put_user_asm(tmp, (u32 __user *)dst,
16024 @@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16025 }
16026 case 8: {
16027 u64 tmp;
16028 - __get_user_asm(tmp, (u64 __user *)src,
16029 + __get_user_asm(tmp, (const u64 __user *)src,
16030 ret, "q", "", "=r", 8);
16031 if (likely(!ret))
16032 __put_user_asm(tmp, (u64 __user *)dst,
16033 @@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16034 return ret;
16035 }
16036 default:
16037 - return copy_user_generic((__force void *)dst,
16038 - (__force void *)src, size);
16039 + return copy_user_generic((__force_kernel void *)____m(dst),
16040 + (__force_kernel const void *)____m(src), size);
16041 }
16042 }
16043
16044 static __must_check __always_inline int
16045 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16046 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16047 {
16048 - return copy_user_generic(dst, (__force const void *)src, size);
16049 + if (size > INT_MAX)
16050 + return size;
16051 +
16052 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16053 + if (!__access_ok(VERIFY_READ, src, size))
16054 + return size;
16055 +#endif
16056 +
16057 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16058 }
16059
16060 -static __must_check __always_inline int
16061 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16062 +static __must_check __always_inline unsigned long
16063 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16064 {
16065 - return copy_user_generic((__force void *)dst, src, size);
16066 + if (size > INT_MAX)
16067 + return size;
16068 +
16069 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16070 + if (!__access_ok(VERIFY_WRITE, dst, size))
16071 + return size;
16072 +#endif
16073 +
16074 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16075 }
16076
16077 -extern long __copy_user_nocache(void *dst, const void __user *src,
16078 - unsigned size, int zerorest);
16079 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16080 + unsigned long size, int zerorest) __size_overflow(3);
16081
16082 -static inline int
16083 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16084 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16085 {
16086 might_sleep();
16087 +
16088 + if (size > INT_MAX)
16089 + return size;
16090 +
16091 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16092 + if (!__access_ok(VERIFY_READ, src, size))
16093 + return size;
16094 +#endif
16095 +
16096 return __copy_user_nocache(dst, src, size, 1);
16097 }
16098
16099 -static inline int
16100 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16101 - unsigned size)
16102 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16103 + unsigned long size)
16104 {
16105 + if (size > INT_MAX)
16106 + return size;
16107 +
16108 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16109 + if (!__access_ok(VERIFY_READ, src, size))
16110 + return size;
16111 +#endif
16112 +
16113 return __copy_user_nocache(dst, src, size, 0);
16114 }
16115
16116 -unsigned long
16117 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16118 +extern unsigned long
16119 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16120
16121 #endif /* _ASM_X86_UACCESS_64_H */
16122 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16123 index 5b238981..77fdd78 100644
16124 --- a/arch/x86/include/asm/word-at-a-time.h
16125 +++ b/arch/x86/include/asm/word-at-a-time.h
16126 @@ -11,7 +11,7 @@
16127 * and shift, for example.
16128 */
16129 struct word_at_a_time {
16130 - const unsigned long one_bits, high_bits;
16131 + unsigned long one_bits, high_bits;
16132 };
16133
16134 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16135 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16136 index 5769349..a3d3e2a 100644
16137 --- a/arch/x86/include/asm/x86_init.h
16138 +++ b/arch/x86/include/asm/x86_init.h
16139 @@ -141,7 +141,7 @@ struct x86_init_ops {
16140 struct x86_init_timers timers;
16141 struct x86_init_iommu iommu;
16142 struct x86_init_pci pci;
16143 -};
16144 +} __no_const;
16145
16146 /**
16147 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16148 @@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
16149 void (*setup_percpu_clockev)(void);
16150 void (*early_percpu_clock_init)(void);
16151 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16152 -};
16153 +} __no_const;
16154
16155 /**
16156 * struct x86_platform_ops - platform specific runtime functions
16157 @@ -178,7 +178,7 @@ struct x86_platform_ops {
16158 void (*save_sched_clock_state)(void);
16159 void (*restore_sched_clock_state)(void);
16160 void (*apic_post_init)(void);
16161 -};
16162 +} __no_const;
16163
16164 struct pci_dev;
16165
16166 @@ -187,14 +187,14 @@ struct x86_msi_ops {
16167 void (*teardown_msi_irq)(unsigned int irq);
16168 void (*teardown_msi_irqs)(struct pci_dev *dev);
16169 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16170 -};
16171 +} __no_const;
16172
16173 struct x86_io_apic_ops {
16174 void (*init) (void);
16175 unsigned int (*read) (unsigned int apic, unsigned int reg);
16176 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
16177 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
16178 -};
16179 +} __no_const;
16180
16181 extern struct x86_init_ops x86_init;
16182 extern struct x86_cpuinit_ops x86_cpuinit;
16183 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16184 index 0415cda..b43d877 100644
16185 --- a/arch/x86/include/asm/xsave.h
16186 +++ b/arch/x86/include/asm/xsave.h
16187 @@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16188 return -EFAULT;
16189
16190 __asm__ __volatile__(ASM_STAC "\n"
16191 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16192 + "1:"
16193 + __copyuser_seg
16194 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16195 "2: " ASM_CLAC "\n"
16196 ".section .fixup,\"ax\"\n"
16197 "3: movl $-1,%[err]\n"
16198 @@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16199 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16200 {
16201 int err;
16202 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16203 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16204 u32 lmask = mask;
16205 u32 hmask = mask >> 32;
16206
16207 __asm__ __volatile__(ASM_STAC "\n"
16208 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16209 + "1:"
16210 + __copyuser_seg
16211 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16212 "2: " ASM_CLAC "\n"
16213 ".section .fixup,\"ax\"\n"
16214 "3: movl $-1,%[err]\n"
16215 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16216 index bbae024..e1528f9 100644
16217 --- a/arch/x86/include/uapi/asm/e820.h
16218 +++ b/arch/x86/include/uapi/asm/e820.h
16219 @@ -63,7 +63,7 @@ struct e820map {
16220 #define ISA_START_ADDRESS 0xa0000
16221 #define ISA_END_ADDRESS 0x100000
16222
16223 -#define BIOS_BEGIN 0x000a0000
16224 +#define BIOS_BEGIN 0x000c0000
16225 #define BIOS_END 0x00100000
16226
16227 #define BIOS_ROM_BASE 0xffe00000
16228 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16229 index 34e923a..0c6bb6e 100644
16230 --- a/arch/x86/kernel/Makefile
16231 +++ b/arch/x86/kernel/Makefile
16232 @@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16233 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16234 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16235 obj-y += probe_roms.o
16236 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16237 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16238 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16239 obj-y += syscall_$(BITS).o
16240 obj-$(CONFIG_X86_64) += vsyscall_64.o
16241 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16242 index bacf4b0..4ede72e 100644
16243 --- a/arch/x86/kernel/acpi/boot.c
16244 +++ b/arch/x86/kernel/acpi/boot.c
16245 @@ -1358,7 +1358,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16246 * If your system is blacklisted here, but you find that acpi=force
16247 * works for you, please contact linux-acpi@vger.kernel.org
16248 */
16249 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
16250 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16251 /*
16252 * Boxes that need ACPI disabled
16253 */
16254 @@ -1433,7 +1433,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16255 };
16256
16257 /* second table for DMI checks that should run after early-quirks */
16258 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16259 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16260 /*
16261 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16262 * which includes some code which overrides all temperature
16263 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16264 index d5e0d71..6533e08 100644
16265 --- a/arch/x86/kernel/acpi/sleep.c
16266 +++ b/arch/x86/kernel/acpi/sleep.c
16267 @@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16268 #else /* CONFIG_64BIT */
16269 #ifdef CONFIG_SMP
16270 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16271 +
16272 + pax_open_kernel();
16273 early_gdt_descr.address =
16274 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16275 + pax_close_kernel();
16276 +
16277 initial_gs = per_cpu_offset(smp_processor_id());
16278 #endif
16279 initial_code = (unsigned long)wakeup_long64;
16280 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16281 index 13ab720..95d5442 100644
16282 --- a/arch/x86/kernel/acpi/wakeup_32.S
16283 +++ b/arch/x86/kernel/acpi/wakeup_32.S
16284 @@ -30,13 +30,11 @@ wakeup_pmode_return:
16285 # and restore the stack ... but you need gdt for this to work
16286 movl saved_context_esp, %esp
16287
16288 - movl %cs:saved_magic, %eax
16289 - cmpl $0x12345678, %eax
16290 + cmpl $0x12345678, saved_magic
16291 jne bogus_magic
16292
16293 # jump to place where we left off
16294 - movl saved_eip, %eax
16295 - jmp *%eax
16296 + jmp *(saved_eip)
16297
16298 bogus_magic:
16299 jmp bogus_magic
16300 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16301 index ef5ccca..bd83949 100644
16302 --- a/arch/x86/kernel/alternative.c
16303 +++ b/arch/x86/kernel/alternative.c
16304 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16305 */
16306 for (a = start; a < end; a++) {
16307 instr = (u8 *)&a->instr_offset + a->instr_offset;
16308 +
16309 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16310 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16311 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16312 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16313 +#endif
16314 +
16315 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16316 BUG_ON(a->replacementlen > a->instrlen);
16317 BUG_ON(a->instrlen > sizeof(insnbuf));
16318 @@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16319 for (poff = start; poff < end; poff++) {
16320 u8 *ptr = (u8 *)poff + *poff;
16321
16322 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16323 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16324 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16325 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16326 +#endif
16327 +
16328 if (!*poff || ptr < text || ptr >= text_end)
16329 continue;
16330 /* turn DS segment override prefix into lock prefix */
16331 - if (*ptr == 0x3e)
16332 + if (*ktla_ktva(ptr) == 0x3e)
16333 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16334 }
16335 mutex_unlock(&text_mutex);
16336 @@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16337 for (poff = start; poff < end; poff++) {
16338 u8 *ptr = (u8 *)poff + *poff;
16339
16340 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16341 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16342 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16343 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16344 +#endif
16345 +
16346 if (!*poff || ptr < text || ptr >= text_end)
16347 continue;
16348 /* turn lock prefix into DS segment override prefix */
16349 - if (*ptr == 0xf0)
16350 + if (*ktla_ktva(ptr) == 0xf0)
16351 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16352 }
16353 mutex_unlock(&text_mutex);
16354 @@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16355
16356 BUG_ON(p->len > MAX_PATCH_LEN);
16357 /* prep the buffer with the original instructions */
16358 - memcpy(insnbuf, p->instr, p->len);
16359 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16360 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16361 (unsigned long)p->instr, p->len);
16362
16363 @@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16364 if (!uniproc_patched || num_possible_cpus() == 1)
16365 free_init_pages("SMP alternatives",
16366 (unsigned long)__smp_locks,
16367 - (unsigned long)__smp_locks_end);
16368 + PAGE_ALIGN((unsigned long)__smp_locks_end));
16369 #endif
16370
16371 apply_paravirt(__parainstructions, __parainstructions_end);
16372 @@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16373 * instructions. And on the local CPU you need to be protected again NMI or MCE
16374 * handlers seeing an inconsistent instruction while you patch.
16375 */
16376 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
16377 +void *__kprobes text_poke_early(void *addr, const void *opcode,
16378 size_t len)
16379 {
16380 unsigned long flags;
16381 local_irq_save(flags);
16382 - memcpy(addr, opcode, len);
16383 +
16384 + pax_open_kernel();
16385 + memcpy(ktla_ktva(addr), opcode, len);
16386 sync_core();
16387 + pax_close_kernel();
16388 +
16389 local_irq_restore(flags);
16390 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16391 that causes hangs on some VIA CPUs. */
16392 @@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16393 */
16394 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16395 {
16396 - unsigned long flags;
16397 - char *vaddr;
16398 + unsigned char *vaddr = ktla_ktva(addr);
16399 struct page *pages[2];
16400 - int i;
16401 + size_t i;
16402
16403 if (!core_kernel_text((unsigned long)addr)) {
16404 - pages[0] = vmalloc_to_page(addr);
16405 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16406 + pages[0] = vmalloc_to_page(vaddr);
16407 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16408 } else {
16409 - pages[0] = virt_to_page(addr);
16410 + pages[0] = virt_to_page(vaddr);
16411 WARN_ON(!PageReserved(pages[0]));
16412 - pages[1] = virt_to_page(addr + PAGE_SIZE);
16413 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16414 }
16415 BUG_ON(!pages[0]);
16416 - local_irq_save(flags);
16417 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16418 - if (pages[1])
16419 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16420 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16421 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16422 - clear_fixmap(FIX_TEXT_POKE0);
16423 - if (pages[1])
16424 - clear_fixmap(FIX_TEXT_POKE1);
16425 - local_flush_tlb();
16426 - sync_core();
16427 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
16428 - that causes hangs on some VIA CPUs. */
16429 + text_poke_early(addr, opcode, len);
16430 for (i = 0; i < len; i++)
16431 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16432 - local_irq_restore(flags);
16433 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16434 return addr;
16435 }
16436
16437 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16438 index cbf5121..812b537 100644
16439 --- a/arch/x86/kernel/apic/apic.c
16440 +++ b/arch/x86/kernel/apic/apic.c
16441 @@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16442 /*
16443 * Debug level, exported for io_apic.c
16444 */
16445 -unsigned int apic_verbosity;
16446 +int apic_verbosity;
16447
16448 int pic_mode;
16449
16450 @@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16451 apic_write(APIC_ESR, 0);
16452 v1 = apic_read(APIC_ESR);
16453 ack_APIC_irq();
16454 - atomic_inc(&irq_err_count);
16455 + atomic_inc_unchecked(&irq_err_count);
16456
16457 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16458 smp_processor_id(), v0 , v1);
16459 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16460 index 00c77cf..2dc6a2d 100644
16461 --- a/arch/x86/kernel/apic/apic_flat_64.c
16462 +++ b/arch/x86/kernel/apic/apic_flat_64.c
16463 @@ -157,7 +157,7 @@ static int flat_probe(void)
16464 return 1;
16465 }
16466
16467 -static struct apic apic_flat = {
16468 +static struct apic apic_flat __read_only = {
16469 .name = "flat",
16470 .probe = flat_probe,
16471 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16472 @@ -271,7 +271,7 @@ static int physflat_probe(void)
16473 return 0;
16474 }
16475
16476 -static struct apic apic_physflat = {
16477 +static struct apic apic_physflat __read_only = {
16478
16479 .name = "physical flat",
16480 .probe = physflat_probe,
16481 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16482 index e145f28..2752888 100644
16483 --- a/arch/x86/kernel/apic/apic_noop.c
16484 +++ b/arch/x86/kernel/apic/apic_noop.c
16485 @@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16486 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16487 }
16488
16489 -struct apic apic_noop = {
16490 +struct apic apic_noop __read_only = {
16491 .name = "noop",
16492 .probe = noop_probe,
16493 .acpi_madt_oem_check = NULL,
16494 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16495 index d50e364..543bee3 100644
16496 --- a/arch/x86/kernel/apic/bigsmp_32.c
16497 +++ b/arch/x86/kernel/apic/bigsmp_32.c
16498 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16499 return dmi_bigsmp;
16500 }
16501
16502 -static struct apic apic_bigsmp = {
16503 +static struct apic apic_bigsmp __read_only = {
16504
16505 .name = "bigsmp",
16506 .probe = probe_bigsmp,
16507 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16508 index 0874799..a7a7892 100644
16509 --- a/arch/x86/kernel/apic/es7000_32.c
16510 +++ b/arch/x86/kernel/apic/es7000_32.c
16511 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16512 return ret && es7000_apic_is_cluster();
16513 }
16514
16515 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16516 -static struct apic __refdata apic_es7000_cluster = {
16517 +static struct apic apic_es7000_cluster __read_only = {
16518
16519 .name = "es7000",
16520 .probe = probe_es7000,
16521 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16522 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16523 };
16524
16525 -static struct apic __refdata apic_es7000 = {
16526 +static struct apic apic_es7000 __read_only = {
16527
16528 .name = "es7000",
16529 .probe = probe_es7000,
16530 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16531 index b739d39..aebc14c 100644
16532 --- a/arch/x86/kernel/apic/io_apic.c
16533 +++ b/arch/x86/kernel/apic/io_apic.c
16534 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16535 }
16536 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16537
16538 -void lock_vector_lock(void)
16539 +void lock_vector_lock(void) __acquires(vector_lock)
16540 {
16541 /* Used to the online set of cpus does not change
16542 * during assign_irq_vector.
16543 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
16544 raw_spin_lock(&vector_lock);
16545 }
16546
16547 -void unlock_vector_lock(void)
16548 +void unlock_vector_lock(void) __releases(vector_lock)
16549 {
16550 raw_spin_unlock(&vector_lock);
16551 }
16552 @@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
16553 ack_APIC_irq();
16554 }
16555
16556 -atomic_t irq_mis_count;
16557 +atomic_unchecked_t irq_mis_count;
16558
16559 #ifdef CONFIG_GENERIC_PENDING_IRQ
16560 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16561 @@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
16562 * at the cpu.
16563 */
16564 if (!(v & (1 << (i & 0x1f)))) {
16565 - atomic_inc(&irq_mis_count);
16566 + atomic_inc_unchecked(&irq_mis_count);
16567
16568 eoi_ioapic_irq(irq, cfg);
16569 }
16570 @@ -2567,11 +2567,13 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
16571
16572 static void irq_remap_modify_chip_defaults(struct irq_chip *chip)
16573 {
16574 - chip->irq_print_chip = ir_print_prefix;
16575 - chip->irq_ack = ir_ack_apic_edge;
16576 - chip->irq_eoi = ir_ack_apic_level;
16577 + pax_open_kernel();
16578 + *(void **)&chip->irq_print_chip = ir_print_prefix;
16579 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
16580 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
16581
16582 - chip->irq_set_affinity = set_remapped_irq_affinity;
16583 + *(void **)&chip->irq_set_affinity = set_remapped_irq_affinity;
16584 + pax_close_kernel();
16585 }
16586 #endif /* CONFIG_IRQ_REMAP */
16587
16588 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16589 index d661ee9..791fd33 100644
16590 --- a/arch/x86/kernel/apic/numaq_32.c
16591 +++ b/arch/x86/kernel/apic/numaq_32.c
16592 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16593 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16594 }
16595
16596 -/* Use __refdata to keep false positive warning calm. */
16597 -static struct apic __refdata apic_numaq = {
16598 +static struct apic apic_numaq __read_only = {
16599
16600 .name = "NUMAQ",
16601 .probe = probe_numaq,
16602 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16603 index eb35ef9..f184a21 100644
16604 --- a/arch/x86/kernel/apic/probe_32.c
16605 +++ b/arch/x86/kernel/apic/probe_32.c
16606 @@ -72,7 +72,7 @@ static int probe_default(void)
16607 return 1;
16608 }
16609
16610 -static struct apic apic_default = {
16611 +static struct apic apic_default __read_only = {
16612
16613 .name = "default",
16614 .probe = probe_default,
16615 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16616 index 77c95c0..434f8a4 100644
16617 --- a/arch/x86/kernel/apic/summit_32.c
16618 +++ b/arch/x86/kernel/apic/summit_32.c
16619 @@ -486,7 +486,7 @@ void setup_summit(void)
16620 }
16621 #endif
16622
16623 -static struct apic apic_summit = {
16624 +static struct apic apic_summit __read_only = {
16625
16626 .name = "summit",
16627 .probe = probe_summit,
16628 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16629 index c88baa4..757aee1 100644
16630 --- a/arch/x86/kernel/apic/x2apic_cluster.c
16631 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
16632 @@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16633 return notifier_from_errno(err);
16634 }
16635
16636 -static struct notifier_block __refdata x2apic_cpu_notifier = {
16637 +static struct notifier_block x2apic_cpu_notifier = {
16638 .notifier_call = update_clusterinfo,
16639 };
16640
16641 @@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16642 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16643 }
16644
16645 -static struct apic apic_x2apic_cluster = {
16646 +static struct apic apic_x2apic_cluster __read_only = {
16647
16648 .name = "cluster x2apic",
16649 .probe = x2apic_cluster_probe,
16650 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16651 index 562a76d..a003c0f 100644
16652 --- a/arch/x86/kernel/apic/x2apic_phys.c
16653 +++ b/arch/x86/kernel/apic/x2apic_phys.c
16654 @@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16655 return apic == &apic_x2apic_phys;
16656 }
16657
16658 -static struct apic apic_x2apic_phys = {
16659 +static struct apic apic_x2apic_phys __read_only = {
16660
16661 .name = "physical x2apic",
16662 .probe = x2apic_phys_probe,
16663 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
16664 index 8cfade9..b9d04fc 100644
16665 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
16666 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
16667 @@ -333,7 +333,7 @@ static int uv_probe(void)
16668 return apic == &apic_x2apic_uv_x;
16669 }
16670
16671 -static struct apic __refdata apic_x2apic_uv_x = {
16672 +static struct apic apic_x2apic_uv_x __read_only = {
16673
16674 .name = "UV large system",
16675 .probe = uv_probe,
16676 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
16677 index d65464e..1035d31 100644
16678 --- a/arch/x86/kernel/apm_32.c
16679 +++ b/arch/x86/kernel/apm_32.c
16680 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
16681 * This is for buggy BIOS's that refer to (real mode) segment 0x40
16682 * even though they are called in protected mode.
16683 */
16684 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
16685 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
16686 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
16687
16688 static const char driver_version[] = "1.16ac"; /* no spaces */
16689 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
16690 BUG_ON(cpu != 0);
16691 gdt = get_cpu_gdt_table(cpu);
16692 save_desc_40 = gdt[0x40 / 8];
16693 +
16694 + pax_open_kernel();
16695 gdt[0x40 / 8] = bad_bios_desc;
16696 + pax_close_kernel();
16697
16698 apm_irq_save(flags);
16699 APM_DO_SAVE_SEGS;
16700 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
16701 &call->esi);
16702 APM_DO_RESTORE_SEGS;
16703 apm_irq_restore(flags);
16704 +
16705 + pax_open_kernel();
16706 gdt[0x40 / 8] = save_desc_40;
16707 + pax_close_kernel();
16708 +
16709 put_cpu();
16710
16711 return call->eax & 0xff;
16712 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
16713 BUG_ON(cpu != 0);
16714 gdt = get_cpu_gdt_table(cpu);
16715 save_desc_40 = gdt[0x40 / 8];
16716 +
16717 + pax_open_kernel();
16718 gdt[0x40 / 8] = bad_bios_desc;
16719 + pax_close_kernel();
16720
16721 apm_irq_save(flags);
16722 APM_DO_SAVE_SEGS;
16723 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
16724 &call->eax);
16725 APM_DO_RESTORE_SEGS;
16726 apm_irq_restore(flags);
16727 +
16728 + pax_open_kernel();
16729 gdt[0x40 / 8] = save_desc_40;
16730 + pax_close_kernel();
16731 +
16732 put_cpu();
16733 return error;
16734 }
16735 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
16736 * code to that CPU.
16737 */
16738 gdt = get_cpu_gdt_table(0);
16739 +
16740 + pax_open_kernel();
16741 set_desc_base(&gdt[APM_CS >> 3],
16742 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
16743 set_desc_base(&gdt[APM_CS_16 >> 3],
16744 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
16745 set_desc_base(&gdt[APM_DS >> 3],
16746 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
16747 + pax_close_kernel();
16748
16749 proc_create("apm", 0, NULL, &apm_file_ops);
16750
16751 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
16752 index 2861082..6d4718e 100644
16753 --- a/arch/x86/kernel/asm-offsets.c
16754 +++ b/arch/x86/kernel/asm-offsets.c
16755 @@ -33,6 +33,8 @@ void common(void) {
16756 OFFSET(TI_status, thread_info, status);
16757 OFFSET(TI_addr_limit, thread_info, addr_limit);
16758 OFFSET(TI_preempt_count, thread_info, preempt_count);
16759 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
16760 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
16761
16762 BLANK();
16763 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
16764 @@ -53,8 +55,26 @@ void common(void) {
16765 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
16766 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
16767 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
16768 +
16769 +#ifdef CONFIG_PAX_KERNEXEC
16770 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
16771 #endif
16772
16773 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16774 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
16775 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
16776 +#ifdef CONFIG_X86_64
16777 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
16778 +#endif
16779 +#endif
16780 +
16781 +#endif
16782 +
16783 + BLANK();
16784 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
16785 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
16786 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
16787 +
16788 #ifdef CONFIG_XEN
16789 BLANK();
16790 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
16791 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
16792 index 1b4754f..fbb4227 100644
16793 --- a/arch/x86/kernel/asm-offsets_64.c
16794 +++ b/arch/x86/kernel/asm-offsets_64.c
16795 @@ -76,6 +76,7 @@ int main(void)
16796 BLANK();
16797 #undef ENTRY
16798
16799 + DEFINE(TSS_size, sizeof(struct tss_struct));
16800 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
16801 BLANK();
16802
16803 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
16804 index a0e067d..9c7db16 100644
16805 --- a/arch/x86/kernel/cpu/Makefile
16806 +++ b/arch/x86/kernel/cpu/Makefile
16807 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
16808 CFLAGS_REMOVE_perf_event.o = -pg
16809 endif
16810
16811 -# Make sure load_percpu_segment has no stackprotector
16812 -nostackp := $(call cc-option, -fno-stack-protector)
16813 -CFLAGS_common.o := $(nostackp)
16814 -
16815 obj-y := intel_cacheinfo.o scattered.o topology.o
16816 obj-y += proc.o capflags.o powerflags.o common.o
16817 obj-y += vmware.o hypervisor.o mshyperv.o
16818 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
16819 index 15239ff..e23e04e 100644
16820 --- a/arch/x86/kernel/cpu/amd.c
16821 +++ b/arch/x86/kernel/cpu/amd.c
16822 @@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
16823 unsigned int size)
16824 {
16825 /* AMD errata T13 (order #21922) */
16826 - if ((c->x86 == 6)) {
16827 + if (c->x86 == 6) {
16828 /* Duron Rev A0 */
16829 if (c->x86_model == 3 && c->x86_mask == 0)
16830 size = 64;
16831 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
16832 index 9c3ab43..51e6366 100644
16833 --- a/arch/x86/kernel/cpu/common.c
16834 +++ b/arch/x86/kernel/cpu/common.c
16835 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
16836
16837 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
16838
16839 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
16840 -#ifdef CONFIG_X86_64
16841 - /*
16842 - * We need valid kernel segments for data and code in long mode too
16843 - * IRET will check the segment types kkeil 2000/10/28
16844 - * Also sysret mandates a special GDT layout
16845 - *
16846 - * TLS descriptors are currently at a different place compared to i386.
16847 - * Hopefully nobody expects them at a fixed place (Wine?)
16848 - */
16849 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
16850 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
16851 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
16852 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
16853 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
16854 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
16855 -#else
16856 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
16857 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16858 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
16859 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
16860 - /*
16861 - * Segments used for calling PnP BIOS have byte granularity.
16862 - * They code segments and data segments have fixed 64k limits,
16863 - * the transfer segment sizes are set at run time.
16864 - */
16865 - /* 32-bit code */
16866 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16867 - /* 16-bit code */
16868 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16869 - /* 16-bit data */
16870 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
16871 - /* 16-bit data */
16872 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
16873 - /* 16-bit data */
16874 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
16875 - /*
16876 - * The APM segments have byte granularity and their bases
16877 - * are set at run time. All have 64k limits.
16878 - */
16879 - /* 32-bit code */
16880 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16881 - /* 16-bit code */
16882 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16883 - /* data */
16884 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
16885 -
16886 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16887 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16888 - GDT_STACK_CANARY_INIT
16889 -#endif
16890 -} };
16891 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
16892 -
16893 static int __init x86_xsave_setup(char *s)
16894 {
16895 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
16896 @@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
16897 {
16898 struct desc_ptr gdt_descr;
16899
16900 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
16901 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16902 gdt_descr.size = GDT_SIZE - 1;
16903 load_gdt(&gdt_descr);
16904 /* Reload the per-cpu base */
16905 @@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
16906 /* Filter out anything that depends on CPUID levels we don't have */
16907 filter_cpuid_features(c, true);
16908
16909 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16910 + setup_clear_cpu_cap(X86_FEATURE_SEP);
16911 +#endif
16912 +
16913 /* If the model name is still unset, do table lookup. */
16914 if (!c->x86_model_id[0]) {
16915 const char *p;
16916 @@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
16917 }
16918 __setup("clearcpuid=", setup_disablecpuid);
16919
16920 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
16921 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
16922 +
16923 #ifdef CONFIG_X86_64
16924 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
16925 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
16926 - (unsigned long) nmi_idt_table };
16927 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
16928
16929 DEFINE_PER_CPU_FIRST(union irq_stack_union,
16930 irq_stack_union) __aligned(PAGE_SIZE);
16931 @@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
16932 EXPORT_PER_CPU_SYMBOL(current_task);
16933
16934 DEFINE_PER_CPU(unsigned long, kernel_stack) =
16935 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
16936 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
16937 EXPORT_PER_CPU_SYMBOL(kernel_stack);
16938
16939 DEFINE_PER_CPU(char *, irq_stack_ptr) =
16940 @@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
16941 int i;
16942
16943 cpu = stack_smp_processor_id();
16944 - t = &per_cpu(init_tss, cpu);
16945 + t = init_tss + cpu;
16946 oist = &per_cpu(orig_ist, cpu);
16947
16948 #ifdef CONFIG_NUMA
16949 @@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
16950 switch_to_new_gdt(cpu);
16951 loadsegment(fs, 0);
16952
16953 - load_idt((const struct desc_ptr *)&idt_descr);
16954 + load_idt(&idt_descr);
16955
16956 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
16957 syscall_init();
16958 @@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
16959 wrmsrl(MSR_KERNEL_GS_BASE, 0);
16960 barrier();
16961
16962 - x86_configure_nx();
16963 enable_x2apic();
16964
16965 /*
16966 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
16967 {
16968 int cpu = smp_processor_id();
16969 struct task_struct *curr = current;
16970 - struct tss_struct *t = &per_cpu(init_tss, cpu);
16971 + struct tss_struct *t = init_tss + cpu;
16972 struct thread_struct *thread = &curr->thread;
16973
16974 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
16975 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
16976 index fcaabd0..7b55a26 100644
16977 --- a/arch/x86/kernel/cpu/intel.c
16978 +++ b/arch/x86/kernel/cpu/intel.c
16979 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
16980 * Update the IDT descriptor and reload the IDT so that
16981 * it uses the read-only mapped virtual address.
16982 */
16983 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
16984 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
16985 load_idt(&idt_descr);
16986 }
16987 #endif
16988 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
16989 index 84c1309..39b7224 100644
16990 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
16991 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
16992 @@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
16993 };
16994
16995 #ifdef CONFIG_AMD_NB
16996 +static struct attribute *default_attrs_amd_nb[] = {
16997 + &type.attr,
16998 + &level.attr,
16999 + &coherency_line_size.attr,
17000 + &physical_line_partition.attr,
17001 + &ways_of_associativity.attr,
17002 + &number_of_sets.attr,
17003 + &size.attr,
17004 + &shared_cpu_map.attr,
17005 + &shared_cpu_list.attr,
17006 + NULL,
17007 + NULL,
17008 + NULL,
17009 + NULL
17010 +};
17011 +
17012 static struct attribute ** __cpuinit amd_l3_attrs(void)
17013 {
17014 static struct attribute **attrs;
17015 @@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17016
17017 n = ARRAY_SIZE(default_attrs);
17018
17019 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17020 - n += 2;
17021 -
17022 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17023 - n += 1;
17024 -
17025 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17026 - if (attrs == NULL)
17027 - return attrs = default_attrs;
17028 -
17029 - for (n = 0; default_attrs[n]; n++)
17030 - attrs[n] = default_attrs[n];
17031 + attrs = default_attrs_amd_nb;
17032
17033 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17034 attrs[n++] = &cache_disable_0.attr;
17035 @@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17036 .default_attrs = default_attrs,
17037 };
17038
17039 +#ifdef CONFIG_AMD_NB
17040 +static struct kobj_type ktype_cache_amd_nb = {
17041 + .sysfs_ops = &sysfs_ops,
17042 + .default_attrs = default_attrs_amd_nb,
17043 +};
17044 +#endif
17045 +
17046 static struct kobj_type ktype_percpu_entry = {
17047 .sysfs_ops = &sysfs_ops,
17048 };
17049 @@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17050 return retval;
17051 }
17052
17053 +#ifdef CONFIG_AMD_NB
17054 + amd_l3_attrs();
17055 +#endif
17056 +
17057 for (i = 0; i < num_cache_leaves; i++) {
17058 + struct kobj_type *ktype;
17059 +
17060 this_object = INDEX_KOBJECT_PTR(cpu, i);
17061 this_object->cpu = cpu;
17062 this_object->index = i;
17063
17064 this_leaf = CPUID4_INFO_IDX(cpu, i);
17065
17066 - ktype_cache.default_attrs = default_attrs;
17067 + ktype = &ktype_cache;
17068 #ifdef CONFIG_AMD_NB
17069 if (this_leaf->base.nb)
17070 - ktype_cache.default_attrs = amd_l3_attrs();
17071 + ktype = &ktype_cache_amd_nb;
17072 #endif
17073 retval = kobject_init_and_add(&(this_object->kobj),
17074 - &ktype_cache,
17075 + ktype,
17076 per_cpu(ici_cache_kobject, cpu),
17077 "index%1lu", i);
17078 if (unlikely(retval)) {
17079 @@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17080 return NOTIFY_OK;
17081 }
17082
17083 -static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17084 +static struct notifier_block cacheinfo_cpu_notifier = {
17085 .notifier_call = cacheinfo_cpu_callback,
17086 };
17087
17088 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17089 index 80dbda8..be16652 100644
17090 --- a/arch/x86/kernel/cpu/mcheck/mce.c
17091 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
17092 @@ -45,6 +45,7 @@
17093 #include <asm/processor.h>
17094 #include <asm/mce.h>
17095 #include <asm/msr.h>
17096 +#include <asm/local.h>
17097
17098 #include "mce-internal.h"
17099
17100 @@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17101 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17102 m->cs, m->ip);
17103
17104 - if (m->cs == __KERNEL_CS)
17105 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17106 print_symbol("{%s}", m->ip);
17107 pr_cont("\n");
17108 }
17109 @@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17110
17111 #define PANIC_TIMEOUT 5 /* 5 seconds */
17112
17113 -static atomic_t mce_paniced;
17114 +static atomic_unchecked_t mce_paniced;
17115
17116 static int fake_panic;
17117 -static atomic_t mce_fake_paniced;
17118 +static atomic_unchecked_t mce_fake_paniced;
17119
17120 /* Panic in progress. Enable interrupts and wait for final IPI */
17121 static void wait_for_panic(void)
17122 @@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17123 /*
17124 * Make sure only one CPU runs in machine check panic
17125 */
17126 - if (atomic_inc_return(&mce_paniced) > 1)
17127 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17128 wait_for_panic();
17129 barrier();
17130
17131 @@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17132 console_verbose();
17133 } else {
17134 /* Don't log too much for fake panic */
17135 - if (atomic_inc_return(&mce_fake_paniced) > 1)
17136 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17137 return;
17138 }
17139 /* First print corrected ones that are still unlogged */
17140 @@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
17141 * might have been modified by someone else.
17142 */
17143 rmb();
17144 - if (atomic_read(&mce_paniced))
17145 + if (atomic_read_unchecked(&mce_paniced))
17146 wait_for_panic();
17147 if (!mca_cfg.monarch_timeout)
17148 goto out;
17149 @@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17150 }
17151
17152 /* Call the installed machine check handler for this CPU setup. */
17153 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
17154 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17155 unexpected_machine_check;
17156
17157 /*
17158 @@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17159 return;
17160 }
17161
17162 + pax_open_kernel();
17163 machine_check_vector = do_machine_check;
17164 + pax_close_kernel();
17165
17166 __mcheck_cpu_init_generic();
17167 __mcheck_cpu_init_vendor(c);
17168 @@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17169 */
17170
17171 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17172 -static int mce_chrdev_open_count; /* #times opened */
17173 +static local_t mce_chrdev_open_count; /* #times opened */
17174 static int mce_chrdev_open_exclu; /* already open exclusive? */
17175
17176 static int mce_chrdev_open(struct inode *inode, struct file *file)
17177 @@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17178 spin_lock(&mce_chrdev_state_lock);
17179
17180 if (mce_chrdev_open_exclu ||
17181 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17182 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17183 spin_unlock(&mce_chrdev_state_lock);
17184
17185 return -EBUSY;
17186 @@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17187
17188 if (file->f_flags & O_EXCL)
17189 mce_chrdev_open_exclu = 1;
17190 - mce_chrdev_open_count++;
17191 + local_inc(&mce_chrdev_open_count);
17192
17193 spin_unlock(&mce_chrdev_state_lock);
17194
17195 @@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17196 {
17197 spin_lock(&mce_chrdev_state_lock);
17198
17199 - mce_chrdev_open_count--;
17200 + local_dec(&mce_chrdev_open_count);
17201 mce_chrdev_open_exclu = 0;
17202
17203 spin_unlock(&mce_chrdev_state_lock);
17204 @@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17205 return NOTIFY_OK;
17206 }
17207
17208 -static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17209 +static struct notifier_block mce_cpu_notifier = {
17210 .notifier_call = mce_cpu_callback,
17211 };
17212
17213 @@ -2382,7 +2385,7 @@ static __init void mce_init_banks(void)
17214
17215 for (i = 0; i < mca_cfg.banks; i++) {
17216 struct mce_bank *b = &mce_banks[i];
17217 - struct device_attribute *a = &b->attr;
17218 + device_attribute_no_const *a = &b->attr;
17219
17220 sysfs_attr_init(&a->attr);
17221 a->attr.name = b->attrname;
17222 @@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
17223 static void mce_reset(void)
17224 {
17225 cpu_missing = 0;
17226 - atomic_set(&mce_fake_paniced, 0);
17227 + atomic_set_unchecked(&mce_fake_paniced, 0);
17228 atomic_set(&mce_executing, 0);
17229 atomic_set(&mce_callin, 0);
17230 atomic_set(&global_nwo, 0);
17231 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17232 index 2d5454c..51987eb 100644
17233 --- a/arch/x86/kernel/cpu/mcheck/p5.c
17234 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
17235 @@ -11,6 +11,7 @@
17236 #include <asm/processor.h>
17237 #include <asm/mce.h>
17238 #include <asm/msr.h>
17239 +#include <asm/pgtable.h>
17240
17241 /* By default disabled */
17242 int mce_p5_enabled __read_mostly;
17243 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17244 if (!cpu_has(c, X86_FEATURE_MCE))
17245 return;
17246
17247 + pax_open_kernel();
17248 machine_check_vector = pentium_machine_check;
17249 + pax_close_kernel();
17250 /* Make sure the vector pointer is visible before we enable MCEs: */
17251 wmb();
17252
17253 diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17254 index 47a1870..8c019a7 100644
17255 --- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17256 +++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17257 @@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17258 return notifier_from_errno(err);
17259 }
17260
17261 -static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17262 +static struct notifier_block thermal_throttle_cpu_notifier =
17263 {
17264 .notifier_call = thermal_throttle_cpu_callback,
17265 };
17266 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17267 index 2d7998f..17c9de1 100644
17268 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
17269 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17270 @@ -10,6 +10,7 @@
17271 #include <asm/processor.h>
17272 #include <asm/mce.h>
17273 #include <asm/msr.h>
17274 +#include <asm/pgtable.h>
17275
17276 /* Machine check handler for WinChip C6: */
17277 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17278 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17279 {
17280 u32 lo, hi;
17281
17282 + pax_open_kernel();
17283 machine_check_vector = winchip_machine_check;
17284 + pax_close_kernel();
17285 /* Make sure the vector pointer is visible before we enable MCEs: */
17286 wmb();
17287
17288 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17289 index 726bf96..81f0526 100644
17290 --- a/arch/x86/kernel/cpu/mtrr/main.c
17291 +++ b/arch/x86/kernel/cpu/mtrr/main.c
17292 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17293 u64 size_or_mask, size_and_mask;
17294 static bool mtrr_aps_delayed_init;
17295
17296 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17297 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17298
17299 const struct mtrr_ops *mtrr_if;
17300
17301 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17302 index df5e41f..816c719 100644
17303 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17304 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17305 @@ -25,7 +25,7 @@ struct mtrr_ops {
17306 int (*validate_add_page)(unsigned long base, unsigned long size,
17307 unsigned int type);
17308 int (*have_wrcomb)(void);
17309 -};
17310 +} __do_const;
17311
17312 extern int generic_get_free_region(unsigned long base, unsigned long size,
17313 int replace_reg);
17314 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17315 index 6774c17..72c1b22 100644
17316 --- a/arch/x86/kernel/cpu/perf_event.c
17317 +++ b/arch/x86/kernel/cpu/perf_event.c
17318 @@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
17319 pr_info("no hardware sampling interrupt available.\n");
17320 }
17321
17322 -static struct attribute_group x86_pmu_format_group = {
17323 +static attribute_group_no_const x86_pmu_format_group = {
17324 .name = "format",
17325 .attrs = NULL,
17326 };
17327 @@ -1313,7 +1313,7 @@ static struct attribute_group x86_pmu_format_group = {
17328 struct perf_pmu_events_attr {
17329 struct device_attribute attr;
17330 u64 id;
17331 -};
17332 +} __do_const;
17333
17334 /*
17335 * Remove all undefined events (x86_pmu.event_map(id) == 0)
17336 @@ -1381,7 +1381,7 @@ static struct attribute *events_attr[] = {
17337 NULL,
17338 };
17339
17340 -static struct attribute_group x86_pmu_events_group = {
17341 +static attribute_group_no_const x86_pmu_events_group = {
17342 .name = "events",
17343 .attrs = events_attr,
17344 };
17345 @@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17346 if (idx > GDT_ENTRIES)
17347 return 0;
17348
17349 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17350 + desc = get_cpu_gdt_table(smp_processor_id());
17351 }
17352
17353 return get_desc_base(desc + idx);
17354 @@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17355 break;
17356
17357 perf_callchain_store(entry, frame.return_address);
17358 - fp = frame.next_frame;
17359 + fp = (const void __force_user *)frame.next_frame;
17360 }
17361 }
17362
17363 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17364 index 4914e94..60b06e3 100644
17365 --- a/arch/x86/kernel/cpu/perf_event_intel.c
17366 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
17367 @@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
17368 * v2 and above have a perf capabilities MSR
17369 */
17370 if (version > 1) {
17371 - u64 capabilities;
17372 + u64 capabilities = x86_pmu.intel_cap.capabilities;
17373
17374 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17375 - x86_pmu.intel_cap.capabilities = capabilities;
17376 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17377 + x86_pmu.intel_cap.capabilities = capabilities;
17378 }
17379
17380 intel_ds_init();
17381 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17382 index b43200d..7fdcdbb 100644
17383 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17384 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17385 @@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17386 static int __init uncore_type_init(struct intel_uncore_type *type)
17387 {
17388 struct intel_uncore_pmu *pmus;
17389 - struct attribute_group *events_group;
17390 + attribute_group_no_const *events_group;
17391 struct attribute **attrs;
17392 int i, j;
17393
17394 @@ -2826,7 +2826,7 @@ static int
17395 return NOTIFY_OK;
17396 }
17397
17398 -static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17399 +static struct notifier_block uncore_cpu_nb = {
17400 .notifier_call = uncore_cpu_notifier,
17401 /*
17402 * to migrate uncore events, our notifier should be executed
17403 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17404 index e68a455..975a932 100644
17405 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17406 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17407 @@ -428,7 +428,7 @@ struct intel_uncore_box {
17408 struct uncore_event_desc {
17409 struct kobj_attribute attr;
17410 const char *config;
17411 -};
17412 +} __do_const;
17413
17414 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17415 { \
17416 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17417 index 60c7891..9e911d3 100644
17418 --- a/arch/x86/kernel/cpuid.c
17419 +++ b/arch/x86/kernel/cpuid.c
17420 @@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17421 return notifier_from_errno(err);
17422 }
17423
17424 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
17425 +static struct notifier_block cpuid_class_cpu_notifier =
17426 {
17427 .notifier_call = cpuid_class_cpu_callback,
17428 };
17429 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17430 index 74467fe..18793d5 100644
17431 --- a/arch/x86/kernel/crash.c
17432 +++ b/arch/x86/kernel/crash.c
17433 @@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17434 {
17435 #ifdef CONFIG_X86_32
17436 struct pt_regs fixed_regs;
17437 -#endif
17438
17439 -#ifdef CONFIG_X86_32
17440 - if (!user_mode_vm(regs)) {
17441 + if (!user_mode(regs)) {
17442 crash_fixup_ss_esp(&fixed_regs, regs);
17443 regs = &fixed_regs;
17444 }
17445 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17446 index 37250fe..bf2ec74 100644
17447 --- a/arch/x86/kernel/doublefault_32.c
17448 +++ b/arch/x86/kernel/doublefault_32.c
17449 @@ -11,7 +11,7 @@
17450
17451 #define DOUBLEFAULT_STACKSIZE (1024)
17452 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17453 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17454 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17455
17456 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17457
17458 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
17459 unsigned long gdt, tss;
17460
17461 store_gdt(&gdt_desc);
17462 - gdt = gdt_desc.address;
17463 + gdt = (unsigned long)gdt_desc.address;
17464
17465 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17466
17467 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17468 /* 0x2 bit is always set */
17469 .flags = X86_EFLAGS_SF | 0x2,
17470 .sp = STACK_START,
17471 - .es = __USER_DS,
17472 + .es = __KERNEL_DS,
17473 .cs = __KERNEL_CS,
17474 .ss = __KERNEL_DS,
17475 - .ds = __USER_DS,
17476 + .ds = __KERNEL_DS,
17477 .fs = __KERNEL_PERCPU,
17478
17479 .__cr3 = __pa_nodebug(swapper_pg_dir),
17480 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17481 index ae42418b..787c16b 100644
17482 --- a/arch/x86/kernel/dumpstack.c
17483 +++ b/arch/x86/kernel/dumpstack.c
17484 @@ -2,6 +2,9 @@
17485 * Copyright (C) 1991, 1992 Linus Torvalds
17486 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17487 */
17488 +#ifdef CONFIG_GRKERNSEC_HIDESYM
17489 +#define __INCLUDED_BY_HIDESYM 1
17490 +#endif
17491 #include <linux/kallsyms.h>
17492 #include <linux/kprobes.h>
17493 #include <linux/uaccess.h>
17494 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17495 static void
17496 print_ftrace_graph_addr(unsigned long addr, void *data,
17497 const struct stacktrace_ops *ops,
17498 - struct thread_info *tinfo, int *graph)
17499 + struct task_struct *task, int *graph)
17500 {
17501 - struct task_struct *task;
17502 unsigned long ret_addr;
17503 int index;
17504
17505 if (addr != (unsigned long)return_to_handler)
17506 return;
17507
17508 - task = tinfo->task;
17509 index = task->curr_ret_stack;
17510
17511 if (!task->ret_stack || index < *graph)
17512 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17513 static inline void
17514 print_ftrace_graph_addr(unsigned long addr, void *data,
17515 const struct stacktrace_ops *ops,
17516 - struct thread_info *tinfo, int *graph)
17517 + struct task_struct *task, int *graph)
17518 { }
17519 #endif
17520
17521 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17522 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17523 */
17524
17525 -static inline int valid_stack_ptr(struct thread_info *tinfo,
17526 - void *p, unsigned int size, void *end)
17527 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17528 {
17529 - void *t = tinfo;
17530 if (end) {
17531 if (p < end && p >= (end-THREAD_SIZE))
17532 return 1;
17533 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17534 }
17535
17536 unsigned long
17537 -print_context_stack(struct thread_info *tinfo,
17538 +print_context_stack(struct task_struct *task, void *stack_start,
17539 unsigned long *stack, unsigned long bp,
17540 const struct stacktrace_ops *ops, void *data,
17541 unsigned long *end, int *graph)
17542 {
17543 struct stack_frame *frame = (struct stack_frame *)bp;
17544
17545 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17546 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17547 unsigned long addr;
17548
17549 addr = *stack;
17550 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17551 } else {
17552 ops->address(data, addr, 0);
17553 }
17554 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17555 + print_ftrace_graph_addr(addr, data, ops, task, graph);
17556 }
17557 stack++;
17558 }
17559 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17560 EXPORT_SYMBOL_GPL(print_context_stack);
17561
17562 unsigned long
17563 -print_context_stack_bp(struct thread_info *tinfo,
17564 +print_context_stack_bp(struct task_struct *task, void *stack_start,
17565 unsigned long *stack, unsigned long bp,
17566 const struct stacktrace_ops *ops, void *data,
17567 unsigned long *end, int *graph)
17568 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17569 struct stack_frame *frame = (struct stack_frame *)bp;
17570 unsigned long *ret_addr = &frame->return_address;
17571
17572 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17573 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17574 unsigned long addr = *ret_addr;
17575
17576 if (!__kernel_text_address(addr))
17577 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17578 ops->address(data, addr, 1);
17579 frame = frame->next_frame;
17580 ret_addr = &frame->return_address;
17581 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17582 + print_ftrace_graph_addr(addr, data, ops, task, graph);
17583 }
17584
17585 return (unsigned long)frame;
17586 @@ -189,7 +188,7 @@ void dump_stack(void)
17587
17588 bp = stack_frame(current, NULL);
17589 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17590 - current->pid, current->comm, print_tainted(),
17591 + task_pid_nr(current), current->comm, print_tainted(),
17592 init_utsname()->release,
17593 (int)strcspn(init_utsname()->version, " "),
17594 init_utsname()->version);
17595 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17596 }
17597 EXPORT_SYMBOL_GPL(oops_begin);
17598
17599 +extern void gr_handle_kernel_exploit(void);
17600 +
17601 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17602 {
17603 if (regs && kexec_should_crash(current))
17604 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17605 panic("Fatal exception in interrupt");
17606 if (panic_on_oops)
17607 panic("Fatal exception");
17608 - do_exit(signr);
17609 +
17610 + gr_handle_kernel_exploit();
17611 +
17612 + do_group_exit(signr);
17613 }
17614
17615 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17616 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17617 print_modules();
17618 show_regs(regs);
17619 #ifdef CONFIG_X86_32
17620 - if (user_mode_vm(regs)) {
17621 + if (user_mode(regs)) {
17622 sp = regs->sp;
17623 ss = regs->ss & 0xffff;
17624 } else {
17625 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17626 unsigned long flags = oops_begin();
17627 int sig = SIGSEGV;
17628
17629 - if (!user_mode_vm(regs))
17630 + if (!user_mode(regs))
17631 report_bug(regs->ip, regs);
17632
17633 if (__die(str, regs, err))
17634 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17635 index 1038a41..db2c12b 100644
17636 --- a/arch/x86/kernel/dumpstack_32.c
17637 +++ b/arch/x86/kernel/dumpstack_32.c
17638 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17639 bp = stack_frame(task, regs);
17640
17641 for (;;) {
17642 - struct thread_info *context;
17643 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17644
17645 - context = (struct thread_info *)
17646 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17647 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17648 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17649
17650 - stack = (unsigned long *)context->previous_esp;
17651 - if (!stack)
17652 + if (stack_start == task_stack_page(task))
17653 break;
17654 + stack = *(unsigned long **)stack_start;
17655 if (ops->stack(data, "IRQ") < 0)
17656 break;
17657 touch_nmi_watchdog();
17658 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
17659 {
17660 int i;
17661
17662 - __show_regs(regs, !user_mode_vm(regs));
17663 + __show_regs(regs, !user_mode(regs));
17664
17665 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
17666 TASK_COMM_LEN, current->comm, task_pid_nr(current),
17667 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
17668 * When in-kernel, we also print out the stack and code at the
17669 * time of the fault..
17670 */
17671 - if (!user_mode_vm(regs)) {
17672 + if (!user_mode(regs)) {
17673 unsigned int code_prologue = code_bytes * 43 / 64;
17674 unsigned int code_len = code_bytes;
17675 unsigned char c;
17676 u8 *ip;
17677 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
17678
17679 pr_emerg("Stack:\n");
17680 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
17681
17682 pr_emerg("Code:");
17683
17684 - ip = (u8 *)regs->ip - code_prologue;
17685 + ip = (u8 *)regs->ip - code_prologue + cs_base;
17686 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
17687 /* try starting at IP */
17688 - ip = (u8 *)regs->ip;
17689 + ip = (u8 *)regs->ip + cs_base;
17690 code_len = code_len - code_prologue + 1;
17691 }
17692 for (i = 0; i < code_len; i++, ip++) {
17693 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
17694 pr_cont(" Bad EIP value.");
17695 break;
17696 }
17697 - if (ip == (u8 *)regs->ip)
17698 + if (ip == (u8 *)regs->ip + cs_base)
17699 pr_cont(" <%02x>", c);
17700 else
17701 pr_cont(" %02x", c);
17702 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
17703 {
17704 unsigned short ud2;
17705
17706 + ip = ktla_ktva(ip);
17707 if (ip < PAGE_OFFSET)
17708 return 0;
17709 if (probe_kernel_address((unsigned short *)ip, ud2))
17710 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
17711
17712 return ud2 == 0x0b0f;
17713 }
17714 +
17715 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17716 +void pax_check_alloca(unsigned long size)
17717 +{
17718 + unsigned long sp = (unsigned long)&sp, stack_left;
17719 +
17720 + /* all kernel stacks are of the same size */
17721 + stack_left = sp & (THREAD_SIZE - 1);
17722 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17723 +}
17724 +EXPORT_SYMBOL(pax_check_alloca);
17725 +#endif
17726 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
17727 index b653675..51cc8c0 100644
17728 --- a/arch/x86/kernel/dumpstack_64.c
17729 +++ b/arch/x86/kernel/dumpstack_64.c
17730 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17731 unsigned long *irq_stack_end =
17732 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
17733 unsigned used = 0;
17734 - struct thread_info *tinfo;
17735 int graph = 0;
17736 unsigned long dummy;
17737 + void *stack_start;
17738
17739 if (!task)
17740 task = current;
17741 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17742 * current stack address. If the stacks consist of nested
17743 * exceptions
17744 */
17745 - tinfo = task_thread_info(task);
17746 for (;;) {
17747 char *id;
17748 unsigned long *estack_end;
17749 +
17750 estack_end = in_exception_stack(cpu, (unsigned long)stack,
17751 &used, &id);
17752
17753 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17754 if (ops->stack(data, id) < 0)
17755 break;
17756
17757 - bp = ops->walk_stack(tinfo, stack, bp, ops,
17758 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
17759 data, estack_end, &graph);
17760 ops->stack(data, "<EOE>");
17761 /*
17762 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17763 * second-to-last pointer (index -2 to end) in the
17764 * exception stack:
17765 */
17766 + if ((u16)estack_end[-1] != __KERNEL_DS)
17767 + goto out;
17768 stack = (unsigned long *) estack_end[-2];
17769 continue;
17770 }
17771 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17772 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
17773 if (ops->stack(data, "IRQ") < 0)
17774 break;
17775 - bp = ops->walk_stack(tinfo, stack, bp,
17776 + bp = ops->walk_stack(task, irq_stack, stack, bp,
17777 ops, data, irq_stack_end, &graph);
17778 /*
17779 * We link to the next stack (which would be
17780 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17781 /*
17782 * This handles the process stack:
17783 */
17784 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
17785 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17786 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17787 +out:
17788 put_cpu();
17789 }
17790 EXPORT_SYMBOL(dump_trace);
17791 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
17792 {
17793 int i;
17794 unsigned long sp;
17795 - const int cpu = smp_processor_id();
17796 + const int cpu = raw_smp_processor_id();
17797 struct task_struct *cur = current;
17798
17799 sp = regs->sp;
17800 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
17801
17802 return ud2 == 0x0b0f;
17803 }
17804 +
17805 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17806 +void pax_check_alloca(unsigned long size)
17807 +{
17808 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
17809 + unsigned cpu, used;
17810 + char *id;
17811 +
17812 + /* check the process stack first */
17813 + stack_start = (unsigned long)task_stack_page(current);
17814 + stack_end = stack_start + THREAD_SIZE;
17815 + if (likely(stack_start <= sp && sp < stack_end)) {
17816 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
17817 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17818 + return;
17819 + }
17820 +
17821 + cpu = get_cpu();
17822 +
17823 + /* check the irq stacks */
17824 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
17825 + stack_start = stack_end - IRQ_STACK_SIZE;
17826 + if (stack_start <= sp && sp < stack_end) {
17827 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
17828 + put_cpu();
17829 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17830 + return;
17831 + }
17832 +
17833 + /* check the exception stacks */
17834 + used = 0;
17835 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
17836 + stack_start = stack_end - EXCEPTION_STKSZ;
17837 + if (stack_end && stack_start <= sp && sp < stack_end) {
17838 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
17839 + put_cpu();
17840 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17841 + return;
17842 + }
17843 +
17844 + put_cpu();
17845 +
17846 + /* unknown stack */
17847 + BUG();
17848 +}
17849 +EXPORT_SYMBOL(pax_check_alloca);
17850 +#endif
17851 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
17852 index 9b9f18b..9fcaa04 100644
17853 --- a/arch/x86/kernel/early_printk.c
17854 +++ b/arch/x86/kernel/early_printk.c
17855 @@ -7,6 +7,7 @@
17856 #include <linux/pci_regs.h>
17857 #include <linux/pci_ids.h>
17858 #include <linux/errno.h>
17859 +#include <linux/sched.h>
17860 #include <asm/io.h>
17861 #include <asm/processor.h>
17862 #include <asm/fcntl.h>
17863 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
17864 index 6ed91d9..6cc365b 100644
17865 --- a/arch/x86/kernel/entry_32.S
17866 +++ b/arch/x86/kernel/entry_32.S
17867 @@ -177,13 +177,153 @@
17868 /*CFI_REL_OFFSET gs, PT_GS*/
17869 .endm
17870 .macro SET_KERNEL_GS reg
17871 +
17872 +#ifdef CONFIG_CC_STACKPROTECTOR
17873 movl $(__KERNEL_STACK_CANARY), \reg
17874 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17875 + movl $(__USER_DS), \reg
17876 +#else
17877 + xorl \reg, \reg
17878 +#endif
17879 +
17880 movl \reg, %gs
17881 .endm
17882
17883 #endif /* CONFIG_X86_32_LAZY_GS */
17884
17885 -.macro SAVE_ALL
17886 +.macro pax_enter_kernel
17887 +#ifdef CONFIG_PAX_KERNEXEC
17888 + call pax_enter_kernel
17889 +#endif
17890 +.endm
17891 +
17892 +.macro pax_exit_kernel
17893 +#ifdef CONFIG_PAX_KERNEXEC
17894 + call pax_exit_kernel
17895 +#endif
17896 +.endm
17897 +
17898 +#ifdef CONFIG_PAX_KERNEXEC
17899 +ENTRY(pax_enter_kernel)
17900 +#ifdef CONFIG_PARAVIRT
17901 + pushl %eax
17902 + pushl %ecx
17903 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
17904 + mov %eax, %esi
17905 +#else
17906 + mov %cr0, %esi
17907 +#endif
17908 + bts $16, %esi
17909 + jnc 1f
17910 + mov %cs, %esi
17911 + cmp $__KERNEL_CS, %esi
17912 + jz 3f
17913 + ljmp $__KERNEL_CS, $3f
17914 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
17915 +2:
17916 +#ifdef CONFIG_PARAVIRT
17917 + mov %esi, %eax
17918 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17919 +#else
17920 + mov %esi, %cr0
17921 +#endif
17922 +3:
17923 +#ifdef CONFIG_PARAVIRT
17924 + popl %ecx
17925 + popl %eax
17926 +#endif
17927 + ret
17928 +ENDPROC(pax_enter_kernel)
17929 +
17930 +ENTRY(pax_exit_kernel)
17931 +#ifdef CONFIG_PARAVIRT
17932 + pushl %eax
17933 + pushl %ecx
17934 +#endif
17935 + mov %cs, %esi
17936 + cmp $__KERNEXEC_KERNEL_CS, %esi
17937 + jnz 2f
17938 +#ifdef CONFIG_PARAVIRT
17939 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
17940 + mov %eax, %esi
17941 +#else
17942 + mov %cr0, %esi
17943 +#endif
17944 + btr $16, %esi
17945 + ljmp $__KERNEL_CS, $1f
17946 +1:
17947 +#ifdef CONFIG_PARAVIRT
17948 + mov %esi, %eax
17949 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
17950 +#else
17951 + mov %esi, %cr0
17952 +#endif
17953 +2:
17954 +#ifdef CONFIG_PARAVIRT
17955 + popl %ecx
17956 + popl %eax
17957 +#endif
17958 + ret
17959 +ENDPROC(pax_exit_kernel)
17960 +#endif
17961 +
17962 +.macro pax_erase_kstack
17963 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17964 + call pax_erase_kstack
17965 +#endif
17966 +.endm
17967 +
17968 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17969 +/*
17970 + * ebp: thread_info
17971 + */
17972 +ENTRY(pax_erase_kstack)
17973 + pushl %edi
17974 + pushl %ecx
17975 + pushl %eax
17976 +
17977 + mov TI_lowest_stack(%ebp), %edi
17978 + mov $-0xBEEF, %eax
17979 + std
17980 +
17981 +1: mov %edi, %ecx
17982 + and $THREAD_SIZE_asm - 1, %ecx
17983 + shr $2, %ecx
17984 + repne scasl
17985 + jecxz 2f
17986 +
17987 + cmp $2*16, %ecx
17988 + jc 2f
17989 +
17990 + mov $2*16, %ecx
17991 + repe scasl
17992 + jecxz 2f
17993 + jne 1b
17994 +
17995 +2: cld
17996 + mov %esp, %ecx
17997 + sub %edi, %ecx
17998 +
17999 + cmp $THREAD_SIZE_asm, %ecx
18000 + jb 3f
18001 + ud2
18002 +3:
18003 +
18004 + shr $2, %ecx
18005 + rep stosl
18006 +
18007 + mov TI_task_thread_sp0(%ebp), %edi
18008 + sub $128, %edi
18009 + mov %edi, TI_lowest_stack(%ebp)
18010 +
18011 + popl %eax
18012 + popl %ecx
18013 + popl %edi
18014 + ret
18015 +ENDPROC(pax_erase_kstack)
18016 +#endif
18017 +
18018 +.macro __SAVE_ALL _DS
18019 cld
18020 PUSH_GS
18021 pushl_cfi %fs
18022 @@ -206,7 +346,7 @@
18023 CFI_REL_OFFSET ecx, 0
18024 pushl_cfi %ebx
18025 CFI_REL_OFFSET ebx, 0
18026 - movl $(__USER_DS), %edx
18027 + movl $\_DS, %edx
18028 movl %edx, %ds
18029 movl %edx, %es
18030 movl $(__KERNEL_PERCPU), %edx
18031 @@ -214,6 +354,15 @@
18032 SET_KERNEL_GS %edx
18033 .endm
18034
18035 +.macro SAVE_ALL
18036 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18037 + __SAVE_ALL __KERNEL_DS
18038 + pax_enter_kernel
18039 +#else
18040 + __SAVE_ALL __USER_DS
18041 +#endif
18042 +.endm
18043 +
18044 .macro RESTORE_INT_REGS
18045 popl_cfi %ebx
18046 CFI_RESTORE ebx
18047 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18048 popfl_cfi
18049 jmp syscall_exit
18050 CFI_ENDPROC
18051 -END(ret_from_fork)
18052 +ENDPROC(ret_from_fork)
18053
18054 ENTRY(ret_from_kernel_thread)
18055 CFI_STARTPROC
18056 @@ -344,7 +493,15 @@ ret_from_intr:
18057 andl $SEGMENT_RPL_MASK, %eax
18058 #endif
18059 cmpl $USER_RPL, %eax
18060 +
18061 +#ifdef CONFIG_PAX_KERNEXEC
18062 + jae resume_userspace
18063 +
18064 + pax_exit_kernel
18065 + jmp resume_kernel
18066 +#else
18067 jb resume_kernel # not returning to v8086 or userspace
18068 +#endif
18069
18070 ENTRY(resume_userspace)
18071 LOCKDEP_SYS_EXIT
18072 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18073 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18074 # int/exception return?
18075 jne work_pending
18076 - jmp restore_all
18077 -END(ret_from_exception)
18078 + jmp restore_all_pax
18079 +ENDPROC(ret_from_exception)
18080
18081 #ifdef CONFIG_PREEMPT
18082 ENTRY(resume_kernel)
18083 @@ -372,7 +529,7 @@ need_resched:
18084 jz restore_all
18085 call preempt_schedule_irq
18086 jmp need_resched
18087 -END(resume_kernel)
18088 +ENDPROC(resume_kernel)
18089 #endif
18090 CFI_ENDPROC
18091 /*
18092 @@ -406,30 +563,45 @@ sysenter_past_esp:
18093 /*CFI_REL_OFFSET cs, 0*/
18094 /*
18095 * Push current_thread_info()->sysenter_return to the stack.
18096 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18097 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
18098 */
18099 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18100 + pushl_cfi $0
18101 CFI_REL_OFFSET eip, 0
18102
18103 pushl_cfi %eax
18104 SAVE_ALL
18105 + GET_THREAD_INFO(%ebp)
18106 + movl TI_sysenter_return(%ebp),%ebp
18107 + movl %ebp,PT_EIP(%esp)
18108 ENABLE_INTERRUPTS(CLBR_NONE)
18109
18110 /*
18111 * Load the potential sixth argument from user stack.
18112 * Careful about security.
18113 */
18114 + movl PT_OLDESP(%esp),%ebp
18115 +
18116 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18117 + mov PT_OLDSS(%esp),%ds
18118 +1: movl %ds:(%ebp),%ebp
18119 + push %ss
18120 + pop %ds
18121 +#else
18122 cmpl $__PAGE_OFFSET-3,%ebp
18123 jae syscall_fault
18124 ASM_STAC
18125 1: movl (%ebp),%ebp
18126 ASM_CLAC
18127 +#endif
18128 +
18129 movl %ebp,PT_EBP(%esp)
18130 _ASM_EXTABLE(1b,syscall_fault)
18131
18132 GET_THREAD_INFO(%ebp)
18133
18134 +#ifdef CONFIG_PAX_RANDKSTACK
18135 + pax_erase_kstack
18136 +#endif
18137 +
18138 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18139 jnz sysenter_audit
18140 sysenter_do_call:
18141 @@ -444,12 +616,24 @@ sysenter_do_call:
18142 testl $_TIF_ALLWORK_MASK, %ecx
18143 jne sysexit_audit
18144 sysenter_exit:
18145 +
18146 +#ifdef CONFIG_PAX_RANDKSTACK
18147 + pushl_cfi %eax
18148 + movl %esp, %eax
18149 + call pax_randomize_kstack
18150 + popl_cfi %eax
18151 +#endif
18152 +
18153 + pax_erase_kstack
18154 +
18155 /* if something modifies registers it must also disable sysexit */
18156 movl PT_EIP(%esp), %edx
18157 movl PT_OLDESP(%esp), %ecx
18158 xorl %ebp,%ebp
18159 TRACE_IRQS_ON
18160 1: mov PT_FS(%esp), %fs
18161 +2: mov PT_DS(%esp), %ds
18162 +3: mov PT_ES(%esp), %es
18163 PTGS_TO_GS
18164 ENABLE_INTERRUPTS_SYSEXIT
18165
18166 @@ -466,6 +650,9 @@ sysenter_audit:
18167 movl %eax,%edx /* 2nd arg: syscall number */
18168 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18169 call __audit_syscall_entry
18170 +
18171 + pax_erase_kstack
18172 +
18173 pushl_cfi %ebx
18174 movl PT_EAX(%esp),%eax /* reload syscall number */
18175 jmp sysenter_do_call
18176 @@ -491,10 +678,16 @@ sysexit_audit:
18177
18178 CFI_ENDPROC
18179 .pushsection .fixup,"ax"
18180 -2: movl $0,PT_FS(%esp)
18181 +4: movl $0,PT_FS(%esp)
18182 + jmp 1b
18183 +5: movl $0,PT_DS(%esp)
18184 + jmp 1b
18185 +6: movl $0,PT_ES(%esp)
18186 jmp 1b
18187 .popsection
18188 - _ASM_EXTABLE(1b,2b)
18189 + _ASM_EXTABLE(1b,4b)
18190 + _ASM_EXTABLE(2b,5b)
18191 + _ASM_EXTABLE(3b,6b)
18192 PTGS_TO_GS_EX
18193 ENDPROC(ia32_sysenter_target)
18194
18195 @@ -509,6 +702,11 @@ ENTRY(system_call)
18196 pushl_cfi %eax # save orig_eax
18197 SAVE_ALL
18198 GET_THREAD_INFO(%ebp)
18199 +
18200 +#ifdef CONFIG_PAX_RANDKSTACK
18201 + pax_erase_kstack
18202 +#endif
18203 +
18204 # system call tracing in operation / emulation
18205 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18206 jnz syscall_trace_entry
18207 @@ -527,6 +725,15 @@ syscall_exit:
18208 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18209 jne syscall_exit_work
18210
18211 +restore_all_pax:
18212 +
18213 +#ifdef CONFIG_PAX_RANDKSTACK
18214 + movl %esp, %eax
18215 + call pax_randomize_kstack
18216 +#endif
18217 +
18218 + pax_erase_kstack
18219 +
18220 restore_all:
18221 TRACE_IRQS_IRET
18222 restore_all_notrace:
18223 @@ -583,14 +790,34 @@ ldt_ss:
18224 * compensating for the offset by changing to the ESPFIX segment with
18225 * a base address that matches for the difference.
18226 */
18227 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18228 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18229 mov %esp, %edx /* load kernel esp */
18230 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18231 mov %dx, %ax /* eax: new kernel esp */
18232 sub %eax, %edx /* offset (low word is 0) */
18233 +#ifdef CONFIG_SMP
18234 + movl PER_CPU_VAR(cpu_number), %ebx
18235 + shll $PAGE_SHIFT_asm, %ebx
18236 + addl $cpu_gdt_table, %ebx
18237 +#else
18238 + movl $cpu_gdt_table, %ebx
18239 +#endif
18240 shr $16, %edx
18241 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18242 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18243 +
18244 +#ifdef CONFIG_PAX_KERNEXEC
18245 + mov %cr0, %esi
18246 + btr $16, %esi
18247 + mov %esi, %cr0
18248 +#endif
18249 +
18250 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18251 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18252 +
18253 +#ifdef CONFIG_PAX_KERNEXEC
18254 + bts $16, %esi
18255 + mov %esi, %cr0
18256 +#endif
18257 +
18258 pushl_cfi $__ESPFIX_SS
18259 pushl_cfi %eax /* new kernel esp */
18260 /* Disable interrupts, but do not irqtrace this section: we
18261 @@ -619,20 +846,18 @@ work_resched:
18262 movl TI_flags(%ebp), %ecx
18263 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18264 # than syscall tracing?
18265 - jz restore_all
18266 + jz restore_all_pax
18267 testb $_TIF_NEED_RESCHED, %cl
18268 jnz work_resched
18269
18270 work_notifysig: # deal with pending signals and
18271 # notify-resume requests
18272 + movl %esp, %eax
18273 #ifdef CONFIG_VM86
18274 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18275 - movl %esp, %eax
18276 jne work_notifysig_v86 # returning to kernel-space or
18277 # vm86-space
18278 1:
18279 -#else
18280 - movl %esp, %eax
18281 #endif
18282 TRACE_IRQS_ON
18283 ENABLE_INTERRUPTS(CLBR_NONE)
18284 @@ -653,7 +878,7 @@ work_notifysig_v86:
18285 movl %eax, %esp
18286 jmp 1b
18287 #endif
18288 -END(work_pending)
18289 +ENDPROC(work_pending)
18290
18291 # perform syscall exit tracing
18292 ALIGN
18293 @@ -661,11 +886,14 @@ syscall_trace_entry:
18294 movl $-ENOSYS,PT_EAX(%esp)
18295 movl %esp, %eax
18296 call syscall_trace_enter
18297 +
18298 + pax_erase_kstack
18299 +
18300 /* What it returned is what we'll actually use. */
18301 cmpl $(NR_syscalls), %eax
18302 jnae syscall_call
18303 jmp syscall_exit
18304 -END(syscall_trace_entry)
18305 +ENDPROC(syscall_trace_entry)
18306
18307 # perform syscall exit tracing
18308 ALIGN
18309 @@ -678,21 +906,25 @@ syscall_exit_work:
18310 movl %esp, %eax
18311 call syscall_trace_leave
18312 jmp resume_userspace
18313 -END(syscall_exit_work)
18314 +ENDPROC(syscall_exit_work)
18315 CFI_ENDPROC
18316
18317 RING0_INT_FRAME # can't unwind into user space anyway
18318 syscall_fault:
18319 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18320 + push %ss
18321 + pop %ds
18322 +#endif
18323 ASM_CLAC
18324 GET_THREAD_INFO(%ebp)
18325 movl $-EFAULT,PT_EAX(%esp)
18326 jmp resume_userspace
18327 -END(syscall_fault)
18328 +ENDPROC(syscall_fault)
18329
18330 syscall_badsys:
18331 movl $-ENOSYS,PT_EAX(%esp)
18332 jmp resume_userspace
18333 -END(syscall_badsys)
18334 +ENDPROC(syscall_badsys)
18335 CFI_ENDPROC
18336 /*
18337 * End of kprobes section
18338 @@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18339 * normal stack and adjusts ESP with the matching offset.
18340 */
18341 /* fixup the stack */
18342 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18343 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18344 +#ifdef CONFIG_SMP
18345 + movl PER_CPU_VAR(cpu_number), %ebx
18346 + shll $PAGE_SHIFT_asm, %ebx
18347 + addl $cpu_gdt_table, %ebx
18348 +#else
18349 + movl $cpu_gdt_table, %ebx
18350 +#endif
18351 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18352 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18353 shl $16, %eax
18354 addl %esp, %eax /* the adjusted stack pointer */
18355 pushl_cfi $__KERNEL_DS
18356 @@ -807,7 +1046,7 @@ vector=vector+1
18357 .endr
18358 2: jmp common_interrupt
18359 .endr
18360 -END(irq_entries_start)
18361 +ENDPROC(irq_entries_start)
18362
18363 .previous
18364 END(interrupt)
18365 @@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
18366 pushl_cfi $do_coprocessor_error
18367 jmp error_code
18368 CFI_ENDPROC
18369 -END(coprocessor_error)
18370 +ENDPROC(coprocessor_error)
18371
18372 ENTRY(simd_coprocessor_error)
18373 RING0_INT_FRAME
18374 @@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
18375 #endif
18376 jmp error_code
18377 CFI_ENDPROC
18378 -END(simd_coprocessor_error)
18379 +ENDPROC(simd_coprocessor_error)
18380
18381 ENTRY(device_not_available)
18382 RING0_INT_FRAME
18383 @@ -889,18 +1128,18 @@ ENTRY(device_not_available)
18384 pushl_cfi $do_device_not_available
18385 jmp error_code
18386 CFI_ENDPROC
18387 -END(device_not_available)
18388 +ENDPROC(device_not_available)
18389
18390 #ifdef CONFIG_PARAVIRT
18391 ENTRY(native_iret)
18392 iret
18393 _ASM_EXTABLE(native_iret, iret_exc)
18394 -END(native_iret)
18395 +ENDPROC(native_iret)
18396
18397 ENTRY(native_irq_enable_sysexit)
18398 sti
18399 sysexit
18400 -END(native_irq_enable_sysexit)
18401 +ENDPROC(native_irq_enable_sysexit)
18402 #endif
18403
18404 ENTRY(overflow)
18405 @@ -910,7 +1149,7 @@ ENTRY(overflow)
18406 pushl_cfi $do_overflow
18407 jmp error_code
18408 CFI_ENDPROC
18409 -END(overflow)
18410 +ENDPROC(overflow)
18411
18412 ENTRY(bounds)
18413 RING0_INT_FRAME
18414 @@ -919,7 +1158,7 @@ ENTRY(bounds)
18415 pushl_cfi $do_bounds
18416 jmp error_code
18417 CFI_ENDPROC
18418 -END(bounds)
18419 +ENDPROC(bounds)
18420
18421 ENTRY(invalid_op)
18422 RING0_INT_FRAME
18423 @@ -928,7 +1167,7 @@ ENTRY(invalid_op)
18424 pushl_cfi $do_invalid_op
18425 jmp error_code
18426 CFI_ENDPROC
18427 -END(invalid_op)
18428 +ENDPROC(invalid_op)
18429
18430 ENTRY(coprocessor_segment_overrun)
18431 RING0_INT_FRAME
18432 @@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
18433 pushl_cfi $do_coprocessor_segment_overrun
18434 jmp error_code
18435 CFI_ENDPROC
18436 -END(coprocessor_segment_overrun)
18437 +ENDPROC(coprocessor_segment_overrun)
18438
18439 ENTRY(invalid_TSS)
18440 RING0_EC_FRAME
18441 @@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
18442 pushl_cfi $do_invalid_TSS
18443 jmp error_code
18444 CFI_ENDPROC
18445 -END(invalid_TSS)
18446 +ENDPROC(invalid_TSS)
18447
18448 ENTRY(segment_not_present)
18449 RING0_EC_FRAME
18450 @@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
18451 pushl_cfi $do_segment_not_present
18452 jmp error_code
18453 CFI_ENDPROC
18454 -END(segment_not_present)
18455 +ENDPROC(segment_not_present)
18456
18457 ENTRY(stack_segment)
18458 RING0_EC_FRAME
18459 @@ -961,7 +1200,7 @@ ENTRY(stack_segment)
18460 pushl_cfi $do_stack_segment
18461 jmp error_code
18462 CFI_ENDPROC
18463 -END(stack_segment)
18464 +ENDPROC(stack_segment)
18465
18466 ENTRY(alignment_check)
18467 RING0_EC_FRAME
18468 @@ -969,7 +1208,7 @@ ENTRY(alignment_check)
18469 pushl_cfi $do_alignment_check
18470 jmp error_code
18471 CFI_ENDPROC
18472 -END(alignment_check)
18473 +ENDPROC(alignment_check)
18474
18475 ENTRY(divide_error)
18476 RING0_INT_FRAME
18477 @@ -978,7 +1217,7 @@ ENTRY(divide_error)
18478 pushl_cfi $do_divide_error
18479 jmp error_code
18480 CFI_ENDPROC
18481 -END(divide_error)
18482 +ENDPROC(divide_error)
18483
18484 #ifdef CONFIG_X86_MCE
18485 ENTRY(machine_check)
18486 @@ -988,7 +1227,7 @@ ENTRY(machine_check)
18487 pushl_cfi machine_check_vector
18488 jmp error_code
18489 CFI_ENDPROC
18490 -END(machine_check)
18491 +ENDPROC(machine_check)
18492 #endif
18493
18494 ENTRY(spurious_interrupt_bug)
18495 @@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
18496 pushl_cfi $do_spurious_interrupt_bug
18497 jmp error_code
18498 CFI_ENDPROC
18499 -END(spurious_interrupt_bug)
18500 +ENDPROC(spurious_interrupt_bug)
18501 /*
18502 * End of kprobes section
18503 */
18504 @@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
18505
18506 ENTRY(mcount)
18507 ret
18508 -END(mcount)
18509 +ENDPROC(mcount)
18510
18511 ENTRY(ftrace_caller)
18512 cmpl $0, function_trace_stop
18513 @@ -1134,7 +1373,7 @@ ftrace_graph_call:
18514 .globl ftrace_stub
18515 ftrace_stub:
18516 ret
18517 -END(ftrace_caller)
18518 +ENDPROC(ftrace_caller)
18519
18520 ENTRY(ftrace_regs_caller)
18521 pushf /* push flags before compare (in cs location) */
18522 @@ -1235,7 +1474,7 @@ trace:
18523 popl %ecx
18524 popl %eax
18525 jmp ftrace_stub
18526 -END(mcount)
18527 +ENDPROC(mcount)
18528 #endif /* CONFIG_DYNAMIC_FTRACE */
18529 #endif /* CONFIG_FUNCTION_TRACER */
18530
18531 @@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
18532 popl %ecx
18533 popl %eax
18534 ret
18535 -END(ftrace_graph_caller)
18536 +ENDPROC(ftrace_graph_caller)
18537
18538 .globl return_to_handler
18539 return_to_handler:
18540 @@ -1309,15 +1548,18 @@ error_code:
18541 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18542 REG_TO_PTGS %ecx
18543 SET_KERNEL_GS %ecx
18544 - movl $(__USER_DS), %ecx
18545 + movl $(__KERNEL_DS), %ecx
18546 movl %ecx, %ds
18547 movl %ecx, %es
18548 +
18549 + pax_enter_kernel
18550 +
18551 TRACE_IRQS_OFF
18552 movl %esp,%eax # pt_regs pointer
18553 call *%edi
18554 jmp ret_from_exception
18555 CFI_ENDPROC
18556 -END(page_fault)
18557 +ENDPROC(page_fault)
18558
18559 /*
18560 * Debug traps and NMI can happen at the one SYSENTER instruction
18561 @@ -1360,7 +1602,7 @@ debug_stack_correct:
18562 call do_debug
18563 jmp ret_from_exception
18564 CFI_ENDPROC
18565 -END(debug)
18566 +ENDPROC(debug)
18567
18568 /*
18569 * NMI is doubly nasty. It can happen _while_ we're handling
18570 @@ -1398,6 +1640,9 @@ nmi_stack_correct:
18571 xorl %edx,%edx # zero error code
18572 movl %esp,%eax # pt_regs pointer
18573 call do_nmi
18574 +
18575 + pax_exit_kernel
18576 +
18577 jmp restore_all_notrace
18578 CFI_ENDPROC
18579
18580 @@ -1434,12 +1679,15 @@ nmi_espfix_stack:
18581 FIXUP_ESPFIX_STACK # %eax == %esp
18582 xorl %edx,%edx # zero error code
18583 call do_nmi
18584 +
18585 + pax_exit_kernel
18586 +
18587 RESTORE_REGS
18588 lss 12+4(%esp), %esp # back to espfix stack
18589 CFI_ADJUST_CFA_OFFSET -24
18590 jmp irq_return
18591 CFI_ENDPROC
18592 -END(nmi)
18593 +ENDPROC(nmi)
18594
18595 ENTRY(int3)
18596 RING0_INT_FRAME
18597 @@ -1452,14 +1700,14 @@ ENTRY(int3)
18598 call do_int3
18599 jmp ret_from_exception
18600 CFI_ENDPROC
18601 -END(int3)
18602 +ENDPROC(int3)
18603
18604 ENTRY(general_protection)
18605 RING0_EC_FRAME
18606 pushl_cfi $do_general_protection
18607 jmp error_code
18608 CFI_ENDPROC
18609 -END(general_protection)
18610 +ENDPROC(general_protection)
18611
18612 #ifdef CONFIG_KVM_GUEST
18613 ENTRY(async_page_fault)
18614 @@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
18615 pushl_cfi $do_async_page_fault
18616 jmp error_code
18617 CFI_ENDPROC
18618 -END(async_page_fault)
18619 +ENDPROC(async_page_fault)
18620 #endif
18621
18622 /*
18623 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18624 index cb3c591..bc63707 100644
18625 --- a/arch/x86/kernel/entry_64.S
18626 +++ b/arch/x86/kernel/entry_64.S
18627 @@ -59,6 +59,8 @@
18628 #include <asm/context_tracking.h>
18629 #include <asm/smap.h>
18630 #include <linux/err.h>
18631 +#include <asm/pgtable.h>
18632 +#include <asm/alternative-asm.h>
18633
18634 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18635 #include <linux/elf-em.h>
18636 @@ -80,8 +82,9 @@
18637 #ifdef CONFIG_DYNAMIC_FTRACE
18638
18639 ENTRY(function_hook)
18640 + pax_force_retaddr
18641 retq
18642 -END(function_hook)
18643 +ENDPROC(function_hook)
18644
18645 /* skip is set if stack has been adjusted */
18646 .macro ftrace_caller_setup skip=0
18647 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18648 #endif
18649
18650 GLOBAL(ftrace_stub)
18651 + pax_force_retaddr
18652 retq
18653 -END(ftrace_caller)
18654 +ENDPROC(ftrace_caller)
18655
18656 ENTRY(ftrace_regs_caller)
18657 /* Save the current flags before compare (in SS location)*/
18658 @@ -191,7 +195,7 @@ ftrace_restore_flags:
18659 popfq
18660 jmp ftrace_stub
18661
18662 -END(ftrace_regs_caller)
18663 +ENDPROC(ftrace_regs_caller)
18664
18665
18666 #else /* ! CONFIG_DYNAMIC_FTRACE */
18667 @@ -212,6 +216,7 @@ ENTRY(function_hook)
18668 #endif
18669
18670 GLOBAL(ftrace_stub)
18671 + pax_force_retaddr
18672 retq
18673
18674 trace:
18675 @@ -225,12 +230,13 @@ trace:
18676 #endif
18677 subq $MCOUNT_INSN_SIZE, %rdi
18678
18679 + pax_force_fptr ftrace_trace_function
18680 call *ftrace_trace_function
18681
18682 MCOUNT_RESTORE_FRAME
18683
18684 jmp ftrace_stub
18685 -END(function_hook)
18686 +ENDPROC(function_hook)
18687 #endif /* CONFIG_DYNAMIC_FTRACE */
18688 #endif /* CONFIG_FUNCTION_TRACER */
18689
18690 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
18691
18692 MCOUNT_RESTORE_FRAME
18693
18694 + pax_force_retaddr
18695 retq
18696 -END(ftrace_graph_caller)
18697 +ENDPROC(ftrace_graph_caller)
18698
18699 GLOBAL(return_to_handler)
18700 subq $24, %rsp
18701 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
18702 movq 8(%rsp), %rdx
18703 movq (%rsp), %rax
18704 addq $24, %rsp
18705 + pax_force_fptr %rdi
18706 jmp *%rdi
18707 +ENDPROC(return_to_handler)
18708 #endif
18709
18710
18711 @@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
18712 ENDPROC(native_usergs_sysret64)
18713 #endif /* CONFIG_PARAVIRT */
18714
18715 + .macro ljmpq sel, off
18716 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
18717 + .byte 0x48; ljmp *1234f(%rip)
18718 + .pushsection .rodata
18719 + .align 16
18720 + 1234: .quad \off; .word \sel
18721 + .popsection
18722 +#else
18723 + pushq $\sel
18724 + pushq $\off
18725 + lretq
18726 +#endif
18727 + .endm
18728 +
18729 + .macro pax_enter_kernel
18730 + pax_set_fptr_mask
18731 +#ifdef CONFIG_PAX_KERNEXEC
18732 + call pax_enter_kernel
18733 +#endif
18734 + .endm
18735 +
18736 + .macro pax_exit_kernel
18737 +#ifdef CONFIG_PAX_KERNEXEC
18738 + call pax_exit_kernel
18739 +#endif
18740 + .endm
18741 +
18742 +#ifdef CONFIG_PAX_KERNEXEC
18743 +ENTRY(pax_enter_kernel)
18744 + pushq %rdi
18745 +
18746 +#ifdef CONFIG_PARAVIRT
18747 + PV_SAVE_REGS(CLBR_RDI)
18748 +#endif
18749 +
18750 + GET_CR0_INTO_RDI
18751 + bts $16,%rdi
18752 + jnc 3f
18753 + mov %cs,%edi
18754 + cmp $__KERNEL_CS,%edi
18755 + jnz 2f
18756 +1:
18757 +
18758 +#ifdef CONFIG_PARAVIRT
18759 + PV_RESTORE_REGS(CLBR_RDI)
18760 +#endif
18761 +
18762 + popq %rdi
18763 + pax_force_retaddr
18764 + retq
18765 +
18766 +2: ljmpq __KERNEL_CS,1f
18767 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
18768 +4: SET_RDI_INTO_CR0
18769 + jmp 1b
18770 +ENDPROC(pax_enter_kernel)
18771 +
18772 +ENTRY(pax_exit_kernel)
18773 + pushq %rdi
18774 +
18775 +#ifdef CONFIG_PARAVIRT
18776 + PV_SAVE_REGS(CLBR_RDI)
18777 +#endif
18778 +
18779 + mov %cs,%rdi
18780 + cmp $__KERNEXEC_KERNEL_CS,%edi
18781 + jz 2f
18782 +1:
18783 +
18784 +#ifdef CONFIG_PARAVIRT
18785 + PV_RESTORE_REGS(CLBR_RDI);
18786 +#endif
18787 +
18788 + popq %rdi
18789 + pax_force_retaddr
18790 + retq
18791 +
18792 +2: GET_CR0_INTO_RDI
18793 + btr $16,%rdi
18794 + ljmpq __KERNEL_CS,3f
18795 +3: SET_RDI_INTO_CR0
18796 + jmp 1b
18797 +ENDPROC(pax_exit_kernel)
18798 +#endif
18799 +
18800 + .macro pax_enter_kernel_user
18801 + pax_set_fptr_mask
18802 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18803 + call pax_enter_kernel_user
18804 +#endif
18805 + .endm
18806 +
18807 + .macro pax_exit_kernel_user
18808 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18809 + call pax_exit_kernel_user
18810 +#endif
18811 +#ifdef CONFIG_PAX_RANDKSTACK
18812 + pushq %rax
18813 + call pax_randomize_kstack
18814 + popq %rax
18815 +#endif
18816 + .endm
18817 +
18818 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18819 +ENTRY(pax_enter_kernel_user)
18820 + pushq %rdi
18821 + pushq %rbx
18822 +
18823 +#ifdef CONFIG_PARAVIRT
18824 + PV_SAVE_REGS(CLBR_RDI)
18825 +#endif
18826 +
18827 + GET_CR3_INTO_RDI
18828 + mov %rdi,%rbx
18829 + add $__START_KERNEL_map,%rbx
18830 + sub phys_base(%rip),%rbx
18831 +
18832 +#ifdef CONFIG_PARAVIRT
18833 + pushq %rdi
18834 + cmpl $0, pv_info+PARAVIRT_enabled
18835 + jz 1f
18836 + i = 0
18837 + .rept USER_PGD_PTRS
18838 + mov i*8(%rbx),%rsi
18839 + mov $0,%sil
18840 + lea i*8(%rbx),%rdi
18841 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18842 + i = i + 1
18843 + .endr
18844 + jmp 2f
18845 +1:
18846 +#endif
18847 +
18848 + i = 0
18849 + .rept USER_PGD_PTRS
18850 + movb $0,i*8(%rbx)
18851 + i = i + 1
18852 + .endr
18853 +
18854 +#ifdef CONFIG_PARAVIRT
18855 +2: popq %rdi
18856 +#endif
18857 + SET_RDI_INTO_CR3
18858 +
18859 +#ifdef CONFIG_PAX_KERNEXEC
18860 + GET_CR0_INTO_RDI
18861 + bts $16,%rdi
18862 + SET_RDI_INTO_CR0
18863 +#endif
18864 +
18865 +#ifdef CONFIG_PARAVIRT
18866 + PV_RESTORE_REGS(CLBR_RDI)
18867 +#endif
18868 +
18869 + popq %rbx
18870 + popq %rdi
18871 + pax_force_retaddr
18872 + retq
18873 +ENDPROC(pax_enter_kernel_user)
18874 +
18875 +ENTRY(pax_exit_kernel_user)
18876 + push %rdi
18877 +
18878 +#ifdef CONFIG_PARAVIRT
18879 + pushq %rbx
18880 + PV_SAVE_REGS(CLBR_RDI)
18881 +#endif
18882 +
18883 +#ifdef CONFIG_PAX_KERNEXEC
18884 + GET_CR0_INTO_RDI
18885 + btr $16,%rdi
18886 + SET_RDI_INTO_CR0
18887 +#endif
18888 +
18889 + GET_CR3_INTO_RDI
18890 + add $__START_KERNEL_map,%rdi
18891 + sub phys_base(%rip),%rdi
18892 +
18893 +#ifdef CONFIG_PARAVIRT
18894 + cmpl $0, pv_info+PARAVIRT_enabled
18895 + jz 1f
18896 + mov %rdi,%rbx
18897 + i = 0
18898 + .rept USER_PGD_PTRS
18899 + mov i*8(%rbx),%rsi
18900 + mov $0x67,%sil
18901 + lea i*8(%rbx),%rdi
18902 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18903 + i = i + 1
18904 + .endr
18905 + jmp 2f
18906 +1:
18907 +#endif
18908 +
18909 + i = 0
18910 + .rept USER_PGD_PTRS
18911 + movb $0x67,i*8(%rdi)
18912 + i = i + 1
18913 + .endr
18914 +
18915 +#ifdef CONFIG_PARAVIRT
18916 +2: PV_RESTORE_REGS(CLBR_RDI)
18917 + popq %rbx
18918 +#endif
18919 +
18920 + popq %rdi
18921 + pax_force_retaddr
18922 + retq
18923 +ENDPROC(pax_exit_kernel_user)
18924 +#endif
18925 +
18926 +.macro pax_erase_kstack
18927 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18928 + call pax_erase_kstack
18929 +#endif
18930 +.endm
18931 +
18932 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18933 +ENTRY(pax_erase_kstack)
18934 + pushq %rdi
18935 + pushq %rcx
18936 + pushq %rax
18937 + pushq %r11
18938 +
18939 + GET_THREAD_INFO(%r11)
18940 + mov TI_lowest_stack(%r11), %rdi
18941 + mov $-0xBEEF, %rax
18942 + std
18943 +
18944 +1: mov %edi, %ecx
18945 + and $THREAD_SIZE_asm - 1, %ecx
18946 + shr $3, %ecx
18947 + repne scasq
18948 + jecxz 2f
18949 +
18950 + cmp $2*8, %ecx
18951 + jc 2f
18952 +
18953 + mov $2*8, %ecx
18954 + repe scasq
18955 + jecxz 2f
18956 + jne 1b
18957 +
18958 +2: cld
18959 + mov %esp, %ecx
18960 + sub %edi, %ecx
18961 +
18962 + cmp $THREAD_SIZE_asm, %rcx
18963 + jb 3f
18964 + ud2
18965 +3:
18966 +
18967 + shr $3, %ecx
18968 + rep stosq
18969 +
18970 + mov TI_task_thread_sp0(%r11), %rdi
18971 + sub $256, %rdi
18972 + mov %rdi, TI_lowest_stack(%r11)
18973 +
18974 + popq %r11
18975 + popq %rax
18976 + popq %rcx
18977 + popq %rdi
18978 + pax_force_retaddr
18979 + ret
18980 +ENDPROC(pax_erase_kstack)
18981 +#endif
18982
18983 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
18984 #ifdef CONFIG_TRACE_IRQFLAGS
18985 @@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
18986 .endm
18987
18988 .macro UNFAKE_STACK_FRAME
18989 - addq $8*6, %rsp
18990 - CFI_ADJUST_CFA_OFFSET -(6*8)
18991 + addq $8*6 + ARG_SKIP, %rsp
18992 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
18993 .endm
18994
18995 /*
18996 @@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
18997 movq %rsp, %rsi
18998
18999 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19000 - testl $3, CS-RBP(%rsi)
19001 + testb $3, CS-RBP(%rsi)
19002 je 1f
19003 SWAPGS
19004 /*
19005 @@ -498,9 +774,10 @@ ENTRY(save_rest)
19006 movq_cfi r15, R15+16
19007 movq %r11, 8(%rsp) /* return address */
19008 FIXUP_TOP_OF_STACK %r11, 16
19009 + pax_force_retaddr
19010 ret
19011 CFI_ENDPROC
19012 -END(save_rest)
19013 +ENDPROC(save_rest)
19014
19015 /* save complete stack frame */
19016 .pushsection .kprobes.text, "ax"
19017 @@ -529,9 +806,10 @@ ENTRY(save_paranoid)
19018 js 1f /* negative -> in kernel */
19019 SWAPGS
19020 xorl %ebx,%ebx
19021 -1: ret
19022 +1: pax_force_retaddr_bts
19023 + ret
19024 CFI_ENDPROC
19025 -END(save_paranoid)
19026 +ENDPROC(save_paranoid)
19027 .popsection
19028
19029 /*
19030 @@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
19031
19032 RESTORE_REST
19033
19034 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19035 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19036 jz 1f
19037
19038 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19039 @@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
19040 RESTORE_REST
19041 jmp int_ret_from_sys_call
19042 CFI_ENDPROC
19043 -END(ret_from_fork)
19044 +ENDPROC(ret_from_fork)
19045
19046 /*
19047 * System call entry. Up to 6 arguments in registers are supported.
19048 @@ -608,7 +886,7 @@ END(ret_from_fork)
19049 ENTRY(system_call)
19050 CFI_STARTPROC simple
19051 CFI_SIGNAL_FRAME
19052 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19053 + CFI_DEF_CFA rsp,0
19054 CFI_REGISTER rip,rcx
19055 /*CFI_REGISTER rflags,r11*/
19056 SWAPGS_UNSAFE_STACK
19057 @@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
19058
19059 movq %rsp,PER_CPU_VAR(old_rsp)
19060 movq PER_CPU_VAR(kernel_stack),%rsp
19061 + SAVE_ARGS 8*6,0
19062 + pax_enter_kernel_user
19063 +
19064 +#ifdef CONFIG_PAX_RANDKSTACK
19065 + pax_erase_kstack
19066 +#endif
19067 +
19068 /*
19069 * No need to follow this irqs off/on section - it's straight
19070 * and short:
19071 */
19072 ENABLE_INTERRUPTS(CLBR_NONE)
19073 - SAVE_ARGS 8,0
19074 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19075 movq %rcx,RIP-ARGOFFSET(%rsp)
19076 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19077 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19078 + GET_THREAD_INFO(%rcx)
19079 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19080 jnz tracesys
19081 system_call_fastpath:
19082 #if __SYSCALL_MASK == ~0
19083 @@ -640,7 +925,7 @@ system_call_fastpath:
19084 cmpl $__NR_syscall_max,%eax
19085 #endif
19086 ja badsys
19087 - movq %r10,%rcx
19088 + movq R10-ARGOFFSET(%rsp),%rcx
19089 call *sys_call_table(,%rax,8) # XXX: rip relative
19090 movq %rax,RAX-ARGOFFSET(%rsp)
19091 /*
19092 @@ -654,10 +939,13 @@ sysret_check:
19093 LOCKDEP_SYS_EXIT
19094 DISABLE_INTERRUPTS(CLBR_NONE)
19095 TRACE_IRQS_OFF
19096 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19097 + GET_THREAD_INFO(%rcx)
19098 + movl TI_flags(%rcx),%edx
19099 andl %edi,%edx
19100 jnz sysret_careful
19101 CFI_REMEMBER_STATE
19102 + pax_exit_kernel_user
19103 + pax_erase_kstack
19104 /*
19105 * sysretq will re-enable interrupts:
19106 */
19107 @@ -709,14 +997,18 @@ badsys:
19108 * jump back to the normal fast path.
19109 */
19110 auditsys:
19111 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
19112 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19113 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19114 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19115 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19116 movq %rax,%rsi /* 2nd arg: syscall number */
19117 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19118 call __audit_syscall_entry
19119 +
19120 + pax_erase_kstack
19121 +
19122 LOAD_ARGS 0 /* reload call-clobbered registers */
19123 + pax_set_fptr_mask
19124 jmp system_call_fastpath
19125
19126 /*
19127 @@ -737,7 +1029,7 @@ sysret_audit:
19128 /* Do syscall tracing */
19129 tracesys:
19130 #ifdef CONFIG_AUDITSYSCALL
19131 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19132 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19133 jz auditsys
19134 #endif
19135 SAVE_REST
19136 @@ -745,12 +1037,16 @@ tracesys:
19137 FIXUP_TOP_OF_STACK %rdi
19138 movq %rsp,%rdi
19139 call syscall_trace_enter
19140 +
19141 + pax_erase_kstack
19142 +
19143 /*
19144 * Reload arg registers from stack in case ptrace changed them.
19145 * We don't reload %rax because syscall_trace_enter() returned
19146 * the value it wants us to use in the table lookup.
19147 */
19148 LOAD_ARGS ARGOFFSET, 1
19149 + pax_set_fptr_mask
19150 RESTORE_REST
19151 #if __SYSCALL_MASK == ~0
19152 cmpq $__NR_syscall_max,%rax
19153 @@ -759,7 +1055,7 @@ tracesys:
19154 cmpl $__NR_syscall_max,%eax
19155 #endif
19156 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19157 - movq %r10,%rcx /* fixup for C */
19158 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19159 call *sys_call_table(,%rax,8)
19160 movq %rax,RAX-ARGOFFSET(%rsp)
19161 /* Use IRET because user could have changed frame */
19162 @@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
19163 andl %edi,%edx
19164 jnz int_careful
19165 andl $~TS_COMPAT,TI_status(%rcx)
19166 - jmp retint_swapgs
19167 + pax_exit_kernel_user
19168 + pax_erase_kstack
19169 + jmp retint_swapgs_pax
19170
19171 /* Either reschedule or signal or syscall exit tracking needed. */
19172 /* First do a reschedule test. */
19173 @@ -826,7 +1124,7 @@ int_restore_rest:
19174 TRACE_IRQS_OFF
19175 jmp int_with_check
19176 CFI_ENDPROC
19177 -END(system_call)
19178 +ENDPROC(system_call)
19179
19180 /*
19181 * Certain special system calls that need to save a complete full stack frame.
19182 @@ -842,7 +1140,7 @@ ENTRY(\label)
19183 call \func
19184 jmp ptregscall_common
19185 CFI_ENDPROC
19186 -END(\label)
19187 +ENDPROC(\label)
19188 .endm
19189
19190 .macro FORK_LIKE func
19191 @@ -856,9 +1154,10 @@ ENTRY(stub_\func)
19192 DEFAULT_FRAME 0 8 /* offset 8: return address */
19193 call sys_\func
19194 RESTORE_TOP_OF_STACK %r11, 8
19195 + pax_force_retaddr
19196 ret $REST_SKIP /* pop extended registers */
19197 CFI_ENDPROC
19198 -END(stub_\func)
19199 +ENDPROC(stub_\func)
19200 .endm
19201
19202 FORK_LIKE clone
19203 @@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
19204 movq_cfi_restore R12+8, r12
19205 movq_cfi_restore RBP+8, rbp
19206 movq_cfi_restore RBX+8, rbx
19207 + pax_force_retaddr
19208 ret $REST_SKIP /* pop extended registers */
19209 CFI_ENDPROC
19210 -END(ptregscall_common)
19211 +ENDPROC(ptregscall_common)
19212
19213 ENTRY(stub_execve)
19214 CFI_STARTPROC
19215 @@ -891,7 +1191,7 @@ ENTRY(stub_execve)
19216 RESTORE_REST
19217 jmp int_ret_from_sys_call
19218 CFI_ENDPROC
19219 -END(stub_execve)
19220 +ENDPROC(stub_execve)
19221
19222 /*
19223 * sigreturn is special because it needs to restore all registers on return.
19224 @@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
19225 RESTORE_REST
19226 jmp int_ret_from_sys_call
19227 CFI_ENDPROC
19228 -END(stub_rt_sigreturn)
19229 +ENDPROC(stub_rt_sigreturn)
19230
19231 #ifdef CONFIG_X86_X32_ABI
19232 ENTRY(stub_x32_rt_sigreturn)
19233 @@ -975,7 +1275,7 @@ vector=vector+1
19234 2: jmp common_interrupt
19235 .endr
19236 CFI_ENDPROC
19237 -END(irq_entries_start)
19238 +ENDPROC(irq_entries_start)
19239
19240 .previous
19241 END(interrupt)
19242 @@ -995,6 +1295,16 @@ END(interrupt)
19243 subq $ORIG_RAX-RBP, %rsp
19244 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19245 SAVE_ARGS_IRQ
19246 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19247 + testb $3, CS(%rdi)
19248 + jnz 1f
19249 + pax_enter_kernel
19250 + jmp 2f
19251 +1: pax_enter_kernel_user
19252 +2:
19253 +#else
19254 + pax_enter_kernel
19255 +#endif
19256 call \func
19257 .endm
19258
19259 @@ -1027,7 +1337,7 @@ ret_from_intr:
19260
19261 exit_intr:
19262 GET_THREAD_INFO(%rcx)
19263 - testl $3,CS-ARGOFFSET(%rsp)
19264 + testb $3,CS-ARGOFFSET(%rsp)
19265 je retint_kernel
19266
19267 /* Interrupt came from user space */
19268 @@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
19269 * The iretq could re-enable interrupts:
19270 */
19271 DISABLE_INTERRUPTS(CLBR_ANY)
19272 + pax_exit_kernel_user
19273 +retint_swapgs_pax:
19274 TRACE_IRQS_IRETQ
19275 SWAPGS
19276 jmp restore_args
19277
19278 retint_restore_args: /* return to kernel space */
19279 DISABLE_INTERRUPTS(CLBR_ANY)
19280 + pax_exit_kernel
19281 + pax_force_retaddr (RIP-ARGOFFSET)
19282 /*
19283 * The iretq could re-enable interrupts:
19284 */
19285 @@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
19286 #endif
19287
19288 CFI_ENDPROC
19289 -END(common_interrupt)
19290 +ENDPROC(common_interrupt)
19291 /*
19292 * End of kprobes section
19293 */
19294 @@ -1155,7 +1469,7 @@ ENTRY(\sym)
19295 interrupt \do_sym
19296 jmp ret_from_intr
19297 CFI_ENDPROC
19298 -END(\sym)
19299 +ENDPROC(\sym)
19300 .endm
19301
19302 #ifdef CONFIG_SMP
19303 @@ -1211,12 +1525,22 @@ ENTRY(\sym)
19304 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19305 call error_entry
19306 DEFAULT_FRAME 0
19307 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19308 + testb $3, CS(%rsp)
19309 + jnz 1f
19310 + pax_enter_kernel
19311 + jmp 2f
19312 +1: pax_enter_kernel_user
19313 +2:
19314 +#else
19315 + pax_enter_kernel
19316 +#endif
19317 movq %rsp,%rdi /* pt_regs pointer */
19318 xorl %esi,%esi /* no error code */
19319 call \do_sym
19320 jmp error_exit /* %ebx: no swapgs flag */
19321 CFI_ENDPROC
19322 -END(\sym)
19323 +ENDPROC(\sym)
19324 .endm
19325
19326 .macro paranoidzeroentry sym do_sym
19327 @@ -1229,15 +1553,25 @@ ENTRY(\sym)
19328 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19329 call save_paranoid
19330 TRACE_IRQS_OFF
19331 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19332 + testb $3, CS(%rsp)
19333 + jnz 1f
19334 + pax_enter_kernel
19335 + jmp 2f
19336 +1: pax_enter_kernel_user
19337 +2:
19338 +#else
19339 + pax_enter_kernel
19340 +#endif
19341 movq %rsp,%rdi /* pt_regs pointer */
19342 xorl %esi,%esi /* no error code */
19343 call \do_sym
19344 jmp paranoid_exit /* %ebx: no swapgs flag */
19345 CFI_ENDPROC
19346 -END(\sym)
19347 +ENDPROC(\sym)
19348 .endm
19349
19350 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19351 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19352 .macro paranoidzeroentry_ist sym do_sym ist
19353 ENTRY(\sym)
19354 INTR_FRAME
19355 @@ -1248,14 +1582,30 @@ ENTRY(\sym)
19356 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19357 call save_paranoid
19358 TRACE_IRQS_OFF_DEBUG
19359 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19360 + testb $3, CS(%rsp)
19361 + jnz 1f
19362 + pax_enter_kernel
19363 + jmp 2f
19364 +1: pax_enter_kernel_user
19365 +2:
19366 +#else
19367 + pax_enter_kernel
19368 +#endif
19369 movq %rsp,%rdi /* pt_regs pointer */
19370 xorl %esi,%esi /* no error code */
19371 +#ifdef CONFIG_SMP
19372 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19373 + lea init_tss(%r12), %r12
19374 +#else
19375 + lea init_tss(%rip), %r12
19376 +#endif
19377 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19378 call \do_sym
19379 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19380 jmp paranoid_exit /* %ebx: no swapgs flag */
19381 CFI_ENDPROC
19382 -END(\sym)
19383 +ENDPROC(\sym)
19384 .endm
19385
19386 .macro errorentry sym do_sym
19387 @@ -1267,13 +1617,23 @@ ENTRY(\sym)
19388 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19389 call error_entry
19390 DEFAULT_FRAME 0
19391 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19392 + testb $3, CS(%rsp)
19393 + jnz 1f
19394 + pax_enter_kernel
19395 + jmp 2f
19396 +1: pax_enter_kernel_user
19397 +2:
19398 +#else
19399 + pax_enter_kernel
19400 +#endif
19401 movq %rsp,%rdi /* pt_regs pointer */
19402 movq ORIG_RAX(%rsp),%rsi /* get error code */
19403 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19404 call \do_sym
19405 jmp error_exit /* %ebx: no swapgs flag */
19406 CFI_ENDPROC
19407 -END(\sym)
19408 +ENDPROC(\sym)
19409 .endm
19410
19411 /* error code is on the stack already */
19412 @@ -1287,13 +1647,23 @@ ENTRY(\sym)
19413 call save_paranoid
19414 DEFAULT_FRAME 0
19415 TRACE_IRQS_OFF
19416 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19417 + testb $3, CS(%rsp)
19418 + jnz 1f
19419 + pax_enter_kernel
19420 + jmp 2f
19421 +1: pax_enter_kernel_user
19422 +2:
19423 +#else
19424 + pax_enter_kernel
19425 +#endif
19426 movq %rsp,%rdi /* pt_regs pointer */
19427 movq ORIG_RAX(%rsp),%rsi /* get error code */
19428 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19429 call \do_sym
19430 jmp paranoid_exit /* %ebx: no swapgs flag */
19431 CFI_ENDPROC
19432 -END(\sym)
19433 +ENDPROC(\sym)
19434 .endm
19435
19436 zeroentry divide_error do_divide_error
19437 @@ -1323,9 +1693,10 @@ gs_change:
19438 2: mfence /* workaround */
19439 SWAPGS
19440 popfq_cfi
19441 + pax_force_retaddr
19442 ret
19443 CFI_ENDPROC
19444 -END(native_load_gs_index)
19445 +ENDPROC(native_load_gs_index)
19446
19447 _ASM_EXTABLE(gs_change,bad_gs)
19448 .section .fixup,"ax"
19449 @@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
19450 CFI_DEF_CFA_REGISTER rsp
19451 CFI_ADJUST_CFA_OFFSET -8
19452 decl PER_CPU_VAR(irq_count)
19453 + pax_force_retaddr
19454 ret
19455 CFI_ENDPROC
19456 -END(call_softirq)
19457 +ENDPROC(call_softirq)
19458
19459 #ifdef CONFIG_XEN
19460 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19461 @@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19462 decl PER_CPU_VAR(irq_count)
19463 jmp error_exit
19464 CFI_ENDPROC
19465 -END(xen_do_hypervisor_callback)
19466 +ENDPROC(xen_do_hypervisor_callback)
19467
19468 /*
19469 * Hypervisor uses this for application faults while it executes.
19470 @@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
19471 SAVE_ALL
19472 jmp error_exit
19473 CFI_ENDPROC
19474 -END(xen_failsafe_callback)
19475 +ENDPROC(xen_failsafe_callback)
19476
19477 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
19478 xen_hvm_callback_vector xen_evtchn_do_upcall
19479 @@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
19480 TRACE_IRQS_OFF_DEBUG
19481 testl %ebx,%ebx /* swapgs needed? */
19482 jnz paranoid_restore
19483 - testl $3,CS(%rsp)
19484 + testb $3,CS(%rsp)
19485 jnz paranoid_userspace
19486 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19487 + pax_exit_kernel
19488 + TRACE_IRQS_IRETQ 0
19489 + SWAPGS_UNSAFE_STACK
19490 + RESTORE_ALL 8
19491 + pax_force_retaddr_bts
19492 + jmp irq_return
19493 +#endif
19494 paranoid_swapgs:
19495 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19496 + pax_exit_kernel_user
19497 +#else
19498 + pax_exit_kernel
19499 +#endif
19500 TRACE_IRQS_IRETQ 0
19501 SWAPGS_UNSAFE_STACK
19502 RESTORE_ALL 8
19503 jmp irq_return
19504 paranoid_restore:
19505 + pax_exit_kernel
19506 TRACE_IRQS_IRETQ_DEBUG 0
19507 RESTORE_ALL 8
19508 + pax_force_retaddr_bts
19509 jmp irq_return
19510 paranoid_userspace:
19511 GET_THREAD_INFO(%rcx)
19512 @@ -1539,7 +1926,7 @@ paranoid_schedule:
19513 TRACE_IRQS_OFF
19514 jmp paranoid_userspace
19515 CFI_ENDPROC
19516 -END(paranoid_exit)
19517 +ENDPROC(paranoid_exit)
19518
19519 /*
19520 * Exception entry point. This expects an error code/orig_rax on the stack.
19521 @@ -1566,12 +1953,13 @@ ENTRY(error_entry)
19522 movq_cfi r14, R14+8
19523 movq_cfi r15, R15+8
19524 xorl %ebx,%ebx
19525 - testl $3,CS+8(%rsp)
19526 + testb $3,CS+8(%rsp)
19527 je error_kernelspace
19528 error_swapgs:
19529 SWAPGS
19530 error_sti:
19531 TRACE_IRQS_OFF
19532 + pax_force_retaddr_bts
19533 ret
19534
19535 /*
19536 @@ -1598,7 +1986,7 @@ bstep_iret:
19537 movq %rcx,RIP+8(%rsp)
19538 jmp error_swapgs
19539 CFI_ENDPROC
19540 -END(error_entry)
19541 +ENDPROC(error_entry)
19542
19543
19544 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19545 @@ -1618,7 +2006,7 @@ ENTRY(error_exit)
19546 jnz retint_careful
19547 jmp retint_swapgs
19548 CFI_ENDPROC
19549 -END(error_exit)
19550 +ENDPROC(error_exit)
19551
19552 /*
19553 * Test if a given stack is an NMI stack or not.
19554 @@ -1676,9 +2064,11 @@ ENTRY(nmi)
19555 * If %cs was not the kernel segment, then the NMI triggered in user
19556 * space, which means it is definitely not nested.
19557 */
19558 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19559 + je 1f
19560 cmpl $__KERNEL_CS, 16(%rsp)
19561 jne first_nmi
19562 -
19563 +1:
19564 /*
19565 * Check the special variable on the stack to see if NMIs are
19566 * executing.
19567 @@ -1847,6 +2237,17 @@ end_repeat_nmi:
19568 */
19569 movq %cr2, %r12
19570
19571 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19572 + testb $3, CS(%rsp)
19573 + jnz 1f
19574 + pax_enter_kernel
19575 + jmp 2f
19576 +1: pax_enter_kernel_user
19577 +2:
19578 +#else
19579 + pax_enter_kernel
19580 +#endif
19581 +
19582 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19583 movq %rsp,%rdi
19584 movq $-1,%rsi
19585 @@ -1862,23 +2263,34 @@ end_repeat_nmi:
19586 testl %ebx,%ebx /* swapgs needed? */
19587 jnz nmi_restore
19588 nmi_swapgs:
19589 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19590 + pax_exit_kernel_user
19591 +#else
19592 + pax_exit_kernel
19593 +#endif
19594 SWAPGS_UNSAFE_STACK
19595 + RESTORE_ALL 6*8
19596 + /* Clear the NMI executing stack variable */
19597 + movq $0, 5*8(%rsp)
19598 + jmp irq_return
19599 nmi_restore:
19600 + pax_exit_kernel
19601 /* Pop the extra iret frame at once */
19602 RESTORE_ALL 6*8
19603 + pax_force_retaddr_bts
19604
19605 /* Clear the NMI executing stack variable */
19606 movq $0, 5*8(%rsp)
19607 jmp irq_return
19608 CFI_ENDPROC
19609 -END(nmi)
19610 +ENDPROC(nmi)
19611
19612 ENTRY(ignore_sysret)
19613 CFI_STARTPROC
19614 mov $-ENOSYS,%eax
19615 sysret
19616 CFI_ENDPROC
19617 -END(ignore_sysret)
19618 +ENDPROC(ignore_sysret)
19619
19620 /*
19621 * End of kprobes section
19622 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
19623 index 1d41402..af9a46a 100644
19624 --- a/arch/x86/kernel/ftrace.c
19625 +++ b/arch/x86/kernel/ftrace.c
19626 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
19627 {
19628 unsigned char replaced[MCOUNT_INSN_SIZE];
19629
19630 + ip = ktla_ktva(ip);
19631 +
19632 /*
19633 * Note: Due to modules and __init, code can
19634 * disappear and change, we need to protect against faulting
19635 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19636 unsigned char old[MCOUNT_INSN_SIZE], *new;
19637 int ret;
19638
19639 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
19640 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
19641 new = ftrace_call_replace(ip, (unsigned long)func);
19642
19643 /* See comment above by declaration of modifying_ftrace_code */
19644 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19645 /* Also update the regs callback function */
19646 if (!ret) {
19647 ip = (unsigned long)(&ftrace_regs_call);
19648 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
19649 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
19650 new = ftrace_call_replace(ip, (unsigned long)func);
19651 ret = ftrace_modify_code(ip, old, new);
19652 }
19653 @@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
19654 * kernel identity mapping to modify code.
19655 */
19656 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
19657 - ip = (unsigned long)__va(__pa(ip));
19658 + ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
19659
19660 return probe_kernel_write((void *)ip, val, size);
19661 }
19662 @@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
19663 unsigned char replaced[MCOUNT_INSN_SIZE];
19664 unsigned char brk = BREAKPOINT_INSTRUCTION;
19665
19666 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
19667 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
19668 return -EFAULT;
19669
19670 /* Make sure it is what we expect it to be */
19671 @@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
19672 return ret;
19673
19674 fail_update:
19675 - probe_kernel_write((void *)ip, &old_code[0], 1);
19676 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
19677 goto out;
19678 }
19679
19680 @@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
19681 {
19682 unsigned char code[MCOUNT_INSN_SIZE];
19683
19684 + ip = ktla_ktva(ip);
19685 +
19686 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
19687 return -EFAULT;
19688
19689 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
19690 index c18f59d..9c0c9f6 100644
19691 --- a/arch/x86/kernel/head32.c
19692 +++ b/arch/x86/kernel/head32.c
19693 @@ -18,6 +18,7 @@
19694 #include <asm/io_apic.h>
19695 #include <asm/bios_ebda.h>
19696 #include <asm/tlbflush.h>
19697 +#include <asm/boot.h>
19698
19699 static void __init i386_default_early_setup(void)
19700 {
19701 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
19702
19703 void __init i386_start_kernel(void)
19704 {
19705 - memblock_reserve(__pa_symbol(&_text),
19706 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
19707 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
19708
19709 #ifdef CONFIG_BLK_DEV_INITRD
19710 /* Reserve INITRD */
19711 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
19712 index c8932c7..d56b622 100644
19713 --- a/arch/x86/kernel/head_32.S
19714 +++ b/arch/x86/kernel/head_32.S
19715 @@ -26,6 +26,12 @@
19716 /* Physical address */
19717 #define pa(X) ((X) - __PAGE_OFFSET)
19718
19719 +#ifdef CONFIG_PAX_KERNEXEC
19720 +#define ta(X) (X)
19721 +#else
19722 +#define ta(X) ((X) - __PAGE_OFFSET)
19723 +#endif
19724 +
19725 /*
19726 * References to members of the new_cpu_data structure.
19727 */
19728 @@ -55,11 +61,7 @@
19729 * and small than max_low_pfn, otherwise will waste some page table entries
19730 */
19731
19732 -#if PTRS_PER_PMD > 1
19733 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
19734 -#else
19735 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
19736 -#endif
19737 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
19738
19739 /* Number of possible pages in the lowmem region */
19740 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
19741 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
19742 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19743
19744 /*
19745 + * Real beginning of normal "text" segment
19746 + */
19747 +ENTRY(stext)
19748 +ENTRY(_stext)
19749 +
19750 +/*
19751 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
19752 * %esi points to the real-mode code as a 32-bit pointer.
19753 * CS and DS must be 4 GB flat segments, but we don't depend on
19754 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19755 * can.
19756 */
19757 __HEAD
19758 +
19759 +#ifdef CONFIG_PAX_KERNEXEC
19760 + jmp startup_32
19761 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
19762 +.fill PAGE_SIZE-5,1,0xcc
19763 +#endif
19764 +
19765 ENTRY(startup_32)
19766 movl pa(stack_start),%ecx
19767
19768 @@ -106,6 +121,59 @@ ENTRY(startup_32)
19769 2:
19770 leal -__PAGE_OFFSET(%ecx),%esp
19771
19772 +#ifdef CONFIG_SMP
19773 + movl $pa(cpu_gdt_table),%edi
19774 + movl $__per_cpu_load,%eax
19775 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
19776 + rorl $16,%eax
19777 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
19778 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
19779 + movl $__per_cpu_end - 1,%eax
19780 + subl $__per_cpu_start,%eax
19781 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
19782 +#endif
19783 +
19784 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19785 + movl $NR_CPUS,%ecx
19786 + movl $pa(cpu_gdt_table),%edi
19787 +1:
19788 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
19789 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
19790 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
19791 + addl $PAGE_SIZE_asm,%edi
19792 + loop 1b
19793 +#endif
19794 +
19795 +#ifdef CONFIG_PAX_KERNEXEC
19796 + movl $pa(boot_gdt),%edi
19797 + movl $__LOAD_PHYSICAL_ADDR,%eax
19798 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
19799 + rorl $16,%eax
19800 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
19801 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
19802 + rorl $16,%eax
19803 +
19804 + ljmp $(__BOOT_CS),$1f
19805 +1:
19806 +
19807 + movl $NR_CPUS,%ecx
19808 + movl $pa(cpu_gdt_table),%edi
19809 + addl $__PAGE_OFFSET,%eax
19810 +1:
19811 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
19812 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
19813 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
19814 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
19815 + rorl $16,%eax
19816 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
19817 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
19818 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
19819 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
19820 + rorl $16,%eax
19821 + addl $PAGE_SIZE_asm,%edi
19822 + loop 1b
19823 +#endif
19824 +
19825 /*
19826 * Clear BSS first so that there are no surprises...
19827 */
19828 @@ -196,8 +264,11 @@ ENTRY(startup_32)
19829 movl %eax, pa(max_pfn_mapped)
19830
19831 /* Do early initialization of the fixmap area */
19832 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19833 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
19834 +#ifdef CONFIG_COMPAT_VDSO
19835 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
19836 +#else
19837 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
19838 +#endif
19839 #else /* Not PAE */
19840
19841 page_pde_offset = (__PAGE_OFFSET >> 20);
19842 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19843 movl %eax, pa(max_pfn_mapped)
19844
19845 /* Do early initialization of the fixmap area */
19846 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19847 - movl %eax,pa(initial_page_table+0xffc)
19848 +#ifdef CONFIG_COMPAT_VDSO
19849 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
19850 +#else
19851 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
19852 +#endif
19853 #endif
19854
19855 #ifdef CONFIG_PARAVIRT
19856 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19857 cmpl $num_subarch_entries, %eax
19858 jae bad_subarch
19859
19860 - movl pa(subarch_entries)(,%eax,4), %eax
19861 - subl $__PAGE_OFFSET, %eax
19862 - jmp *%eax
19863 + jmp *pa(subarch_entries)(,%eax,4)
19864
19865 bad_subarch:
19866 WEAK(lguest_entry)
19867 @@ -256,10 +328,10 @@ WEAK(xen_entry)
19868 __INITDATA
19869
19870 subarch_entries:
19871 - .long default_entry /* normal x86/PC */
19872 - .long lguest_entry /* lguest hypervisor */
19873 - .long xen_entry /* Xen hypervisor */
19874 - .long default_entry /* Moorestown MID */
19875 + .long ta(default_entry) /* normal x86/PC */
19876 + .long ta(lguest_entry) /* lguest hypervisor */
19877 + .long ta(xen_entry) /* Xen hypervisor */
19878 + .long ta(default_entry) /* Moorestown MID */
19879 num_subarch_entries = (. - subarch_entries) / 4
19880 .previous
19881 #else
19882 @@ -335,6 +407,7 @@ default_entry:
19883 movl pa(mmu_cr4_features),%eax
19884 movl %eax,%cr4
19885
19886 +#ifdef CONFIG_X86_PAE
19887 testb $X86_CR4_PAE, %al # check if PAE is enabled
19888 jz 6f
19889
19890 @@ -363,6 +436,9 @@ default_entry:
19891 /* Make changes effective */
19892 wrmsr
19893
19894 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
19895 +#endif
19896 +
19897 6:
19898
19899 /*
19900 @@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
19901 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
19902 movl %eax,%ss # after changing gdt.
19903
19904 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
19905 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
19906 movl %eax,%ds
19907 movl %eax,%es
19908
19909 movl $(__KERNEL_PERCPU), %eax
19910 movl %eax,%fs # set this cpu's percpu
19911
19912 +#ifdef CONFIG_CC_STACKPROTECTOR
19913 movl $(__KERNEL_STACK_CANARY),%eax
19914 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
19915 + movl $(__USER_DS),%eax
19916 +#else
19917 + xorl %eax,%eax
19918 +#endif
19919 movl %eax,%gs
19920
19921 xorl %eax,%eax # Clear LDT
19922 @@ -544,8 +626,11 @@ setup_once:
19923 * relocation. Manually set base address in stack canary
19924 * segment descriptor.
19925 */
19926 - movl $gdt_page,%eax
19927 + movl $cpu_gdt_table,%eax
19928 movl $stack_canary,%ecx
19929 +#ifdef CONFIG_SMP
19930 + addl $__per_cpu_load,%ecx
19931 +#endif
19932 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
19933 shrl $16, %ecx
19934 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
19935 @@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
19936 /* This is global to keep gas from relaxing the jumps */
19937 ENTRY(early_idt_handler)
19938 cld
19939 - cmpl $2,%ss:early_recursion_flag
19940 + cmpl $1,%ss:early_recursion_flag
19941 je hlt_loop
19942 incl %ss:early_recursion_flag
19943
19944 @@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
19945 pushl (20+6*4)(%esp) /* trapno */
19946 pushl $fault_msg
19947 call printk
19948 -#endif
19949 call dump_stack
19950 +#endif
19951 hlt_loop:
19952 hlt
19953 jmp hlt_loop
19954 @@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
19955 /* This is the default interrupt "handler" :-) */
19956 ALIGN
19957 ignore_int:
19958 - cld
19959 #ifdef CONFIG_PRINTK
19960 + cmpl $2,%ss:early_recursion_flag
19961 + je hlt_loop
19962 + incl %ss:early_recursion_flag
19963 + cld
19964 pushl %eax
19965 pushl %ecx
19966 pushl %edx
19967 @@ -644,9 +732,6 @@ ignore_int:
19968 movl $(__KERNEL_DS),%eax
19969 movl %eax,%ds
19970 movl %eax,%es
19971 - cmpl $2,early_recursion_flag
19972 - je hlt_loop
19973 - incl early_recursion_flag
19974 pushl 16(%esp)
19975 pushl 24(%esp)
19976 pushl 32(%esp)
19977 @@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
19978 /*
19979 * BSS section
19980 */
19981 -__PAGE_ALIGNED_BSS
19982 - .align PAGE_SIZE
19983 #ifdef CONFIG_X86_PAE
19984 +.section .initial_pg_pmd,"a",@progbits
19985 initial_pg_pmd:
19986 .fill 1024*KPMDS,4,0
19987 #else
19988 +.section .initial_page_table,"a",@progbits
19989 ENTRY(initial_page_table)
19990 .fill 1024,4,0
19991 #endif
19992 +.section .initial_pg_fixmap,"a",@progbits
19993 initial_pg_fixmap:
19994 .fill 1024,4,0
19995 +.section .empty_zero_page,"a",@progbits
19996 ENTRY(empty_zero_page)
19997 .fill 4096,1,0
19998 +.section .swapper_pg_dir,"a",@progbits
19999 ENTRY(swapper_pg_dir)
20000 +#ifdef CONFIG_X86_PAE
20001 + .fill 4,8,0
20002 +#else
20003 .fill 1024,4,0
20004 +#endif
20005 +
20006 +/*
20007 + * The IDT has to be page-aligned to simplify the Pentium
20008 + * F0 0F bug workaround.. We have a special link segment
20009 + * for this.
20010 + */
20011 +.section .idt,"a",@progbits
20012 +ENTRY(idt_table)
20013 + .fill 256,8,0
20014
20015 /*
20016 * This starts the data section.
20017 */
20018 #ifdef CONFIG_X86_PAE
20019 -__PAGE_ALIGNED_DATA
20020 - /* Page-aligned for the benefit of paravirt? */
20021 - .align PAGE_SIZE
20022 +.section .initial_page_table,"a",@progbits
20023 ENTRY(initial_page_table)
20024 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20025 # if KPMDS == 3
20026 @@ -721,12 +820,20 @@ ENTRY(initial_page_table)
20027 # error "Kernel PMDs should be 1, 2 or 3"
20028 # endif
20029 .align PAGE_SIZE /* needs to be page-sized too */
20030 +
20031 +#ifdef CONFIG_PAX_PER_CPU_PGD
20032 +ENTRY(cpu_pgd)
20033 + .rept NR_CPUS
20034 + .fill 4,8,0
20035 + .endr
20036 +#endif
20037 +
20038 #endif
20039
20040 .data
20041 .balign 4
20042 ENTRY(stack_start)
20043 - .long init_thread_union+THREAD_SIZE
20044 + .long init_thread_union+THREAD_SIZE-8
20045
20046 __INITRODATA
20047 int_msg:
20048 @@ -754,7 +861,7 @@ fault_msg:
20049 * segment size, and 32-bit linear address value:
20050 */
20051
20052 - .data
20053 +.section .rodata,"a",@progbits
20054 .globl boot_gdt_descr
20055 .globl idt_descr
20056
20057 @@ -763,7 +870,7 @@ fault_msg:
20058 .word 0 # 32 bit align gdt_desc.address
20059 boot_gdt_descr:
20060 .word __BOOT_DS+7
20061 - .long boot_gdt - __PAGE_OFFSET
20062 + .long pa(boot_gdt)
20063
20064 .word 0 # 32-bit align idt_desc.address
20065 idt_descr:
20066 @@ -774,7 +881,7 @@ idt_descr:
20067 .word 0 # 32 bit align gdt_desc.address
20068 ENTRY(early_gdt_descr)
20069 .word GDT_ENTRIES*8-1
20070 - .long gdt_page /* Overwritten for secondary CPUs */
20071 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
20072
20073 /*
20074 * The boot_gdt must mirror the equivalent in setup.S and is
20075 @@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
20076 .align L1_CACHE_BYTES
20077 ENTRY(boot_gdt)
20078 .fill GDT_ENTRY_BOOT_CS,8,0
20079 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20080 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20081 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20082 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20083 +
20084 + .align PAGE_SIZE_asm
20085 +ENTRY(cpu_gdt_table)
20086 + .rept NR_CPUS
20087 + .quad 0x0000000000000000 /* NULL descriptor */
20088 + .quad 0x0000000000000000 /* 0x0b reserved */
20089 + .quad 0x0000000000000000 /* 0x13 reserved */
20090 + .quad 0x0000000000000000 /* 0x1b reserved */
20091 +
20092 +#ifdef CONFIG_PAX_KERNEXEC
20093 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20094 +#else
20095 + .quad 0x0000000000000000 /* 0x20 unused */
20096 +#endif
20097 +
20098 + .quad 0x0000000000000000 /* 0x28 unused */
20099 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20100 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20101 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20102 + .quad 0x0000000000000000 /* 0x4b reserved */
20103 + .quad 0x0000000000000000 /* 0x53 reserved */
20104 + .quad 0x0000000000000000 /* 0x5b reserved */
20105 +
20106 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20107 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20108 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20109 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20110 +
20111 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20112 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20113 +
20114 + /*
20115 + * Segments used for calling PnP BIOS have byte granularity.
20116 + * The code segments and data segments have fixed 64k limits,
20117 + * the transfer segment sizes are set at run time.
20118 + */
20119 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
20120 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
20121 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
20122 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
20123 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
20124 +
20125 + /*
20126 + * The APM segments have byte granularity and their bases
20127 + * are set at run time. All have 64k limits.
20128 + */
20129 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20130 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20131 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
20132 +
20133 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20134 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20135 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20136 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20137 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20138 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20139 +
20140 + /* Be sure this is zeroed to avoid false validations in Xen */
20141 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20142 + .endr
20143 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20144 index 980053c..74d3b44 100644
20145 --- a/arch/x86/kernel/head_64.S
20146 +++ b/arch/x86/kernel/head_64.S
20147 @@ -20,6 +20,8 @@
20148 #include <asm/processor-flags.h>
20149 #include <asm/percpu.h>
20150 #include <asm/nops.h>
20151 +#include <asm/cpufeature.h>
20152 +#include <asm/alternative-asm.h>
20153
20154 #ifdef CONFIG_PARAVIRT
20155 #include <asm/asm-offsets.h>
20156 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20157 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20158 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20159 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20160 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
20161 +L3_VMALLOC_START = pud_index(VMALLOC_START)
20162 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
20163 +L3_VMALLOC_END = pud_index(VMALLOC_END)
20164 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20165 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20166
20167 .text
20168 __HEAD
20169 @@ -88,35 +96,23 @@ startup_64:
20170 */
20171 addq %rbp, init_level4_pgt + 0(%rip)
20172 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20173 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20174 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20175 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20176 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20177
20178 addq %rbp, level3_ident_pgt + 0(%rip)
20179 +#ifndef CONFIG_XEN
20180 + addq %rbp, level3_ident_pgt + 8(%rip)
20181 +#endif
20182
20183 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20184 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20185 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20186 +
20187 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20188 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
20189
20190 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20191 -
20192 - /* Add an Identity mapping if I am above 1G */
20193 - leaq _text(%rip), %rdi
20194 - andq $PMD_PAGE_MASK, %rdi
20195 -
20196 - movq %rdi, %rax
20197 - shrq $PUD_SHIFT, %rax
20198 - andq $(PTRS_PER_PUD - 1), %rax
20199 - jz ident_complete
20200 -
20201 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
20202 - leaq level3_ident_pgt(%rip), %rbx
20203 - movq %rdx, 0(%rbx, %rax, 8)
20204 -
20205 - movq %rdi, %rax
20206 - shrq $PMD_SHIFT, %rax
20207 - andq $(PTRS_PER_PMD - 1), %rax
20208 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
20209 - leaq level2_spare_pgt(%rip), %rbx
20210 - movq %rdx, 0(%rbx, %rax, 8)
20211 -ident_complete:
20212 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20213
20214 /*
20215 * Fixup the kernel text+data virtual addresses. Note that
20216 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
20217 * after the boot processor executes this code.
20218 */
20219
20220 - /* Enable PAE mode and PGE */
20221 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
20222 + /* Enable PAE mode and PSE/PGE */
20223 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
20224 movq %rax, %cr4
20225
20226 /* Setup early boot stage 4 level pagetables. */
20227 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
20228 movl $MSR_EFER, %ecx
20229 rdmsr
20230 btsl $_EFER_SCE, %eax /* Enable System Call */
20231 - btl $20,%edi /* No Execute supported? */
20232 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20233 jnc 1f
20234 btsl $_EFER_NX, %eax
20235 + leaq init_level4_pgt(%rip), %rdi
20236 +#ifndef CONFIG_EFI
20237 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20238 +#endif
20239 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20240 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20241 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20242 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20243 1: wrmsr /* Make changes effective */
20244
20245 /* Setup cr0 */
20246 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
20247 * jump. In addition we need to ensure %cs is set so we make this
20248 * a far return.
20249 */
20250 + pax_set_fptr_mask
20251 movq initial_code(%rip),%rax
20252 pushq $0 # fake return address to stop unwinder
20253 pushq $__KERNEL_CS # set correct cs
20254 @@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
20255 bad_address:
20256 jmp bad_address
20257
20258 - .section ".init.text","ax"
20259 + __INIT
20260 .globl early_idt_handlers
20261 early_idt_handlers:
20262 # 104(%rsp) %rflags
20263 @@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
20264 call dump_stack
20265 #ifdef CONFIG_KALLSYMS
20266 leaq early_idt_ripmsg(%rip),%rdi
20267 - movq 40(%rsp),%rsi # %rip again
20268 + movq 88(%rsp),%rsi # %rip again
20269 call __print_symbol
20270 #endif
20271 #endif /* EARLY_PRINTK */
20272 @@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
20273 addq $16,%rsp # drop vector number and error code
20274 decl early_recursion_flag(%rip)
20275 INTERRUPT_RETURN
20276 + .previous
20277
20278 + __INITDATA
20279 .balign 4
20280 early_recursion_flag:
20281 .long 0
20282 + .previous
20283
20284 + .section .rodata,"a",@progbits
20285 #ifdef CONFIG_EARLY_PRINTK
20286 early_idt_msg:
20287 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20288 @@ -376,6 +385,7 @@ early_idt_ripmsg:
20289 #endif /* CONFIG_EARLY_PRINTK */
20290 .previous
20291
20292 + .section .rodata,"a",@progbits
20293 #define NEXT_PAGE(name) \
20294 .balign PAGE_SIZE; \
20295 ENTRY(name)
20296 @@ -388,7 +398,6 @@ ENTRY(name)
20297 i = i + 1 ; \
20298 .endr
20299
20300 - .data
20301 /*
20302 * This default setting generates an ident mapping at address 0x100000
20303 * and a mapping for the kernel that precisely maps virtual address
20304 @@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
20305 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20306 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20307 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20308 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
20309 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20310 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
20311 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20312 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20313 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20314 .org init_level4_pgt + L4_START_KERNEL*8, 0
20315 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20316 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20317
20318 +#ifdef CONFIG_PAX_PER_CPU_PGD
20319 +NEXT_PAGE(cpu_pgd)
20320 + .rept NR_CPUS
20321 + .fill 512,8,0
20322 + .endr
20323 +#endif
20324 +
20325 NEXT_PAGE(level3_ident_pgt)
20326 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20327 +#ifdef CONFIG_XEN
20328 .fill 511,8,0
20329 +#else
20330 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20331 + .fill 510,8,0
20332 +#endif
20333 +
20334 +NEXT_PAGE(level3_vmalloc_start_pgt)
20335 + .fill 512,8,0
20336 +
20337 +NEXT_PAGE(level3_vmalloc_end_pgt)
20338 + .fill 512,8,0
20339 +
20340 +NEXT_PAGE(level3_vmemmap_pgt)
20341 + .fill L3_VMEMMAP_START,8,0
20342 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20343
20344 NEXT_PAGE(level3_kernel_pgt)
20345 .fill L3_START_KERNEL,8,0
20346 @@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
20347 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20348 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20349
20350 +NEXT_PAGE(level2_vmemmap_pgt)
20351 + .fill 512,8,0
20352 +
20353 NEXT_PAGE(level2_fixmap_pgt)
20354 - .fill 506,8,0
20355 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20356 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20357 - .fill 5,8,0
20358 + .fill 507,8,0
20359 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20360 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20361 + .fill 4,8,0
20362
20363 -NEXT_PAGE(level1_fixmap_pgt)
20364 +NEXT_PAGE(level1_vsyscall_pgt)
20365 .fill 512,8,0
20366
20367 -NEXT_PAGE(level2_ident_pgt)
20368 - /* Since I easily can, map the first 1G.
20369 + /* Since I easily can, map the first 2G.
20370 * Don't set NX because code runs from these pages.
20371 */
20372 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20373 +NEXT_PAGE(level2_ident_pgt)
20374 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20375
20376 NEXT_PAGE(level2_kernel_pgt)
20377 /*
20378 @@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
20379 * If you want to increase this then increase MODULES_VADDR
20380 * too.)
20381 */
20382 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
20383 - KERNEL_IMAGE_SIZE/PMD_SIZE)
20384 -
20385 -NEXT_PAGE(level2_spare_pgt)
20386 - .fill 512, 8, 0
20387 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
20388
20389 #undef PMDS
20390 #undef NEXT_PAGE
20391
20392 - .data
20393 + .align PAGE_SIZE
20394 +ENTRY(cpu_gdt_table)
20395 + .rept NR_CPUS
20396 + .quad 0x0000000000000000 /* NULL descriptor */
20397 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20398 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
20399 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
20400 + .quad 0x00cffb000000ffff /* __USER32_CS */
20401 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20402 + .quad 0x00affb000000ffff /* __USER_CS */
20403 +
20404 +#ifdef CONFIG_PAX_KERNEXEC
20405 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20406 +#else
20407 + .quad 0x0 /* unused */
20408 +#endif
20409 +
20410 + .quad 0,0 /* TSS */
20411 + .quad 0,0 /* LDT */
20412 + .quad 0,0,0 /* three TLS descriptors */
20413 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
20414 + /* asm/segment.h:GDT_ENTRIES must match this */
20415 +
20416 + /* zero the remaining page */
20417 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20418 + .endr
20419 +
20420 .align 16
20421 .globl early_gdt_descr
20422 early_gdt_descr:
20423 .word GDT_ENTRIES*8-1
20424 early_gdt_descr_base:
20425 - .quad INIT_PER_CPU_VAR(gdt_page)
20426 + .quad cpu_gdt_table
20427
20428 ENTRY(phys_base)
20429 /* This must match the first entry in level2_kernel_pgt */
20430 .quad 0x0000000000000000
20431
20432 #include "../../x86/xen/xen-head.S"
20433 -
20434 - .section .bss, "aw", @nobits
20435 +
20436 + .section .rodata,"a",@progbits
20437 .align L1_CACHE_BYTES
20438 ENTRY(idt_table)
20439 - .skip IDT_ENTRIES * 16
20440 + .fill 512,8,0
20441
20442 .align L1_CACHE_BYTES
20443 ENTRY(nmi_idt_table)
20444 - .skip IDT_ENTRIES * 16
20445 + .fill 512,8,0
20446
20447 __PAGE_ALIGNED_BSS
20448 .align PAGE_SIZE
20449 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20450 index 9c3bd4a..e1d9b35 100644
20451 --- a/arch/x86/kernel/i386_ksyms_32.c
20452 +++ b/arch/x86/kernel/i386_ksyms_32.c
20453 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20454 EXPORT_SYMBOL(cmpxchg8b_emu);
20455 #endif
20456
20457 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
20458 +
20459 /* Networking helper routines. */
20460 EXPORT_SYMBOL(csum_partial_copy_generic);
20461 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20462 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20463
20464 EXPORT_SYMBOL(__get_user_1);
20465 EXPORT_SYMBOL(__get_user_2);
20466 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
20467
20468 EXPORT_SYMBOL(csum_partial);
20469 EXPORT_SYMBOL(empty_zero_page);
20470 +
20471 +#ifdef CONFIG_PAX_KERNEXEC
20472 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20473 +#endif
20474 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20475 index 245a71d..89d9ce4 100644
20476 --- a/arch/x86/kernel/i387.c
20477 +++ b/arch/x86/kernel/i387.c
20478 @@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20479 static inline bool interrupted_user_mode(void)
20480 {
20481 struct pt_regs *regs = get_irq_regs();
20482 - return regs && user_mode_vm(regs);
20483 + return regs && user_mode(regs);
20484 }
20485
20486 /*
20487 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20488 index 9a5c460..b332a4b 100644
20489 --- a/arch/x86/kernel/i8259.c
20490 +++ b/arch/x86/kernel/i8259.c
20491 @@ -209,7 +209,7 @@ spurious_8259A_irq:
20492 "spurious 8259A interrupt: IRQ%d.\n", irq);
20493 spurious_irq_mask |= irqmask;
20494 }
20495 - atomic_inc(&irq_err_count);
20496 + atomic_inc_unchecked(&irq_err_count);
20497 /*
20498 * Theoretically we do not have to handle this IRQ,
20499 * but in Linux this does not cause problems and is
20500 @@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20501 /* (slave's support for AEOI in flat mode is to be investigated) */
20502 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20503
20504 + pax_open_kernel();
20505 if (auto_eoi)
20506 /*
20507 * In AEOI mode we just have to mask the interrupt
20508 * when acking.
20509 */
20510 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
20511 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20512 else
20513 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20514 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20515 + pax_close_kernel();
20516
20517 udelay(100); /* wait for 8259A to initialize */
20518
20519 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20520 index a979b5b..1d6db75 100644
20521 --- a/arch/x86/kernel/io_delay.c
20522 +++ b/arch/x86/kernel/io_delay.c
20523 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20524 * Quirk table for systems that misbehave (lock up, etc.) if port
20525 * 0x80 is used:
20526 */
20527 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20528 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20529 {
20530 .callback = dmi_io_delay_0xed_port,
20531 .ident = "Compaq Presario V6000",
20532 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20533 index 8c96897..be66bfa 100644
20534 --- a/arch/x86/kernel/ioport.c
20535 +++ b/arch/x86/kernel/ioport.c
20536 @@ -6,6 +6,7 @@
20537 #include <linux/sched.h>
20538 #include <linux/kernel.h>
20539 #include <linux/capability.h>
20540 +#include <linux/security.h>
20541 #include <linux/errno.h>
20542 #include <linux/types.h>
20543 #include <linux/ioport.h>
20544 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20545
20546 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20547 return -EINVAL;
20548 +#ifdef CONFIG_GRKERNSEC_IO
20549 + if (turn_on && grsec_disable_privio) {
20550 + gr_handle_ioperm();
20551 + return -EPERM;
20552 + }
20553 +#endif
20554 if (turn_on && !capable(CAP_SYS_RAWIO))
20555 return -EPERM;
20556
20557 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20558 * because the ->io_bitmap_max value must match the bitmap
20559 * contents:
20560 */
20561 - tss = &per_cpu(init_tss, get_cpu());
20562 + tss = init_tss + get_cpu();
20563
20564 if (turn_on)
20565 bitmap_clear(t->io_bitmap_ptr, from, num);
20566 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
20567 return -EINVAL;
20568 /* Trying to gain more privileges? */
20569 if (level > old) {
20570 +#ifdef CONFIG_GRKERNSEC_IO
20571 + if (grsec_disable_privio) {
20572 + gr_handle_iopl();
20573 + return -EPERM;
20574 + }
20575 +#endif
20576 if (!capable(CAP_SYS_RAWIO))
20577 return -EPERM;
20578 }
20579 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20580 index e4595f1..ee3bfb8 100644
20581 --- a/arch/x86/kernel/irq.c
20582 +++ b/arch/x86/kernel/irq.c
20583 @@ -18,7 +18,7 @@
20584 #include <asm/mce.h>
20585 #include <asm/hw_irq.h>
20586
20587 -atomic_t irq_err_count;
20588 +atomic_unchecked_t irq_err_count;
20589
20590 /* Function pointer for generic interrupt vector handling */
20591 void (*x86_platform_ipi_callback)(void) = NULL;
20592 @@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20593 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20594 seq_printf(p, " Machine check polls\n");
20595 #endif
20596 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20597 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20598 #if defined(CONFIG_X86_IO_APIC)
20599 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20600 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20601 #endif
20602 return 0;
20603 }
20604 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20605
20606 u64 arch_irq_stat(void)
20607 {
20608 - u64 sum = atomic_read(&irq_err_count);
20609 + u64 sum = atomic_read_unchecked(&irq_err_count);
20610
20611 #ifdef CONFIG_X86_IO_APIC
20612 - sum += atomic_read(&irq_mis_count);
20613 + sum += atomic_read_unchecked(&irq_mis_count);
20614 #endif
20615 return sum;
20616 }
20617 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20618 index 344faf8..355f60d 100644
20619 --- a/arch/x86/kernel/irq_32.c
20620 +++ b/arch/x86/kernel/irq_32.c
20621 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20622 __asm__ __volatile__("andl %%esp,%0" :
20623 "=r" (sp) : "0" (THREAD_SIZE - 1));
20624
20625 - return sp < (sizeof(struct thread_info) + STACK_WARN);
20626 + return sp < STACK_WARN;
20627 }
20628
20629 static void print_stack_overflow(void)
20630 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20631 * per-CPU IRQ handling contexts (thread information and stack)
20632 */
20633 union irq_ctx {
20634 - struct thread_info tinfo;
20635 - u32 stack[THREAD_SIZE/sizeof(u32)];
20636 + unsigned long previous_esp;
20637 + u32 stack[THREAD_SIZE/sizeof(u32)];
20638 } __attribute__((aligned(THREAD_SIZE)));
20639
20640 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
20641 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
20642 static inline int
20643 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20644 {
20645 - union irq_ctx *curctx, *irqctx;
20646 + union irq_ctx *irqctx;
20647 u32 *isp, arg1, arg2;
20648
20649 - curctx = (union irq_ctx *) current_thread_info();
20650 irqctx = __this_cpu_read(hardirq_ctx);
20651
20652 /*
20653 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20654 * handler) we can't do that and just have to keep using the
20655 * current stack (which is the irq stack already after all)
20656 */
20657 - if (unlikely(curctx == irqctx))
20658 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
20659 return 0;
20660
20661 /* build the stack frame on the IRQ stack */
20662 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20663 - irqctx->tinfo.task = curctx->tinfo.task;
20664 - irqctx->tinfo.previous_esp = current_stack_pointer;
20665 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20666 + irqctx->previous_esp = current_stack_pointer;
20667
20668 - /* Copy the preempt_count so that the [soft]irq checks work. */
20669 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
20670 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20671 + __set_fs(MAKE_MM_SEG(0));
20672 +#endif
20673
20674 if (unlikely(overflow))
20675 call_on_stack(print_stack_overflow, isp);
20676 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20677 : "0" (irq), "1" (desc), "2" (isp),
20678 "D" (desc->handle_irq)
20679 : "memory", "cc", "ecx");
20680 +
20681 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20682 + __set_fs(current_thread_info()->addr_limit);
20683 +#endif
20684 +
20685 return 1;
20686 }
20687
20688 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20689 */
20690 void __cpuinit irq_ctx_init(int cpu)
20691 {
20692 - union irq_ctx *irqctx;
20693 -
20694 if (per_cpu(hardirq_ctx, cpu))
20695 return;
20696
20697 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20698 - THREADINFO_GFP,
20699 - THREAD_SIZE_ORDER));
20700 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20701 - irqctx->tinfo.cpu = cpu;
20702 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
20703 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20704 -
20705 - per_cpu(hardirq_ctx, cpu) = irqctx;
20706 -
20707 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20708 - THREADINFO_GFP,
20709 - THREAD_SIZE_ORDER));
20710 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20711 - irqctx->tinfo.cpu = cpu;
20712 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20713 -
20714 - per_cpu(softirq_ctx, cpu) = irqctx;
20715 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20716 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20717 +
20718 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20719 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20720
20721 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20722 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20723 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
20724 asmlinkage void do_softirq(void)
20725 {
20726 unsigned long flags;
20727 - struct thread_info *curctx;
20728 union irq_ctx *irqctx;
20729 u32 *isp;
20730
20731 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
20732 local_irq_save(flags);
20733
20734 if (local_softirq_pending()) {
20735 - curctx = current_thread_info();
20736 irqctx = __this_cpu_read(softirq_ctx);
20737 - irqctx->tinfo.task = curctx->task;
20738 - irqctx->tinfo.previous_esp = current_stack_pointer;
20739 + irqctx->previous_esp = current_stack_pointer;
20740
20741 /* build the stack frame on the softirq stack */
20742 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20743 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20744 +
20745 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20746 + __set_fs(MAKE_MM_SEG(0));
20747 +#endif
20748
20749 call_on_stack(__do_softirq, isp);
20750 +
20751 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20752 + __set_fs(current_thread_info()->addr_limit);
20753 +#endif
20754 +
20755 /*
20756 * Shouldn't happen, we returned above if in_interrupt():
20757 */
20758 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
20759 if (unlikely(!desc))
20760 return false;
20761
20762 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20763 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20764 if (unlikely(overflow))
20765 print_stack_overflow();
20766 desc->handle_irq(irq, desc);
20767 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
20768 index d04d3ec..ea4b374 100644
20769 --- a/arch/x86/kernel/irq_64.c
20770 +++ b/arch/x86/kernel/irq_64.c
20771 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
20772 u64 estack_top, estack_bottom;
20773 u64 curbase = (u64)task_stack_page(current);
20774
20775 - if (user_mode_vm(regs))
20776 + if (user_mode(regs))
20777 return;
20778
20779 if (regs->sp >= curbase + sizeof(struct thread_info) +
20780 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
20781 index dc1404b..bbc43e7 100644
20782 --- a/arch/x86/kernel/kdebugfs.c
20783 +++ b/arch/x86/kernel/kdebugfs.c
20784 @@ -27,7 +27,7 @@ struct setup_data_node {
20785 u32 len;
20786 };
20787
20788 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
20789 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
20790 size_t count, loff_t *ppos)
20791 {
20792 struct setup_data_node *node = file->private_data;
20793 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
20794 index 836f832..a8bda67 100644
20795 --- a/arch/x86/kernel/kgdb.c
20796 +++ b/arch/x86/kernel/kgdb.c
20797 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
20798 #ifdef CONFIG_X86_32
20799 switch (regno) {
20800 case GDB_SS:
20801 - if (!user_mode_vm(regs))
20802 + if (!user_mode(regs))
20803 *(unsigned long *)mem = __KERNEL_DS;
20804 break;
20805 case GDB_SP:
20806 - if (!user_mode_vm(regs))
20807 + if (!user_mode(regs))
20808 *(unsigned long *)mem = kernel_stack_pointer(regs);
20809 break;
20810 case GDB_GS:
20811 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
20812 bp->attr.bp_addr = breakinfo[breakno].addr;
20813 bp->attr.bp_len = breakinfo[breakno].len;
20814 bp->attr.bp_type = breakinfo[breakno].type;
20815 - info->address = breakinfo[breakno].addr;
20816 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
20817 + info->address = ktla_ktva(breakinfo[breakno].addr);
20818 + else
20819 + info->address = breakinfo[breakno].addr;
20820 info->len = breakinfo[breakno].len;
20821 info->type = breakinfo[breakno].type;
20822 val = arch_install_hw_breakpoint(bp);
20823 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
20824 case 'k':
20825 /* clear the trace bit */
20826 linux_regs->flags &= ~X86_EFLAGS_TF;
20827 - atomic_set(&kgdb_cpu_doing_single_step, -1);
20828 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
20829
20830 /* set the trace bit if we're stepping */
20831 if (remcomInBuffer[0] == 's') {
20832 linux_regs->flags |= X86_EFLAGS_TF;
20833 - atomic_set(&kgdb_cpu_doing_single_step,
20834 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
20835 raw_smp_processor_id());
20836 }
20837
20838 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
20839
20840 switch (cmd) {
20841 case DIE_DEBUG:
20842 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
20843 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
20844 if (user_mode(regs))
20845 return single_step_cont(regs, args);
20846 break;
20847 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20848 #endif /* CONFIG_DEBUG_RODATA */
20849
20850 bpt->type = BP_BREAKPOINT;
20851 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
20852 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
20853 BREAK_INSTR_SIZE);
20854 if (err)
20855 return err;
20856 - err = probe_kernel_write((char *)bpt->bpt_addr,
20857 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20858 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
20859 #ifdef CONFIG_DEBUG_RODATA
20860 if (!err)
20861 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20862 return -EBUSY;
20863 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
20864 BREAK_INSTR_SIZE);
20865 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20866 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20867 if (err)
20868 return err;
20869 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
20870 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
20871 if (mutex_is_locked(&text_mutex))
20872 goto knl_write;
20873 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
20874 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20875 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20876 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
20877 goto knl_write;
20878 return err;
20879 knl_write:
20880 #endif /* CONFIG_DEBUG_RODATA */
20881 - return probe_kernel_write((char *)bpt->bpt_addr,
20882 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20883 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
20884 }
20885
20886 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
20887 index c5e410e..ed5a7f0 100644
20888 --- a/arch/x86/kernel/kprobes-opt.c
20889 +++ b/arch/x86/kernel/kprobes-opt.c
20890 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20891 * Verify if the address gap is in 2GB range, because this uses
20892 * a relative jump.
20893 */
20894 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
20895 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
20896 if (abs(rel) > 0x7fffffff)
20897 return -ERANGE;
20898
20899 @@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20900 op->optinsn.size = ret;
20901
20902 /* Copy arch-dep-instance from template */
20903 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
20904 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
20905
20906 /* Set probe information */
20907 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
20908
20909 /* Set probe function call */
20910 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
20911 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
20912
20913 /* Set returning jmp instruction at the tail of out-of-line buffer */
20914 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
20915 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
20916 (u8 *)op->kp.addr + op->optinsn.size);
20917
20918 flush_icache_range((unsigned long) buf,
20919 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
20920 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
20921
20922 /* Backup instructions which will be replaced by jump address */
20923 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
20924 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
20925 RELATIVE_ADDR_SIZE);
20926
20927 insn_buf[0] = RELATIVEJUMP_OPCODE;
20928 @@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
20929 /* This kprobe is really able to run optimized path. */
20930 op = container_of(p, struct optimized_kprobe, kp);
20931 /* Detour through copied instructions */
20932 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
20933 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
20934 if (!reenter)
20935 reset_current_kprobe();
20936 preempt_enable_no_resched();
20937 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
20938 index 57916c0..9e0b9d0 100644
20939 --- a/arch/x86/kernel/kprobes.c
20940 +++ b/arch/x86/kernel/kprobes.c
20941 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
20942 s32 raddr;
20943 } __attribute__((packed)) *insn;
20944
20945 - insn = (struct __arch_relative_insn *)from;
20946 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
20947 +
20948 + pax_open_kernel();
20949 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
20950 insn->op = op;
20951 + pax_close_kernel();
20952 }
20953
20954 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
20955 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
20956 kprobe_opcode_t opcode;
20957 kprobe_opcode_t *orig_opcodes = opcodes;
20958
20959 - if (search_exception_tables((unsigned long)opcodes))
20960 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
20961 return 0; /* Page fault may occur on this address. */
20962
20963 retry:
20964 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
20965 * for the first byte, we can recover the original instruction
20966 * from it and kp->opcode.
20967 */
20968 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20969 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20970 buf[0] = kp->opcode;
20971 - return (unsigned long)buf;
20972 + return ktva_ktla((unsigned long)buf);
20973 }
20974
20975 /*
20976 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20977 /* Another subsystem puts a breakpoint, failed to recover */
20978 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
20979 return 0;
20980 + pax_open_kernel();
20981 memcpy(dest, insn.kaddr, insn.length);
20982 + pax_close_kernel();
20983
20984 #ifdef CONFIG_X86_64
20985 if (insn_rip_relative(&insn)) {
20986 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20987 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
20988 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
20989 disp = (u8 *) dest + insn_offset_displacement(&insn);
20990 + pax_open_kernel();
20991 *(s32 *) disp = (s32) newdisp;
20992 + pax_close_kernel();
20993 }
20994 #endif
20995 return insn.length;
20996 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20997 * nor set current_kprobe, because it doesn't use single
20998 * stepping.
20999 */
21000 - regs->ip = (unsigned long)p->ainsn.insn;
21001 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21002 preempt_enable_no_resched();
21003 return;
21004 }
21005 @@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21006 regs->flags &= ~X86_EFLAGS_IF;
21007 /* single step inline if the instruction is an int3 */
21008 if (p->opcode == BREAKPOINT_INSTRUCTION)
21009 - regs->ip = (unsigned long)p->addr;
21010 + regs->ip = ktla_ktva((unsigned long)p->addr);
21011 else
21012 - regs->ip = (unsigned long)p->ainsn.insn;
21013 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21014 }
21015
21016 /*
21017 @@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21018 setup_singlestep(p, regs, kcb, 0);
21019 return 1;
21020 }
21021 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
21022 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21023 /*
21024 * The breakpoint instruction was removed right
21025 * after we hit it. Another cpu has removed
21026 @@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21027 " movq %rax, 152(%rsp)\n"
21028 RESTORE_REGS_STRING
21029 " popfq\n"
21030 +#ifdef KERNEXEC_PLUGIN
21031 + " btsq $63,(%rsp)\n"
21032 +#endif
21033 #else
21034 " pushf\n"
21035 SAVE_REGS_STRING
21036 @@ -788,7 +798,7 @@ static void __kprobes
21037 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21038 {
21039 unsigned long *tos = stack_addr(regs);
21040 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21041 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21042 unsigned long orig_ip = (unsigned long)p->addr;
21043 kprobe_opcode_t *insn = p->ainsn.insn;
21044
21045 @@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21046 struct die_args *args = data;
21047 int ret = NOTIFY_DONE;
21048
21049 - if (args->regs && user_mode_vm(args->regs))
21050 + if (args->regs && user_mode(args->regs))
21051 return ret;
21052
21053 switch (val) {
21054 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21055 index 9c2bd8b..bb1131c 100644
21056 --- a/arch/x86/kernel/kvm.c
21057 +++ b/arch/x86/kernel/kvm.c
21058 @@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21059 return NOTIFY_OK;
21060 }
21061
21062 -static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21063 +static struct notifier_block kvm_cpu_notifier = {
21064 .notifier_call = kvm_cpu_notify,
21065 };
21066 #endif
21067 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21068 index ebc9873..1b9724b 100644
21069 --- a/arch/x86/kernel/ldt.c
21070 +++ b/arch/x86/kernel/ldt.c
21071 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21072 if (reload) {
21073 #ifdef CONFIG_SMP
21074 preempt_disable();
21075 - load_LDT(pc);
21076 + load_LDT_nolock(pc);
21077 if (!cpumask_equal(mm_cpumask(current->mm),
21078 cpumask_of(smp_processor_id())))
21079 smp_call_function(flush_ldt, current->mm, 1);
21080 preempt_enable();
21081 #else
21082 - load_LDT(pc);
21083 + load_LDT_nolock(pc);
21084 #endif
21085 }
21086 if (oldsize) {
21087 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21088 return err;
21089
21090 for (i = 0; i < old->size; i++)
21091 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21092 + write_ldt_entry(new->ldt, i, old->ldt + i);
21093 return 0;
21094 }
21095
21096 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21097 retval = copy_ldt(&mm->context, &old_mm->context);
21098 mutex_unlock(&old_mm->context.lock);
21099 }
21100 +
21101 + if (tsk == current) {
21102 + mm->context.vdso = 0;
21103 +
21104 +#ifdef CONFIG_X86_32
21105 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21106 + mm->context.user_cs_base = 0UL;
21107 + mm->context.user_cs_limit = ~0UL;
21108 +
21109 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21110 + cpus_clear(mm->context.cpu_user_cs_mask);
21111 +#endif
21112 +
21113 +#endif
21114 +#endif
21115 +
21116 + }
21117 +
21118 return retval;
21119 }
21120
21121 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21122 }
21123 }
21124
21125 +#ifdef CONFIG_PAX_SEGMEXEC
21126 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21127 + error = -EINVAL;
21128 + goto out_unlock;
21129 + }
21130 +#endif
21131 +
21132 fill_ldt(&ldt, &ldt_info);
21133 if (oldmode)
21134 ldt.avl = 0;
21135 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21136 index 5b19e4d..6476a76 100644
21137 --- a/arch/x86/kernel/machine_kexec_32.c
21138 +++ b/arch/x86/kernel/machine_kexec_32.c
21139 @@ -26,7 +26,7 @@
21140 #include <asm/cacheflush.h>
21141 #include <asm/debugreg.h>
21142
21143 -static void set_idt(void *newidt, __u16 limit)
21144 +static void set_idt(struct desc_struct *newidt, __u16 limit)
21145 {
21146 struct desc_ptr curidt;
21147
21148 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21149 }
21150
21151
21152 -static void set_gdt(void *newgdt, __u16 limit)
21153 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21154 {
21155 struct desc_ptr curgdt;
21156
21157 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21158 }
21159
21160 control_page = page_address(image->control_code_page);
21161 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21162 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21163
21164 relocate_kernel_ptr = control_page;
21165 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21166 diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21167 index 3a04b22..1d2eb09 100644
21168 --- a/arch/x86/kernel/microcode_core.c
21169 +++ b/arch/x86/kernel/microcode_core.c
21170 @@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21171 return NOTIFY_OK;
21172 }
21173
21174 -static struct notifier_block __refdata mc_cpu_notifier = {
21175 +static struct notifier_block mc_cpu_notifier = {
21176 .notifier_call = mc_cpu_callback,
21177 };
21178
21179 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21180 index 3544aed..01ddc1c 100644
21181 --- a/arch/x86/kernel/microcode_intel.c
21182 +++ b/arch/x86/kernel/microcode_intel.c
21183 @@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21184
21185 static int get_ucode_user(void *to, const void *from, size_t n)
21186 {
21187 - return copy_from_user(to, from, n);
21188 + return copy_from_user(to, (const void __force_user *)from, n);
21189 }
21190
21191 static enum ucode_state
21192 request_microcode_user(int cpu, const void __user *buf, size_t size)
21193 {
21194 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21195 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21196 }
21197
21198 static void microcode_fini_cpu(int cpu)
21199 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21200 index 216a4d7..228255a 100644
21201 --- a/arch/x86/kernel/module.c
21202 +++ b/arch/x86/kernel/module.c
21203 @@ -43,15 +43,60 @@ do { \
21204 } while (0)
21205 #endif
21206
21207 -void *module_alloc(unsigned long size)
21208 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21209 {
21210 - if (PAGE_ALIGN(size) > MODULES_LEN)
21211 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21212 return NULL;
21213 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21214 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21215 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21216 -1, __builtin_return_address(0));
21217 }
21218
21219 +void *module_alloc(unsigned long size)
21220 +{
21221 +
21222 +#ifdef CONFIG_PAX_KERNEXEC
21223 + return __module_alloc(size, PAGE_KERNEL);
21224 +#else
21225 + return __module_alloc(size, PAGE_KERNEL_EXEC);
21226 +#endif
21227 +
21228 +}
21229 +
21230 +#ifdef CONFIG_PAX_KERNEXEC
21231 +#ifdef CONFIG_X86_32
21232 +void *module_alloc_exec(unsigned long size)
21233 +{
21234 + struct vm_struct *area;
21235 +
21236 + if (size == 0)
21237 + return NULL;
21238 +
21239 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21240 + return area ? area->addr : NULL;
21241 +}
21242 +EXPORT_SYMBOL(module_alloc_exec);
21243 +
21244 +void module_free_exec(struct module *mod, void *module_region)
21245 +{
21246 + vunmap(module_region);
21247 +}
21248 +EXPORT_SYMBOL(module_free_exec);
21249 +#else
21250 +void module_free_exec(struct module *mod, void *module_region)
21251 +{
21252 + module_free(mod, module_region);
21253 +}
21254 +EXPORT_SYMBOL(module_free_exec);
21255 +
21256 +void *module_alloc_exec(unsigned long size)
21257 +{
21258 + return __module_alloc(size, PAGE_KERNEL_RX);
21259 +}
21260 +EXPORT_SYMBOL(module_alloc_exec);
21261 +#endif
21262 +#endif
21263 +
21264 #ifdef CONFIG_X86_32
21265 int apply_relocate(Elf32_Shdr *sechdrs,
21266 const char *strtab,
21267 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21268 unsigned int i;
21269 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21270 Elf32_Sym *sym;
21271 - uint32_t *location;
21272 + uint32_t *plocation, location;
21273
21274 DEBUGP("Applying relocate section %u to %u\n",
21275 relsec, sechdrs[relsec].sh_info);
21276 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21277 /* This is where to make the change */
21278 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21279 - + rel[i].r_offset;
21280 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21281 + location = (uint32_t)plocation;
21282 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21283 + plocation = ktla_ktva((void *)plocation);
21284 /* This is the symbol it is referring to. Note that all
21285 undefined symbols have been resolved. */
21286 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21287 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21288 switch (ELF32_R_TYPE(rel[i].r_info)) {
21289 case R_386_32:
21290 /* We add the value into the location given */
21291 - *location += sym->st_value;
21292 + pax_open_kernel();
21293 + *plocation += sym->st_value;
21294 + pax_close_kernel();
21295 break;
21296 case R_386_PC32:
21297 /* Add the value, subtract its position */
21298 - *location += sym->st_value - (uint32_t)location;
21299 + pax_open_kernel();
21300 + *plocation += sym->st_value - location;
21301 + pax_close_kernel();
21302 break;
21303 default:
21304 pr_err("%s: Unknown relocation: %u\n",
21305 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21306 case R_X86_64_NONE:
21307 break;
21308 case R_X86_64_64:
21309 + pax_open_kernel();
21310 *(u64 *)loc = val;
21311 + pax_close_kernel();
21312 break;
21313 case R_X86_64_32:
21314 + pax_open_kernel();
21315 *(u32 *)loc = val;
21316 + pax_close_kernel();
21317 if (val != *(u32 *)loc)
21318 goto overflow;
21319 break;
21320 case R_X86_64_32S:
21321 + pax_open_kernel();
21322 *(s32 *)loc = val;
21323 + pax_close_kernel();
21324 if ((s64)val != *(s32 *)loc)
21325 goto overflow;
21326 break;
21327 case R_X86_64_PC32:
21328 val -= (u64)loc;
21329 + pax_open_kernel();
21330 *(u32 *)loc = val;
21331 + pax_close_kernel();
21332 +
21333 #if 0
21334 if ((s64)val != *(s32 *)loc)
21335 goto overflow;
21336 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21337 index 4929502..686c291 100644
21338 --- a/arch/x86/kernel/msr.c
21339 +++ b/arch/x86/kernel/msr.c
21340 @@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21341 return notifier_from_errno(err);
21342 }
21343
21344 -static struct notifier_block __refdata msr_class_cpu_notifier = {
21345 +static struct notifier_block msr_class_cpu_notifier = {
21346 .notifier_call = msr_class_cpu_callback,
21347 };
21348
21349 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21350 index f84f5c5..f404e81 100644
21351 --- a/arch/x86/kernel/nmi.c
21352 +++ b/arch/x86/kernel/nmi.c
21353 @@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
21354 return handled;
21355 }
21356
21357 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21358 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
21359 {
21360 struct nmi_desc *desc = nmi_to_desc(type);
21361 unsigned long flags;
21362 @@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21363 * event confuses some handlers (kdump uses this flag)
21364 */
21365 if (action->flags & NMI_FLAG_FIRST)
21366 - list_add_rcu(&action->list, &desc->head);
21367 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21368 else
21369 - list_add_tail_rcu(&action->list, &desc->head);
21370 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21371
21372 spin_unlock_irqrestore(&desc->lock, flags);
21373 return 0;
21374 @@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21375 if (!strcmp(n->name, name)) {
21376 WARN(in_nmi(),
21377 "Trying to free NMI (%s) from NMI context!\n", n->name);
21378 - list_del_rcu(&n->list);
21379 + pax_list_del_rcu((struct list_head *)&n->list);
21380 break;
21381 }
21382 }
21383 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21384 dotraplinkage notrace __kprobes void
21385 do_nmi(struct pt_regs *regs, long error_code)
21386 {
21387 +
21388 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21389 + if (!user_mode(regs)) {
21390 + unsigned long cs = regs->cs & 0xFFFF;
21391 + unsigned long ip = ktva_ktla(regs->ip);
21392 +
21393 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21394 + regs->ip = ip;
21395 + }
21396 +#endif
21397 +
21398 nmi_nesting_preprocess(regs);
21399
21400 nmi_enter();
21401 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21402 index 6d9582e..f746287 100644
21403 --- a/arch/x86/kernel/nmi_selftest.c
21404 +++ b/arch/x86/kernel/nmi_selftest.c
21405 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21406 {
21407 /* trap all the unknown NMIs we may generate */
21408 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21409 - __initdata);
21410 + __initconst);
21411 }
21412
21413 static void __init cleanup_nmi_testsuite(void)
21414 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21415 unsigned long timeout;
21416
21417 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21418 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21419 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21420 nmi_fail = FAILURE;
21421 return;
21422 }
21423 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21424 index 676b8c7..870ba04 100644
21425 --- a/arch/x86/kernel/paravirt-spinlocks.c
21426 +++ b/arch/x86/kernel/paravirt-spinlocks.c
21427 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21428 arch_spin_lock(lock);
21429 }
21430
21431 -struct pv_lock_ops pv_lock_ops = {
21432 +struct pv_lock_ops pv_lock_ops __read_only = {
21433 #ifdef CONFIG_SMP
21434 .spin_is_locked = __ticket_spin_is_locked,
21435 .spin_is_contended = __ticket_spin_is_contended,
21436 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21437 index 17fff18..5cfa0f4 100644
21438 --- a/arch/x86/kernel/paravirt.c
21439 +++ b/arch/x86/kernel/paravirt.c
21440 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21441 {
21442 return x;
21443 }
21444 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21445 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21446 +#endif
21447
21448 void __init default_banner(void)
21449 {
21450 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21451 if (opfunc == NULL)
21452 /* If there's no function, patch it with a ud2a (BUG) */
21453 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21454 - else if (opfunc == _paravirt_nop)
21455 + else if (opfunc == (void *)_paravirt_nop)
21456 /* If the operation is a nop, then nop the callsite */
21457 ret = paravirt_patch_nop();
21458
21459 /* identity functions just return their single argument */
21460 - else if (opfunc == _paravirt_ident_32)
21461 + else if (opfunc == (void *)_paravirt_ident_32)
21462 ret = paravirt_patch_ident_32(insnbuf, len);
21463 - else if (opfunc == _paravirt_ident_64)
21464 + else if (opfunc == (void *)_paravirt_ident_64)
21465 ret = paravirt_patch_ident_64(insnbuf, len);
21466 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21467 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21468 + ret = paravirt_patch_ident_64(insnbuf, len);
21469 +#endif
21470
21471 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21472 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21473 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21474 if (insn_len > len || start == NULL)
21475 insn_len = len;
21476 else
21477 - memcpy(insnbuf, start, insn_len);
21478 + memcpy(insnbuf, ktla_ktva(start), insn_len);
21479
21480 return insn_len;
21481 }
21482 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
21483 preempt_enable();
21484 }
21485
21486 -struct pv_info pv_info = {
21487 +struct pv_info pv_info __read_only = {
21488 .name = "bare hardware",
21489 .paravirt_enabled = 0,
21490 .kernel_rpl = 0,
21491 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
21492 #endif
21493 };
21494
21495 -struct pv_init_ops pv_init_ops = {
21496 +struct pv_init_ops pv_init_ops __read_only = {
21497 .patch = native_patch,
21498 };
21499
21500 -struct pv_time_ops pv_time_ops = {
21501 +struct pv_time_ops pv_time_ops __read_only = {
21502 .sched_clock = native_sched_clock,
21503 .steal_clock = native_steal_clock,
21504 };
21505
21506 -struct pv_irq_ops pv_irq_ops = {
21507 +struct pv_irq_ops pv_irq_ops __read_only = {
21508 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21509 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21510 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21511 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21512 #endif
21513 };
21514
21515 -struct pv_cpu_ops pv_cpu_ops = {
21516 +struct pv_cpu_ops pv_cpu_ops __read_only = {
21517 .cpuid = native_cpuid,
21518 .get_debugreg = native_get_debugreg,
21519 .set_debugreg = native_set_debugreg,
21520 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21521 .end_context_switch = paravirt_nop,
21522 };
21523
21524 -struct pv_apic_ops pv_apic_ops = {
21525 +struct pv_apic_ops pv_apic_ops __read_only= {
21526 #ifdef CONFIG_X86_LOCAL_APIC
21527 .startup_ipi_hook = paravirt_nop,
21528 #endif
21529 };
21530
21531 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21532 +#ifdef CONFIG_X86_32
21533 +#ifdef CONFIG_X86_PAE
21534 +/* 64-bit pagetable entries */
21535 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21536 +#else
21537 /* 32-bit pagetable entries */
21538 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21539 +#endif
21540 #else
21541 /* 64-bit pagetable entries */
21542 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21543 #endif
21544
21545 -struct pv_mmu_ops pv_mmu_ops = {
21546 +struct pv_mmu_ops pv_mmu_ops __read_only = {
21547
21548 .read_cr2 = native_read_cr2,
21549 .write_cr2 = native_write_cr2,
21550 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21551 .make_pud = PTE_IDENT,
21552
21553 .set_pgd = native_set_pgd,
21554 + .set_pgd_batched = native_set_pgd_batched,
21555 #endif
21556 #endif /* PAGETABLE_LEVELS >= 3 */
21557
21558 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21559 },
21560
21561 .set_fixmap = native_set_fixmap,
21562 +
21563 +#ifdef CONFIG_PAX_KERNEXEC
21564 + .pax_open_kernel = native_pax_open_kernel,
21565 + .pax_close_kernel = native_pax_close_kernel,
21566 +#endif
21567 +
21568 };
21569
21570 EXPORT_SYMBOL_GPL(pv_time_ops);
21571 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21572 index 35ccf75..7a15747 100644
21573 --- a/arch/x86/kernel/pci-iommu_table.c
21574 +++ b/arch/x86/kernel/pci-iommu_table.c
21575 @@ -2,7 +2,7 @@
21576 #include <asm/iommu_table.h>
21577 #include <linux/string.h>
21578 #include <linux/kallsyms.h>
21579 -
21580 +#include <linux/sched.h>
21581
21582 #define DEBUG 1
21583
21584 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
21585 index 6c483ba..d10ce2f 100644
21586 --- a/arch/x86/kernel/pci-swiotlb.c
21587 +++ b/arch/x86/kernel/pci-swiotlb.c
21588 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
21589 void *vaddr, dma_addr_t dma_addr,
21590 struct dma_attrs *attrs)
21591 {
21592 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
21593 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
21594 }
21595
21596 static struct dma_map_ops swiotlb_dma_ops = {
21597 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21598 index 2ed787f..f70c9f6 100644
21599 --- a/arch/x86/kernel/process.c
21600 +++ b/arch/x86/kernel/process.c
21601 @@ -36,7 +36,8 @@
21602 * section. Since TSS's are completely CPU-local, we want them
21603 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21604 */
21605 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
21606 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
21607 +EXPORT_SYMBOL(init_tss);
21608
21609 #ifdef CONFIG_X86_64
21610 static DEFINE_PER_CPU(unsigned char, is_idle);
21611 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
21612 task_xstate_cachep =
21613 kmem_cache_create("task_xstate", xstate_size,
21614 __alignof__(union thread_xstate),
21615 - SLAB_PANIC | SLAB_NOTRACK, NULL);
21616 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
21617 }
21618
21619 /*
21620 @@ -105,7 +106,7 @@ void exit_thread(void)
21621 unsigned long *bp = t->io_bitmap_ptr;
21622
21623 if (bp) {
21624 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
21625 + struct tss_struct *tss = init_tss + get_cpu();
21626
21627 t->io_bitmap_ptr = NULL;
21628 clear_thread_flag(TIF_IO_BITMAP);
21629 @@ -136,7 +137,7 @@ void show_regs_common(void)
21630 board = dmi_get_system_info(DMI_BOARD_NAME);
21631
21632 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
21633 - current->pid, current->comm, print_tainted(),
21634 + task_pid_nr(current), current->comm, print_tainted(),
21635 init_utsname()->release,
21636 (int)strcspn(init_utsname()->version, " "),
21637 init_utsname()->version,
21638 @@ -149,6 +150,9 @@ void flush_thread(void)
21639 {
21640 struct task_struct *tsk = current;
21641
21642 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
21643 + loadsegment(gs, 0);
21644 +#endif
21645 flush_ptrace_hw_breakpoint(tsk);
21646 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
21647 drop_init_fpu(tsk);
21648 @@ -301,7 +305,7 @@ static void __exit_idle(void)
21649 void exit_idle(void)
21650 {
21651 /* idle loop has pid 0 */
21652 - if (current->pid)
21653 + if (task_pid_nr(current))
21654 return;
21655 __exit_idle();
21656 }
21657 @@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
21658
21659 return ret;
21660 }
21661 -void stop_this_cpu(void *dummy)
21662 +__noreturn void stop_this_cpu(void *dummy)
21663 {
21664 local_irq_disable();
21665 /*
21666 @@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
21667 }
21668 early_param("idle", idle_setup);
21669
21670 -unsigned long arch_align_stack(unsigned long sp)
21671 +#ifdef CONFIG_PAX_RANDKSTACK
21672 +void pax_randomize_kstack(struct pt_regs *regs)
21673 {
21674 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
21675 - sp -= get_random_int() % 8192;
21676 - return sp & ~0xf;
21677 -}
21678 + struct thread_struct *thread = &current->thread;
21679 + unsigned long time;
21680
21681 -unsigned long arch_randomize_brk(struct mm_struct *mm)
21682 -{
21683 - unsigned long range_end = mm->brk + 0x02000000;
21684 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
21685 -}
21686 + if (!randomize_va_space)
21687 + return;
21688 +
21689 + if (v8086_mode(regs))
21690 + return;
21691
21692 + rdtscl(time);
21693 +
21694 + /* P4 seems to return a 0 LSB, ignore it */
21695 +#ifdef CONFIG_MPENTIUM4
21696 + time &= 0x3EUL;
21697 + time <<= 2;
21698 +#elif defined(CONFIG_X86_64)
21699 + time &= 0xFUL;
21700 + time <<= 4;
21701 +#else
21702 + time &= 0x1FUL;
21703 + time <<= 3;
21704 +#endif
21705 +
21706 + thread->sp0 ^= time;
21707 + load_sp0(init_tss + smp_processor_id(), thread);
21708 +
21709 +#ifdef CONFIG_X86_64
21710 + this_cpu_write(kernel_stack, thread->sp0);
21711 +#endif
21712 +}
21713 +#endif
21714 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
21715 index b5a8905..d9cacac 100644
21716 --- a/arch/x86/kernel/process_32.c
21717 +++ b/arch/x86/kernel/process_32.c
21718 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
21719 unsigned long thread_saved_pc(struct task_struct *tsk)
21720 {
21721 return ((unsigned long *)tsk->thread.sp)[3];
21722 +//XXX return tsk->thread.eip;
21723 }
21724
21725 void __show_regs(struct pt_regs *regs, int all)
21726 @@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
21727 unsigned long sp;
21728 unsigned short ss, gs;
21729
21730 - if (user_mode_vm(regs)) {
21731 + if (user_mode(regs)) {
21732 sp = regs->sp;
21733 ss = regs->ss & 0xffff;
21734 - gs = get_user_gs(regs);
21735 } else {
21736 sp = kernel_stack_pointer(regs);
21737 savesegment(ss, ss);
21738 - savesegment(gs, gs);
21739 }
21740 + gs = get_user_gs(regs);
21741
21742 show_regs_common();
21743
21744 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
21745 (u16)regs->cs, regs->ip, regs->flags,
21746 - smp_processor_id());
21747 + raw_smp_processor_id());
21748 print_symbol("EIP is at %s\n", regs->ip);
21749
21750 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
21751 @@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
21752 int copy_thread(unsigned long clone_flags, unsigned long sp,
21753 unsigned long arg, struct task_struct *p)
21754 {
21755 - struct pt_regs *childregs = task_pt_regs(p);
21756 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
21757 struct task_struct *tsk;
21758 int err;
21759
21760 p->thread.sp = (unsigned long) childregs;
21761 p->thread.sp0 = (unsigned long) (childregs+1);
21762 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21763
21764 if (unlikely(p->flags & PF_KTHREAD)) {
21765 /* kernel thread */
21766 memset(childregs, 0, sizeof(struct pt_regs));
21767 p->thread.ip = (unsigned long) ret_from_kernel_thread;
21768 - task_user_gs(p) = __KERNEL_STACK_CANARY;
21769 - childregs->ds = __USER_DS;
21770 - childregs->es = __USER_DS;
21771 + savesegment(gs, childregs->gs);
21772 + childregs->ds = __KERNEL_DS;
21773 + childregs->es = __KERNEL_DS;
21774 childregs->fs = __KERNEL_PERCPU;
21775 childregs->bx = sp; /* function */
21776 childregs->bp = arg;
21777 @@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21778 struct thread_struct *prev = &prev_p->thread,
21779 *next = &next_p->thread;
21780 int cpu = smp_processor_id();
21781 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21782 + struct tss_struct *tss = init_tss + cpu;
21783 fpu_switch_t fpu;
21784
21785 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
21786 @@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21787 */
21788 lazy_save_gs(prev->gs);
21789
21790 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21791 + __set_fs(task_thread_info(next_p)->addr_limit);
21792 +#endif
21793 +
21794 /*
21795 * Load the per-thread Thread-Local Storage descriptor.
21796 */
21797 @@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21798 */
21799 arch_end_context_switch(next_p);
21800
21801 + this_cpu_write(current_task, next_p);
21802 + this_cpu_write(current_tinfo, &next_p->tinfo);
21803 +
21804 /*
21805 * Restore %gs if needed (which is common)
21806 */
21807 @@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21808
21809 switch_fpu_finish(next_p, fpu);
21810
21811 - this_cpu_write(current_task, next_p);
21812 -
21813 return prev_p;
21814 }
21815
21816 @@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
21817 } while (count++ < 16);
21818 return 0;
21819 }
21820 -
21821 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
21822 index 6e68a61..955a9a5 100644
21823 --- a/arch/x86/kernel/process_64.c
21824 +++ b/arch/x86/kernel/process_64.c
21825 @@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
21826 struct pt_regs *childregs;
21827 struct task_struct *me = current;
21828
21829 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
21830 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
21831 childregs = task_pt_regs(p);
21832 p->thread.sp = (unsigned long) childregs;
21833 p->thread.usersp = me->thread.usersp;
21834 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21835 set_tsk_thread_flag(p, TIF_FORK);
21836 p->fpu_counter = 0;
21837 p->thread.io_bitmap_ptr = NULL;
21838 @@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21839 struct thread_struct *prev = &prev_p->thread;
21840 struct thread_struct *next = &next_p->thread;
21841 int cpu = smp_processor_id();
21842 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21843 + struct tss_struct *tss = init_tss + cpu;
21844 unsigned fsindex, gsindex;
21845 fpu_switch_t fpu;
21846
21847 @@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21848 prev->usersp = this_cpu_read(old_rsp);
21849 this_cpu_write(old_rsp, next->usersp);
21850 this_cpu_write(current_task, next_p);
21851 + this_cpu_write(current_tinfo, &next_p->tinfo);
21852
21853 - this_cpu_write(kernel_stack,
21854 - (unsigned long)task_stack_page(next_p) +
21855 - THREAD_SIZE - KERNEL_STACK_OFFSET);
21856 + this_cpu_write(kernel_stack, next->sp0);
21857
21858 /*
21859 * Now maybe reload the debug registers and handle I/O bitmaps
21860 @@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
21861 if (!p || p == current || p->state == TASK_RUNNING)
21862 return 0;
21863 stack = (unsigned long)task_stack_page(p);
21864 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
21865 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
21866 return 0;
21867 fp = *(u64 *)(p->thread.sp);
21868 do {
21869 - if (fp < (unsigned long)stack ||
21870 - fp >= (unsigned long)stack+THREAD_SIZE)
21871 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
21872 return 0;
21873 ip = *(u64 *)(fp+8);
21874 if (!in_sched_functions(ip))
21875 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
21876 index b629bbe..0fa615a 100644
21877 --- a/arch/x86/kernel/ptrace.c
21878 +++ b/arch/x86/kernel/ptrace.c
21879 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
21880 {
21881 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
21882 unsigned long sp = (unsigned long)&regs->sp;
21883 - struct thread_info *tinfo;
21884
21885 - if (context == (sp & ~(THREAD_SIZE - 1)))
21886 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
21887 return sp;
21888
21889 - tinfo = (struct thread_info *)context;
21890 - if (tinfo->previous_esp)
21891 - return tinfo->previous_esp;
21892 + sp = *(unsigned long *)context;
21893 + if (sp)
21894 + return sp;
21895
21896 return (unsigned long)regs;
21897 }
21898 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
21899 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
21900 {
21901 int i;
21902 - int dr7 = 0;
21903 + unsigned long dr7 = 0;
21904 struct arch_hw_breakpoint *info;
21905
21906 for (i = 0; i < HBP_NUM; i++) {
21907 @@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
21908 unsigned long addr, unsigned long data)
21909 {
21910 int ret;
21911 - unsigned long __user *datap = (unsigned long __user *)data;
21912 + unsigned long __user *datap = (__force unsigned long __user *)data;
21913
21914 switch (request) {
21915 /* read the word at location addr in the USER area. */
21916 @@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
21917 if ((int) addr < 0)
21918 return -EIO;
21919 ret = do_get_thread_area(child, addr,
21920 - (struct user_desc __user *)data);
21921 + (__force struct user_desc __user *) data);
21922 break;
21923
21924 case PTRACE_SET_THREAD_AREA:
21925 if ((int) addr < 0)
21926 return -EIO;
21927 ret = do_set_thread_area(child, addr,
21928 - (struct user_desc __user *)data, 0);
21929 + (__force struct user_desc __user *) data, 0);
21930 break;
21931 #endif
21932
21933 @@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
21934
21935 #ifdef CONFIG_X86_64
21936
21937 -static struct user_regset x86_64_regsets[] __read_mostly = {
21938 +static user_regset_no_const x86_64_regsets[] __read_only = {
21939 [REGSET_GENERAL] = {
21940 .core_note_type = NT_PRSTATUS,
21941 .n = sizeof(struct user_regs_struct) / sizeof(long),
21942 @@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
21943 #endif /* CONFIG_X86_64 */
21944
21945 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
21946 -static struct user_regset x86_32_regsets[] __read_mostly = {
21947 +static user_regset_no_const x86_32_regsets[] __read_only = {
21948 [REGSET_GENERAL] = {
21949 .core_note_type = NT_PRSTATUS,
21950 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
21951 @@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
21952 */
21953 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
21954
21955 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21956 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21957 {
21958 #ifdef CONFIG_X86_64
21959 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
21960 @@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
21961 memset(info, 0, sizeof(*info));
21962 info->si_signo = SIGTRAP;
21963 info->si_code = si_code;
21964 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
21965 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
21966 }
21967
21968 void user_single_step_siginfo(struct task_struct *tsk,
21969 @@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
21970 # define IS_IA32 0
21971 #endif
21972
21973 +#ifdef CONFIG_GRKERNSEC_SETXID
21974 +extern void gr_delayed_cred_worker(void);
21975 +#endif
21976 +
21977 /*
21978 * We must return the syscall number to actually look up in the table.
21979 * This can be -1L to skip running any syscall at all.
21980 @@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
21981
21982 user_exit();
21983
21984 +#ifdef CONFIG_GRKERNSEC_SETXID
21985 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21986 + gr_delayed_cred_worker();
21987 +#endif
21988 +
21989 /*
21990 * If we stepped into a sysenter/syscall insn, it trapped in
21991 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
21992 @@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
21993 */
21994 user_exit();
21995
21996 +#ifdef CONFIG_GRKERNSEC_SETXID
21997 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21998 + gr_delayed_cred_worker();
21999 +#endif
22000 +
22001 audit_syscall_exit(regs);
22002
22003 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22004 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22005 index 2cb9470..ff1fd80 100644
22006 --- a/arch/x86/kernel/pvclock.c
22007 +++ b/arch/x86/kernel/pvclock.c
22008 @@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22009 return pv_tsc_khz;
22010 }
22011
22012 -static atomic64_t last_value = ATOMIC64_INIT(0);
22013 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22014
22015 void pvclock_resume(void)
22016 {
22017 - atomic64_set(&last_value, 0);
22018 + atomic64_set_unchecked(&last_value, 0);
22019 }
22020
22021 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22022 @@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22023 * updating at the same time, and one of them could be slightly behind,
22024 * making the assumption that last_value always go forward fail to hold.
22025 */
22026 - last = atomic64_read(&last_value);
22027 + last = atomic64_read_unchecked(&last_value);
22028 do {
22029 if (ret < last)
22030 return last;
22031 - last = atomic64_cmpxchg(&last_value, last, ret);
22032 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22033 } while (unlikely(last != ret));
22034
22035 return ret;
22036 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22037 index 76fa1e9..abf09ea 100644
22038 --- a/arch/x86/kernel/reboot.c
22039 +++ b/arch/x86/kernel/reboot.c
22040 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22041 EXPORT_SYMBOL(pm_power_off);
22042
22043 static const struct desc_ptr no_idt = {};
22044 -static int reboot_mode;
22045 +static unsigned short reboot_mode;
22046 enum reboot_type reboot_type = BOOT_ACPI;
22047 int reboot_force;
22048
22049 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22050
22051 void __noreturn machine_real_restart(unsigned int type)
22052 {
22053 +
22054 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22055 + struct desc_struct *gdt;
22056 +#endif
22057 +
22058 local_irq_disable();
22059
22060 /*
22061 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22062
22063 /* Jump to the identity-mapped low memory code */
22064 #ifdef CONFIG_X86_32
22065 - asm volatile("jmpl *%0" : :
22066 +
22067 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22068 + gdt = get_cpu_gdt_table(smp_processor_id());
22069 + pax_open_kernel();
22070 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22071 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22072 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22073 + loadsegment(ds, __KERNEL_DS);
22074 + loadsegment(es, __KERNEL_DS);
22075 + loadsegment(ss, __KERNEL_DS);
22076 +#endif
22077 +#ifdef CONFIG_PAX_KERNEXEC
22078 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22079 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22080 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22081 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22082 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22083 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22084 +#endif
22085 + pax_close_kernel();
22086 +#endif
22087 +
22088 + asm volatile("ljmpl *%0" : :
22089 "rm" (real_mode_header->machine_real_restart_asm),
22090 "a" (type));
22091 #else
22092 @@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22093 * try to force a triple fault and then cycle between hitting the keyboard
22094 * controller and doing that
22095 */
22096 -static void native_machine_emergency_restart(void)
22097 +static void __noreturn native_machine_emergency_restart(void)
22098 {
22099 int i;
22100 int attempt = 0;
22101 @@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22102 #endif
22103 }
22104
22105 -static void __machine_emergency_restart(int emergency)
22106 +static void __noreturn __machine_emergency_restart(int emergency)
22107 {
22108 reboot_emergency = emergency;
22109 machine_ops.emergency_restart();
22110 }
22111
22112 -static void native_machine_restart(char *__unused)
22113 +static void __noreturn native_machine_restart(char *__unused)
22114 {
22115 pr_notice("machine restart\n");
22116
22117 @@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22118 __machine_emergency_restart(0);
22119 }
22120
22121 -static void native_machine_halt(void)
22122 +static void __noreturn native_machine_halt(void)
22123 {
22124 /* Stop other cpus and apics */
22125 machine_shutdown();
22126 @@ -679,7 +706,7 @@ static void native_machine_halt(void)
22127 stop_this_cpu(NULL);
22128 }
22129
22130 -static void native_machine_power_off(void)
22131 +static void __noreturn native_machine_power_off(void)
22132 {
22133 if (pm_power_off) {
22134 if (!reboot_force)
22135 @@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22136 }
22137 /* A fallback in case there is no PM info available */
22138 tboot_shutdown(TB_SHUTDOWN_HALT);
22139 + unreachable();
22140 }
22141
22142 -struct machine_ops machine_ops = {
22143 +struct machine_ops machine_ops __read_only = {
22144 .power_off = native_machine_power_off,
22145 .shutdown = native_machine_shutdown,
22146 .emergency_restart = native_machine_emergency_restart,
22147 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22148 index 7a6f3b3..bed145d7 100644
22149 --- a/arch/x86/kernel/relocate_kernel_64.S
22150 +++ b/arch/x86/kernel/relocate_kernel_64.S
22151 @@ -11,6 +11,7 @@
22152 #include <asm/kexec.h>
22153 #include <asm/processor-flags.h>
22154 #include <asm/pgtable_types.h>
22155 +#include <asm/alternative-asm.h>
22156
22157 /*
22158 * Must be relocatable PIC code callable as a C function
22159 @@ -160,13 +161,14 @@ identity_mapped:
22160 xorq %rbp, %rbp
22161 xorq %r8, %r8
22162 xorq %r9, %r9
22163 - xorq %r10, %r9
22164 + xorq %r10, %r10
22165 xorq %r11, %r11
22166 xorq %r12, %r12
22167 xorq %r13, %r13
22168 xorq %r14, %r14
22169 xorq %r15, %r15
22170
22171 + pax_force_retaddr 0, 1
22172 ret
22173
22174 1:
22175 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22176 index 8b24289..d37b58b 100644
22177 --- a/arch/x86/kernel/setup.c
22178 +++ b/arch/x86/kernel/setup.c
22179 @@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
22180
22181 switch (data->type) {
22182 case SETUP_E820_EXT:
22183 - parse_e820_ext(data);
22184 + parse_e820_ext((struct setup_data __force_kernel *)data);
22185 break;
22186 case SETUP_DTB:
22187 add_dtb(pa_data);
22188 @@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
22189 * area (640->1Mb) as ram even though it is not.
22190 * take them out.
22191 */
22192 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22193 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22194
22195 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22196 }
22197 @@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
22198
22199 if (!boot_params.hdr.root_flags)
22200 root_mountflags &= ~MS_RDONLY;
22201 - init_mm.start_code = (unsigned long) _text;
22202 - init_mm.end_code = (unsigned long) _etext;
22203 + init_mm.start_code = ktla_ktva((unsigned long) _text);
22204 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
22205 init_mm.end_data = (unsigned long) _edata;
22206 init_mm.brk = _brk_end;
22207
22208 - code_resource.start = virt_to_phys(_text);
22209 - code_resource.end = virt_to_phys(_etext)-1;
22210 - data_resource.start = virt_to_phys(_etext);
22211 + code_resource.start = virt_to_phys(ktla_ktva(_text));
22212 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
22213 + data_resource.start = virt_to_phys(_sdata);
22214 data_resource.end = virt_to_phys(_edata)-1;
22215 bss_resource.start = virt_to_phys(&__bss_start);
22216 bss_resource.end = virt_to_phys(&__bss_stop)-1;
22217 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22218 index 5cdff03..5810740 100644
22219 --- a/arch/x86/kernel/setup_percpu.c
22220 +++ b/arch/x86/kernel/setup_percpu.c
22221 @@ -21,19 +21,17 @@
22222 #include <asm/cpu.h>
22223 #include <asm/stackprotector.h>
22224
22225 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22226 +#ifdef CONFIG_SMP
22227 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22228 EXPORT_PER_CPU_SYMBOL(cpu_number);
22229 +#endif
22230
22231 -#ifdef CONFIG_X86_64
22232 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22233 -#else
22234 -#define BOOT_PERCPU_OFFSET 0
22235 -#endif
22236
22237 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22238 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22239
22240 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22241 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22242 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22243 };
22244 EXPORT_SYMBOL(__per_cpu_offset);
22245 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22246 {
22247 #ifdef CONFIG_X86_32
22248 struct desc_struct gdt;
22249 + unsigned long base = per_cpu_offset(cpu);
22250
22251 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22252 - 0x2 | DESCTYPE_S, 0x8);
22253 - gdt.s = 1;
22254 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22255 + 0x83 | DESCTYPE_S, 0xC);
22256 write_gdt_entry(get_cpu_gdt_table(cpu),
22257 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22258 #endif
22259 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22260 /* alrighty, percpu areas up and running */
22261 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22262 for_each_possible_cpu(cpu) {
22263 +#ifdef CONFIG_CC_STACKPROTECTOR
22264 +#ifdef CONFIG_X86_32
22265 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
22266 +#endif
22267 +#endif
22268 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22269 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22270 per_cpu(cpu_number, cpu) = cpu;
22271 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22272 */
22273 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22274 #endif
22275 +#ifdef CONFIG_CC_STACKPROTECTOR
22276 +#ifdef CONFIG_X86_32
22277 + if (!cpu)
22278 + per_cpu(stack_canary.canary, cpu) = canary;
22279 +#endif
22280 +#endif
22281 /*
22282 * Up to this point, the boot CPU has been using .init.data
22283 * area. Reload any changed state for the boot CPU.
22284 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22285 index d6bf1f3..3ffce5a 100644
22286 --- a/arch/x86/kernel/signal.c
22287 +++ b/arch/x86/kernel/signal.c
22288 @@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22289 * Align the stack pointer according to the i386 ABI,
22290 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22291 */
22292 - sp = ((sp + 4) & -16ul) - 4;
22293 + sp = ((sp - 12) & -16ul) - 4;
22294 #else /* !CONFIG_X86_32 */
22295 sp = round_down(sp, 16) - 8;
22296 #endif
22297 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22298 }
22299
22300 if (current->mm->context.vdso)
22301 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22302 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22303 else
22304 - restorer = &frame->retcode;
22305 + restorer = (void __user *)&frame->retcode;
22306 if (ka->sa.sa_flags & SA_RESTORER)
22307 restorer = ka->sa.sa_restorer;
22308
22309 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22310 * reasons and because gdb uses it as a signature to notice
22311 * signal handler stack frames.
22312 */
22313 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22314 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22315
22316 if (err)
22317 return -EFAULT;
22318 @@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22319 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22320
22321 /* Set up to return from userspace. */
22322 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22323 + if (current->mm->context.vdso)
22324 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22325 + else
22326 + restorer = (void __user *)&frame->retcode;
22327 if (ka->sa.sa_flags & SA_RESTORER)
22328 restorer = ka->sa.sa_restorer;
22329 put_user_ex(restorer, &frame->pretcode);
22330 @@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22331 * reasons and because gdb uses it as a signature to notice
22332 * signal handler stack frames.
22333 */
22334 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22335 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22336 } put_user_catch(err);
22337
22338 err |= copy_siginfo_to_user(&frame->info, info);
22339 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22340 index 48d2b7d..90d328a 100644
22341 --- a/arch/x86/kernel/smp.c
22342 +++ b/arch/x86/kernel/smp.c
22343 @@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22344
22345 __setup("nonmi_ipi", nonmi_ipi_setup);
22346
22347 -struct smp_ops smp_ops = {
22348 +struct smp_ops smp_ops __read_only = {
22349 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22350 .smp_prepare_cpus = native_smp_prepare_cpus,
22351 .smp_cpus_done = native_smp_cpus_done,
22352 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22353 index ed0fe38..87fc692 100644
22354 --- a/arch/x86/kernel/smpboot.c
22355 +++ b/arch/x86/kernel/smpboot.c
22356 @@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22357 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22358 (THREAD_SIZE + task_stack_page(idle))) - 1);
22359 per_cpu(current_task, cpu) = idle;
22360 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
22361
22362 #ifdef CONFIG_X86_32
22363 /* Stack for startup_32 can be just as for start_secondary onwards */
22364 @@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22365 #else
22366 clear_tsk_thread_flag(idle, TIF_FORK);
22367 initial_gs = per_cpu_offset(cpu);
22368 - per_cpu(kernel_stack, cpu) =
22369 - (unsigned long)task_stack_page(idle) -
22370 - KERNEL_STACK_OFFSET + THREAD_SIZE;
22371 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22372 #endif
22373 +
22374 + pax_open_kernel();
22375 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22376 + pax_close_kernel();
22377 +
22378 initial_code = (unsigned long)start_secondary;
22379 stack_start = idle->thread.sp;
22380
22381 @@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22382 /* the FPU context is blank, nobody can own it */
22383 __cpu_disable_lazy_restore(cpu);
22384
22385 +#ifdef CONFIG_PAX_PER_CPU_PGD
22386 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22387 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22388 + KERNEL_PGD_PTRS);
22389 +#endif
22390 +
22391 + /* the FPU context is blank, nobody can own it */
22392 + __cpu_disable_lazy_restore(cpu);
22393 +
22394 err = do_boot_cpu(apicid, cpu, tidle);
22395 if (err) {
22396 pr_debug("do_boot_cpu failed %d\n", err);
22397 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22398 index 9b4d51d..5d28b58 100644
22399 --- a/arch/x86/kernel/step.c
22400 +++ b/arch/x86/kernel/step.c
22401 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22402 struct desc_struct *desc;
22403 unsigned long base;
22404
22405 - seg &= ~7UL;
22406 + seg >>= 3;
22407
22408 mutex_lock(&child->mm->context.lock);
22409 - if (unlikely((seg >> 3) >= child->mm->context.size))
22410 + if (unlikely(seg >= child->mm->context.size))
22411 addr = -1L; /* bogus selector, access would fault */
22412 else {
22413 desc = child->mm->context.ldt + seg;
22414 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22415 addr += base;
22416 }
22417 mutex_unlock(&child->mm->context.lock);
22418 - }
22419 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22420 + addr = ktla_ktva(addr);
22421
22422 return addr;
22423 }
22424 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22425 unsigned char opcode[15];
22426 unsigned long addr = convert_ip_to_linear(child, regs);
22427
22428 + if (addr == -EINVAL)
22429 + return 0;
22430 +
22431 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22432 for (i = 0; i < copied; i++) {
22433 switch (opcode[i]) {
22434 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22435 new file mode 100644
22436 index 0000000..207bec6
22437 --- /dev/null
22438 +++ b/arch/x86/kernel/sys_i386_32.c
22439 @@ -0,0 +1,250 @@
22440 +/*
22441 + * This file contains various random system calls that
22442 + * have a non-standard calling sequence on the Linux/i386
22443 + * platform.
22444 + */
22445 +
22446 +#include <linux/errno.h>
22447 +#include <linux/sched.h>
22448 +#include <linux/mm.h>
22449 +#include <linux/fs.h>
22450 +#include <linux/smp.h>
22451 +#include <linux/sem.h>
22452 +#include <linux/msg.h>
22453 +#include <linux/shm.h>
22454 +#include <linux/stat.h>
22455 +#include <linux/syscalls.h>
22456 +#include <linux/mman.h>
22457 +#include <linux/file.h>
22458 +#include <linux/utsname.h>
22459 +#include <linux/ipc.h>
22460 +
22461 +#include <linux/uaccess.h>
22462 +#include <linux/unistd.h>
22463 +
22464 +#include <asm/syscalls.h>
22465 +
22466 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22467 +{
22468 + unsigned long pax_task_size = TASK_SIZE;
22469 +
22470 +#ifdef CONFIG_PAX_SEGMEXEC
22471 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22472 + pax_task_size = SEGMEXEC_TASK_SIZE;
22473 +#endif
22474 +
22475 + if (flags & MAP_FIXED)
22476 + if (len > pax_task_size || addr > pax_task_size - len)
22477 + return -EINVAL;
22478 +
22479 + return 0;
22480 +}
22481 +
22482 +unsigned long
22483 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
22484 + unsigned long len, unsigned long pgoff, unsigned long flags)
22485 +{
22486 + struct mm_struct *mm = current->mm;
22487 + struct vm_area_struct *vma;
22488 + unsigned long start_addr, pax_task_size = TASK_SIZE;
22489 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22490 +
22491 +#ifdef CONFIG_PAX_SEGMEXEC
22492 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22493 + pax_task_size = SEGMEXEC_TASK_SIZE;
22494 +#endif
22495 +
22496 + pax_task_size -= PAGE_SIZE;
22497 +
22498 + if (len > pax_task_size)
22499 + return -ENOMEM;
22500 +
22501 + if (flags & MAP_FIXED)
22502 + return addr;
22503 +
22504 +#ifdef CONFIG_PAX_RANDMMAP
22505 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22506 +#endif
22507 +
22508 + if (addr) {
22509 + addr = PAGE_ALIGN(addr);
22510 + if (pax_task_size - len >= addr) {
22511 + vma = find_vma(mm, addr);
22512 + if (check_heap_stack_gap(vma, addr, len, offset))
22513 + return addr;
22514 + }
22515 + }
22516 + if (len > mm->cached_hole_size) {
22517 + start_addr = addr = mm->free_area_cache;
22518 + } else {
22519 + start_addr = addr = mm->mmap_base;
22520 + mm->cached_hole_size = 0;
22521 + }
22522 +
22523 +#ifdef CONFIG_PAX_PAGEEXEC
22524 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
22525 + start_addr = 0x00110000UL;
22526 +
22527 +#ifdef CONFIG_PAX_RANDMMAP
22528 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22529 + start_addr += mm->delta_mmap & 0x03FFF000UL;
22530 +#endif
22531 +
22532 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
22533 + start_addr = addr = mm->mmap_base;
22534 + else
22535 + addr = start_addr;
22536 + }
22537 +#endif
22538 +
22539 +full_search:
22540 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22541 + /* At this point: (!vma || addr < vma->vm_end). */
22542 + if (pax_task_size - len < addr) {
22543 + /*
22544 + * Start a new search - just in case we missed
22545 + * some holes.
22546 + */
22547 + if (start_addr != mm->mmap_base) {
22548 + start_addr = addr = mm->mmap_base;
22549 + mm->cached_hole_size = 0;
22550 + goto full_search;
22551 + }
22552 + return -ENOMEM;
22553 + }
22554 + if (check_heap_stack_gap(vma, addr, len, offset))
22555 + break;
22556 + if (addr + mm->cached_hole_size < vma->vm_start)
22557 + mm->cached_hole_size = vma->vm_start - addr;
22558 + addr = vma->vm_end;
22559 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
22560 + start_addr = addr = mm->mmap_base;
22561 + mm->cached_hole_size = 0;
22562 + goto full_search;
22563 + }
22564 + }
22565 +
22566 + /*
22567 + * Remember the place where we stopped the search:
22568 + */
22569 + mm->free_area_cache = addr + len;
22570 + return addr;
22571 +}
22572 +
22573 +unsigned long
22574 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22575 + const unsigned long len, const unsigned long pgoff,
22576 + const unsigned long flags)
22577 +{
22578 + struct vm_area_struct *vma;
22579 + struct mm_struct *mm = current->mm;
22580 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
22581 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22582 +
22583 +#ifdef CONFIG_PAX_SEGMEXEC
22584 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22585 + pax_task_size = SEGMEXEC_TASK_SIZE;
22586 +#endif
22587 +
22588 + pax_task_size -= PAGE_SIZE;
22589 +
22590 + /* requested length too big for entire address space */
22591 + if (len > pax_task_size)
22592 + return -ENOMEM;
22593 +
22594 + if (flags & MAP_FIXED)
22595 + return addr;
22596 +
22597 +#ifdef CONFIG_PAX_PAGEEXEC
22598 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
22599 + goto bottomup;
22600 +#endif
22601 +
22602 +#ifdef CONFIG_PAX_RANDMMAP
22603 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22604 +#endif
22605 +
22606 + /* requesting a specific address */
22607 + if (addr) {
22608 + addr = PAGE_ALIGN(addr);
22609 + if (pax_task_size - len >= addr) {
22610 + vma = find_vma(mm, addr);
22611 + if (check_heap_stack_gap(vma, addr, len, offset))
22612 + return addr;
22613 + }
22614 + }
22615 +
22616 + /* check if free_area_cache is useful for us */
22617 + if (len <= mm->cached_hole_size) {
22618 + mm->cached_hole_size = 0;
22619 + mm->free_area_cache = mm->mmap_base;
22620 + }
22621 +
22622 + /* either no address requested or can't fit in requested address hole */
22623 + addr = mm->free_area_cache;
22624 +
22625 + /* make sure it can fit in the remaining address space */
22626 + if (addr > len) {
22627 + vma = find_vma(mm, addr-len);
22628 + if (check_heap_stack_gap(vma, addr - len, len, offset))
22629 + /* remember the address as a hint for next time */
22630 + return (mm->free_area_cache = addr-len);
22631 + }
22632 +
22633 + if (mm->mmap_base < len)
22634 + goto bottomup;
22635 +
22636 + addr = mm->mmap_base-len;
22637 +
22638 + do {
22639 + /*
22640 + * Lookup failure means no vma is above this address,
22641 + * else if new region fits below vma->vm_start,
22642 + * return with success:
22643 + */
22644 + vma = find_vma(mm, addr);
22645 + if (check_heap_stack_gap(vma, addr, len, offset))
22646 + /* remember the address as a hint for next time */
22647 + return (mm->free_area_cache = addr);
22648 +
22649 + /* remember the largest hole we saw so far */
22650 + if (addr + mm->cached_hole_size < vma->vm_start)
22651 + mm->cached_hole_size = vma->vm_start - addr;
22652 +
22653 + /* try just below the current vma->vm_start */
22654 + addr = skip_heap_stack_gap(vma, len, offset);
22655 + } while (!IS_ERR_VALUE(addr));
22656 +
22657 +bottomup:
22658 + /*
22659 + * A failed mmap() very likely causes application failure,
22660 + * so fall back to the bottom-up function here. This scenario
22661 + * can happen with large stack limits and large mmap()
22662 + * allocations.
22663 + */
22664 +
22665 +#ifdef CONFIG_PAX_SEGMEXEC
22666 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22667 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22668 + else
22669 +#endif
22670 +
22671 + mm->mmap_base = TASK_UNMAPPED_BASE;
22672 +
22673 +#ifdef CONFIG_PAX_RANDMMAP
22674 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22675 + mm->mmap_base += mm->delta_mmap;
22676 +#endif
22677 +
22678 + mm->free_area_cache = mm->mmap_base;
22679 + mm->cached_hole_size = ~0UL;
22680 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
22681 + /*
22682 + * Restore the topdown base:
22683 + */
22684 + mm->mmap_base = base;
22685 + mm->free_area_cache = base;
22686 + mm->cached_hole_size = ~0UL;
22687 +
22688 + return addr;
22689 +}
22690 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
22691 index 97ef74b..57a1882 100644
22692 --- a/arch/x86/kernel/sys_x86_64.c
22693 +++ b/arch/x86/kernel/sys_x86_64.c
22694 @@ -81,8 +81,8 @@ out:
22695 return error;
22696 }
22697
22698 -static void find_start_end(unsigned long flags, unsigned long *begin,
22699 - unsigned long *end)
22700 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
22701 + unsigned long *begin, unsigned long *end)
22702 {
22703 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
22704 unsigned long new_begin;
22705 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
22706 *begin = new_begin;
22707 }
22708 } else {
22709 - *begin = TASK_UNMAPPED_BASE;
22710 + *begin = mm->mmap_base;
22711 *end = TASK_SIZE;
22712 }
22713 }
22714 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
22715 struct vm_area_struct *vma;
22716 struct vm_unmapped_area_info info;
22717 unsigned long begin, end;
22718 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22719
22720 if (flags & MAP_FIXED)
22721 return addr;
22722
22723 - find_start_end(flags, &begin, &end);
22724 + find_start_end(mm, flags, &begin, &end);
22725
22726 if (len > end)
22727 return -ENOMEM;
22728
22729 +#ifdef CONFIG_PAX_RANDMMAP
22730 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22731 +#endif
22732 +
22733 if (addr) {
22734 addr = PAGE_ALIGN(addr);
22735 vma = find_vma(mm, addr);
22736 - if (end - len >= addr &&
22737 - (!vma || addr + len <= vma->vm_start))
22738 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
22739 return addr;
22740 }
22741
22742 @@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22743 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
22744 goto bottomup;
22745
22746 +#ifdef CONFIG_PAX_RANDMMAP
22747 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22748 +#endif
22749 +
22750 /* requesting a specific address */
22751 if (addr) {
22752 addr = PAGE_ALIGN(addr);
22753 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
22754 index f84fe00..f41d9f1 100644
22755 --- a/arch/x86/kernel/tboot.c
22756 +++ b/arch/x86/kernel/tboot.c
22757 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
22758
22759 void tboot_shutdown(u32 shutdown_type)
22760 {
22761 - void (*shutdown)(void);
22762 + void (* __noreturn shutdown)(void);
22763
22764 if (!tboot_enabled())
22765 return;
22766 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
22767
22768 switch_to_tboot_pt();
22769
22770 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
22771 + shutdown = (void *)tboot->shutdown_entry;
22772 shutdown();
22773
22774 /* should not reach here */
22775 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
22776 return 0;
22777 }
22778
22779 -static atomic_t ap_wfs_count;
22780 +static atomic_unchecked_t ap_wfs_count;
22781
22782 static int tboot_wait_for_aps(int num_aps)
22783 {
22784 @@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
22785 {
22786 switch (action) {
22787 case CPU_DYING:
22788 - atomic_inc(&ap_wfs_count);
22789 + atomic_inc_unchecked(&ap_wfs_count);
22790 if (num_online_cpus() == 1)
22791 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
22792 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
22793 return NOTIFY_BAD;
22794 break;
22795 }
22796 return NOTIFY_OK;
22797 }
22798
22799 -static struct notifier_block tboot_cpu_notifier __cpuinitdata =
22800 +static struct notifier_block tboot_cpu_notifier =
22801 {
22802 .notifier_call = tboot_cpu_callback,
22803 };
22804 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
22805
22806 tboot_create_trampoline();
22807
22808 - atomic_set(&ap_wfs_count, 0);
22809 + atomic_set_unchecked(&ap_wfs_count, 0);
22810 register_hotcpu_notifier(&tboot_cpu_notifier);
22811
22812 acpi_os_set_prepare_sleep(&tboot_sleep);
22813 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
22814 index 24d3c91..d06b473 100644
22815 --- a/arch/x86/kernel/time.c
22816 +++ b/arch/x86/kernel/time.c
22817 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
22818 {
22819 unsigned long pc = instruction_pointer(regs);
22820
22821 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
22822 + if (!user_mode(regs) && in_lock_functions(pc)) {
22823 #ifdef CONFIG_FRAME_POINTER
22824 - return *(unsigned long *)(regs->bp + sizeof(long));
22825 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
22826 #else
22827 unsigned long *sp =
22828 (unsigned long *)kernel_stack_pointer(regs);
22829 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
22830 * or above a saved flags. Eflags has bits 22-31 zero,
22831 * kernel addresses don't.
22832 */
22833 +
22834 +#ifdef CONFIG_PAX_KERNEXEC
22835 + return ktla_ktva(sp[0]);
22836 +#else
22837 if (sp[0] >> 22)
22838 return sp[0];
22839 if (sp[1] >> 22)
22840 return sp[1];
22841 #endif
22842 +
22843 +#endif
22844 }
22845 return pc;
22846 }
22847 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
22848 index 9d9d2f9..cad418a 100644
22849 --- a/arch/x86/kernel/tls.c
22850 +++ b/arch/x86/kernel/tls.c
22851 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
22852 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
22853 return -EINVAL;
22854
22855 +#ifdef CONFIG_PAX_SEGMEXEC
22856 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
22857 + return -EINVAL;
22858 +#endif
22859 +
22860 set_tls_desc(p, idx, &info, 1);
22861
22862 return 0;
22863 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
22864
22865 if (kbuf)
22866 info = kbuf;
22867 - else if (__copy_from_user(infobuf, ubuf, count))
22868 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
22869 return -EFAULT;
22870 else
22871 info = infobuf;
22872 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
22873 index ecffca1..95c4d13 100644
22874 --- a/arch/x86/kernel/traps.c
22875 +++ b/arch/x86/kernel/traps.c
22876 @@ -68,12 +68,6 @@
22877 #include <asm/setup.h>
22878
22879 asmlinkage int system_call(void);
22880 -
22881 -/*
22882 - * The IDT has to be page-aligned to simplify the Pentium
22883 - * F0 0F bug workaround.
22884 - */
22885 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
22886 #endif
22887
22888 DECLARE_BITMAP(used_vectors, NR_VECTORS);
22889 @@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
22890 }
22891
22892 static int __kprobes
22893 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22894 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
22895 struct pt_regs *regs, long error_code)
22896 {
22897 #ifdef CONFIG_X86_32
22898 - if (regs->flags & X86_VM_MASK) {
22899 + if (v8086_mode(regs)) {
22900 /*
22901 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
22902 * On nmi (interrupt 2), do_trap should not be called.
22903 @@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22904 return -1;
22905 }
22906 #endif
22907 - if (!user_mode(regs)) {
22908 + if (!user_mode_novm(regs)) {
22909 if (!fixup_exception(regs)) {
22910 tsk->thread.error_code = error_code;
22911 tsk->thread.trap_nr = trapnr;
22912 +
22913 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22914 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
22915 + str = "PAX: suspicious stack segment fault";
22916 +#endif
22917 +
22918 die(str, regs, error_code);
22919 }
22920 +
22921 +#ifdef CONFIG_PAX_REFCOUNT
22922 + if (trapnr == 4)
22923 + pax_report_refcount_overflow(regs);
22924 +#endif
22925 +
22926 return 0;
22927 }
22928
22929 @@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22930 }
22931
22932 static void __kprobes
22933 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22934 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
22935 long error_code, siginfo_t *info)
22936 {
22937 struct task_struct *tsk = current;
22938 @@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22939 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
22940 printk_ratelimit()) {
22941 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
22942 - tsk->comm, tsk->pid, str,
22943 + tsk->comm, task_pid_nr(tsk), str,
22944 regs->ip, regs->sp, error_code);
22945 print_vma_addr(" in ", regs->ip);
22946 pr_cont("\n");
22947 @@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
22948 conditional_sti(regs);
22949
22950 #ifdef CONFIG_X86_32
22951 - if (regs->flags & X86_VM_MASK) {
22952 + if (v8086_mode(regs)) {
22953 local_irq_enable();
22954 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
22955 goto exit;
22956 @@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
22957 #endif
22958
22959 tsk = current;
22960 - if (!user_mode(regs)) {
22961 + if (!user_mode_novm(regs)) {
22962 if (fixup_exception(regs))
22963 goto exit;
22964
22965 tsk->thread.error_code = error_code;
22966 tsk->thread.trap_nr = X86_TRAP_GP;
22967 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
22968 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
22969 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
22970 +
22971 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22972 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
22973 + die("PAX: suspicious general protection fault", regs, error_code);
22974 + else
22975 +#endif
22976 +
22977 die("general protection fault", regs, error_code);
22978 + }
22979 goto exit;
22980 }
22981
22982 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
22983 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
22984 + struct mm_struct *mm = tsk->mm;
22985 + unsigned long limit;
22986 +
22987 + down_write(&mm->mmap_sem);
22988 + limit = mm->context.user_cs_limit;
22989 + if (limit < TASK_SIZE) {
22990 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
22991 + up_write(&mm->mmap_sem);
22992 + return;
22993 + }
22994 + up_write(&mm->mmap_sem);
22995 + }
22996 +#endif
22997 +
22998 tsk->thread.error_code = error_code;
22999 tsk->thread.trap_nr = X86_TRAP_GP;
23000
23001 @@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23002 /* It's safe to allow irq's after DR6 has been saved */
23003 preempt_conditional_sti(regs);
23004
23005 - if (regs->flags & X86_VM_MASK) {
23006 + if (v8086_mode(regs)) {
23007 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23008 X86_TRAP_DB);
23009 preempt_conditional_cli(regs);
23010 @@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23011 * We already checked v86 mode above, so we can check for kernel mode
23012 * by just checking the CPL of CS.
23013 */
23014 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
23015 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23016 tsk->thread.debugreg6 &= ~DR_STEP;
23017 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23018 regs->flags &= ~X86_EFLAGS_TF;
23019 @@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23020 return;
23021 conditional_sti(regs);
23022
23023 - if (!user_mode_vm(regs))
23024 + if (!user_mode(regs))
23025 {
23026 if (!fixup_exception(regs)) {
23027 task->thread.error_code = error_code;
23028 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23029 index c71025b..b117501 100644
23030 --- a/arch/x86/kernel/uprobes.c
23031 +++ b/arch/x86/kernel/uprobes.c
23032 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23033 int ret = NOTIFY_DONE;
23034
23035 /* We are only interested in userspace traps */
23036 - if (regs && !user_mode_vm(regs))
23037 + if (regs && !user_mode(regs))
23038 return NOTIFY_DONE;
23039
23040 switch (val) {
23041 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23042 index b9242ba..50c5edd 100644
23043 --- a/arch/x86/kernel/verify_cpu.S
23044 +++ b/arch/x86/kernel/verify_cpu.S
23045 @@ -20,6 +20,7 @@
23046 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23047 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23048 * arch/x86/kernel/head_32.S: processor startup
23049 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23050 *
23051 * verify_cpu, returns the status of longmode and SSE in register %eax.
23052 * 0: Success 1: Failure
23053 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23054 index 1dfe69c..a3df6f6 100644
23055 --- a/arch/x86/kernel/vm86_32.c
23056 +++ b/arch/x86/kernel/vm86_32.c
23057 @@ -43,6 +43,7 @@
23058 #include <linux/ptrace.h>
23059 #include <linux/audit.h>
23060 #include <linux/stddef.h>
23061 +#include <linux/grsecurity.h>
23062
23063 #include <asm/uaccess.h>
23064 #include <asm/io.h>
23065 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23066 do_exit(SIGSEGV);
23067 }
23068
23069 - tss = &per_cpu(init_tss, get_cpu());
23070 + tss = init_tss + get_cpu();
23071 current->thread.sp0 = current->thread.saved_sp0;
23072 current->thread.sysenter_cs = __KERNEL_CS;
23073 load_sp0(tss, &current->thread);
23074 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
23075 struct task_struct *tsk;
23076 int tmp, ret = -EPERM;
23077
23078 +#ifdef CONFIG_GRKERNSEC_VM86
23079 + if (!capable(CAP_SYS_RAWIO)) {
23080 + gr_handle_vm86();
23081 + goto out;
23082 + }
23083 +#endif
23084 +
23085 tsk = current;
23086 if (tsk->thread.saved_sp0)
23087 goto out;
23088 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
23089 int tmp, ret;
23090 struct vm86plus_struct __user *v86;
23091
23092 +#ifdef CONFIG_GRKERNSEC_VM86
23093 + if (!capable(CAP_SYS_RAWIO)) {
23094 + gr_handle_vm86();
23095 + ret = -EPERM;
23096 + goto out;
23097 + }
23098 +#endif
23099 +
23100 tsk = current;
23101 switch (cmd) {
23102 case VM86_REQUEST_IRQ:
23103 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23104 tsk->thread.saved_fs = info->regs32->fs;
23105 tsk->thread.saved_gs = get_user_gs(info->regs32);
23106
23107 - tss = &per_cpu(init_tss, get_cpu());
23108 + tss = init_tss + get_cpu();
23109 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23110 if (cpu_has_sep)
23111 tsk->thread.sysenter_cs = 0;
23112 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23113 goto cannot_handle;
23114 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23115 goto cannot_handle;
23116 - intr_ptr = (unsigned long __user *) (i << 2);
23117 + intr_ptr = (__force unsigned long __user *) (i << 2);
23118 if (get_user(segoffs, intr_ptr))
23119 goto cannot_handle;
23120 if ((segoffs >> 16) == BIOSSEG)
23121 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23122 index 22a1530..8fbaaad 100644
23123 --- a/arch/x86/kernel/vmlinux.lds.S
23124 +++ b/arch/x86/kernel/vmlinux.lds.S
23125 @@ -26,6 +26,13 @@
23126 #include <asm/page_types.h>
23127 #include <asm/cache.h>
23128 #include <asm/boot.h>
23129 +#include <asm/segment.h>
23130 +
23131 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23132 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23133 +#else
23134 +#define __KERNEL_TEXT_OFFSET 0
23135 +#endif
23136
23137 #undef i386 /* in case the preprocessor is a 32bit one */
23138
23139 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23140
23141 PHDRS {
23142 text PT_LOAD FLAGS(5); /* R_E */
23143 +#ifdef CONFIG_X86_32
23144 + module PT_LOAD FLAGS(5); /* R_E */
23145 +#endif
23146 +#ifdef CONFIG_XEN
23147 + rodata PT_LOAD FLAGS(5); /* R_E */
23148 +#else
23149 + rodata PT_LOAD FLAGS(4); /* R__ */
23150 +#endif
23151 data PT_LOAD FLAGS(6); /* RW_ */
23152 -#ifdef CONFIG_X86_64
23153 + init.begin PT_LOAD FLAGS(6); /* RW_ */
23154 #ifdef CONFIG_SMP
23155 percpu PT_LOAD FLAGS(6); /* RW_ */
23156 #endif
23157 + text.init PT_LOAD FLAGS(5); /* R_E */
23158 + text.exit PT_LOAD FLAGS(5); /* R_E */
23159 init PT_LOAD FLAGS(7); /* RWE */
23160 -#endif
23161 note PT_NOTE FLAGS(0); /* ___ */
23162 }
23163
23164 SECTIONS
23165 {
23166 #ifdef CONFIG_X86_32
23167 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23168 - phys_startup_32 = startup_32 - LOAD_OFFSET;
23169 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23170 #else
23171 - . = __START_KERNEL;
23172 - phys_startup_64 = startup_64 - LOAD_OFFSET;
23173 + . = __START_KERNEL;
23174 #endif
23175
23176 /* Text and read-only data */
23177 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
23178 - _text = .;
23179 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23180 /* bootstrapping code */
23181 +#ifdef CONFIG_X86_32
23182 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23183 +#else
23184 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23185 +#endif
23186 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23187 + _text = .;
23188 HEAD_TEXT
23189 #ifdef CONFIG_X86_32
23190 . = ALIGN(PAGE_SIZE);
23191 @@ -108,13 +128,48 @@ SECTIONS
23192 IRQENTRY_TEXT
23193 *(.fixup)
23194 *(.gnu.warning)
23195 - /* End of text section */
23196 - _etext = .;
23197 } :text = 0x9090
23198
23199 - NOTES :text :note
23200 + . += __KERNEL_TEXT_OFFSET;
23201
23202 - EXCEPTION_TABLE(16) :text = 0x9090
23203 +#ifdef CONFIG_X86_32
23204 + . = ALIGN(PAGE_SIZE);
23205 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23206 +
23207 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
23208 + MODULES_EXEC_VADDR = .;
23209 + BYTE(0)
23210 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23211 + . = ALIGN(HPAGE_SIZE) - 1;
23212 + MODULES_EXEC_END = .;
23213 +#endif
23214 +
23215 + } :module
23216 +#endif
23217 +
23218 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23219 + /* End of text section */
23220 + BYTE(0)
23221 + _etext = . - __KERNEL_TEXT_OFFSET;
23222 + }
23223 +
23224 +#ifdef CONFIG_X86_32
23225 + . = ALIGN(PAGE_SIZE);
23226 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23227 + *(.idt)
23228 + . = ALIGN(PAGE_SIZE);
23229 + *(.empty_zero_page)
23230 + *(.initial_pg_fixmap)
23231 + *(.initial_pg_pmd)
23232 + *(.initial_page_table)
23233 + *(.swapper_pg_dir)
23234 + } :rodata
23235 +#endif
23236 +
23237 + . = ALIGN(PAGE_SIZE);
23238 + NOTES :rodata :note
23239 +
23240 + EXCEPTION_TABLE(16) :rodata
23241
23242 #if defined(CONFIG_DEBUG_RODATA)
23243 /* .text should occupy whole number of pages */
23244 @@ -126,16 +181,20 @@ SECTIONS
23245
23246 /* Data */
23247 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23248 +
23249 +#ifdef CONFIG_PAX_KERNEXEC
23250 + . = ALIGN(HPAGE_SIZE);
23251 +#else
23252 + . = ALIGN(PAGE_SIZE);
23253 +#endif
23254 +
23255 /* Start of data section */
23256 _sdata = .;
23257
23258 /* init_task */
23259 INIT_TASK_DATA(THREAD_SIZE)
23260
23261 -#ifdef CONFIG_X86_32
23262 - /* 32 bit has nosave before _edata */
23263 NOSAVE_DATA
23264 -#endif
23265
23266 PAGE_ALIGNED_DATA(PAGE_SIZE)
23267
23268 @@ -176,12 +235,19 @@ SECTIONS
23269 #endif /* CONFIG_X86_64 */
23270
23271 /* Init code and data - will be freed after init */
23272 - . = ALIGN(PAGE_SIZE);
23273 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23274 + BYTE(0)
23275 +
23276 +#ifdef CONFIG_PAX_KERNEXEC
23277 + . = ALIGN(HPAGE_SIZE);
23278 +#else
23279 + . = ALIGN(PAGE_SIZE);
23280 +#endif
23281 +
23282 __init_begin = .; /* paired with __init_end */
23283 - }
23284 + } :init.begin
23285
23286 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23287 +#ifdef CONFIG_SMP
23288 /*
23289 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23290 * output PHDR, so the next output section - .init.text - should
23291 @@ -190,12 +256,27 @@ SECTIONS
23292 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23293 #endif
23294
23295 - INIT_TEXT_SECTION(PAGE_SIZE)
23296 -#ifdef CONFIG_X86_64
23297 - :init
23298 -#endif
23299 + . = ALIGN(PAGE_SIZE);
23300 + init_begin = .;
23301 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23302 + VMLINUX_SYMBOL(_sinittext) = .;
23303 + INIT_TEXT
23304 + VMLINUX_SYMBOL(_einittext) = .;
23305 + . = ALIGN(PAGE_SIZE);
23306 + } :text.init
23307
23308 - INIT_DATA_SECTION(16)
23309 + /*
23310 + * .exit.text is discard at runtime, not link time, to deal with
23311 + * references from .altinstructions and .eh_frame
23312 + */
23313 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23314 + EXIT_TEXT
23315 + . = ALIGN(16);
23316 + } :text.exit
23317 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23318 +
23319 + . = ALIGN(PAGE_SIZE);
23320 + INIT_DATA_SECTION(16) :init
23321
23322 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23323 __x86_cpu_dev_start = .;
23324 @@ -257,19 +338,12 @@ SECTIONS
23325 }
23326
23327 . = ALIGN(8);
23328 - /*
23329 - * .exit.text is discard at runtime, not link time, to deal with
23330 - * references from .altinstructions and .eh_frame
23331 - */
23332 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23333 - EXIT_TEXT
23334 - }
23335
23336 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23337 EXIT_DATA
23338 }
23339
23340 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23341 +#ifndef CONFIG_SMP
23342 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23343 #endif
23344
23345 @@ -288,16 +362,10 @@ SECTIONS
23346 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23347 __smp_locks = .;
23348 *(.smp_locks)
23349 - . = ALIGN(PAGE_SIZE);
23350 __smp_locks_end = .;
23351 + . = ALIGN(PAGE_SIZE);
23352 }
23353
23354 -#ifdef CONFIG_X86_64
23355 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23356 - NOSAVE_DATA
23357 - }
23358 -#endif
23359 -
23360 /* BSS */
23361 . = ALIGN(PAGE_SIZE);
23362 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23363 @@ -313,6 +381,7 @@ SECTIONS
23364 __brk_base = .;
23365 . += 64 * 1024; /* 64k alignment slop space */
23366 *(.brk_reservation) /* areas brk users have reserved */
23367 + . = ALIGN(HPAGE_SIZE);
23368 __brk_limit = .;
23369 }
23370
23371 @@ -339,13 +408,12 @@ SECTIONS
23372 * for the boot processor.
23373 */
23374 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23375 -INIT_PER_CPU(gdt_page);
23376 INIT_PER_CPU(irq_stack_union);
23377
23378 /*
23379 * Build-time check on the image size:
23380 */
23381 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23382 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23383 "kernel image bigger than KERNEL_IMAGE_SIZE");
23384
23385 #ifdef CONFIG_SMP
23386 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23387 index 9a907a6..f83f921 100644
23388 --- a/arch/x86/kernel/vsyscall_64.c
23389 +++ b/arch/x86/kernel/vsyscall_64.c
23390 @@ -56,15 +56,13 @@
23391 DEFINE_VVAR(int, vgetcpu_mode);
23392 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23393
23394 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23395 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23396
23397 static int __init vsyscall_setup(char *str)
23398 {
23399 if (str) {
23400 if (!strcmp("emulate", str))
23401 vsyscall_mode = EMULATE;
23402 - else if (!strcmp("native", str))
23403 - vsyscall_mode = NATIVE;
23404 else if (!strcmp("none", str))
23405 vsyscall_mode = NONE;
23406 else
23407 @@ -323,8 +321,7 @@ do_ret:
23408 return true;
23409
23410 sigsegv:
23411 - force_sig(SIGSEGV, current);
23412 - return true;
23413 + do_group_exit(SIGKILL);
23414 }
23415
23416 /*
23417 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23418 extern char __vvar_page;
23419 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23420
23421 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23422 - vsyscall_mode == NATIVE
23423 - ? PAGE_KERNEL_VSYSCALL
23424 - : PAGE_KERNEL_VVAR);
23425 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23426 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23427 (unsigned long)VSYSCALL_START);
23428
23429 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23430 index 1330dd1..d220b99 100644
23431 --- a/arch/x86/kernel/x8664_ksyms_64.c
23432 +++ b/arch/x86/kernel/x8664_ksyms_64.c
23433 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23434 EXPORT_SYMBOL(copy_user_generic_unrolled);
23435 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23436 EXPORT_SYMBOL(__copy_user_nocache);
23437 -EXPORT_SYMBOL(_copy_from_user);
23438 -EXPORT_SYMBOL(_copy_to_user);
23439
23440 EXPORT_SYMBOL(copy_page);
23441 EXPORT_SYMBOL(clear_page);
23442 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23443 index 7a3d075..6cb373d 100644
23444 --- a/arch/x86/kernel/x86_init.c
23445 +++ b/arch/x86/kernel/x86_init.c
23446 @@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
23447 },
23448 };
23449
23450 -struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23451 +struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23452 .early_percpu_clock_init = x86_init_noop,
23453 .setup_percpu_clockev = setup_secondary_APIC_clock,
23454 };
23455 @@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23456 static void default_nmi_init(void) { };
23457 static int default_i8042_detect(void) { return 1; };
23458
23459 -struct x86_platform_ops x86_platform = {
23460 +struct x86_platform_ops x86_platform __read_only = {
23461 .calibrate_tsc = native_calibrate_tsc,
23462 .get_wallclock = mach_get_cmos_time,
23463 .set_wallclock = mach_set_rtc_mmss,
23464 @@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
23465 };
23466
23467 EXPORT_SYMBOL_GPL(x86_platform);
23468 -struct x86_msi_ops x86_msi = {
23469 +struct x86_msi_ops x86_msi __read_only = {
23470 .setup_msi_irqs = native_setup_msi_irqs,
23471 .teardown_msi_irq = native_teardown_msi_irq,
23472 .teardown_msi_irqs = default_teardown_msi_irqs,
23473 .restore_msi_irqs = default_restore_msi_irqs,
23474 };
23475
23476 -struct x86_io_apic_ops x86_io_apic_ops = {
23477 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23478 .init = native_io_apic_init_mappings,
23479 .read = native_io_apic_read,
23480 .write = native_io_apic_write,
23481 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23482 index ada87a3..afea76d 100644
23483 --- a/arch/x86/kernel/xsave.c
23484 +++ b/arch/x86/kernel/xsave.c
23485 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23486 {
23487 int err;
23488
23489 + buf = (struct xsave_struct __user *)____m(buf);
23490 if (use_xsave())
23491 err = xsave_user(buf);
23492 else if (use_fxsr())
23493 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23494 */
23495 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23496 {
23497 + buf = (void __user *)____m(buf);
23498 if (use_xsave()) {
23499 if ((unsigned long)buf % 64 || fx_only) {
23500 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23501 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23502 index a20ecb5..d0e2194 100644
23503 --- a/arch/x86/kvm/cpuid.c
23504 +++ b/arch/x86/kvm/cpuid.c
23505 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23506 struct kvm_cpuid2 *cpuid,
23507 struct kvm_cpuid_entry2 __user *entries)
23508 {
23509 - int r;
23510 + int r, i;
23511
23512 r = -E2BIG;
23513 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23514 goto out;
23515 r = -EFAULT;
23516 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23517 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23518 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23519 goto out;
23520 + for (i = 0; i < cpuid->nent; ++i) {
23521 + struct kvm_cpuid_entry2 cpuid_entry;
23522 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23523 + goto out;
23524 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
23525 + }
23526 vcpu->arch.cpuid_nent = cpuid->nent;
23527 kvm_apic_set_version(vcpu);
23528 kvm_x86_ops->cpuid_update(vcpu);
23529 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23530 struct kvm_cpuid2 *cpuid,
23531 struct kvm_cpuid_entry2 __user *entries)
23532 {
23533 - int r;
23534 + int r, i;
23535
23536 r = -E2BIG;
23537 if (cpuid->nent < vcpu->arch.cpuid_nent)
23538 goto out;
23539 r = -EFAULT;
23540 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23541 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23542 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23543 goto out;
23544 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23545 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23546 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23547 + goto out;
23548 + }
23549 return 0;
23550
23551 out:
23552 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23553 index a27e763..54bfe43 100644
23554 --- a/arch/x86/kvm/emulate.c
23555 +++ b/arch/x86/kvm/emulate.c
23556 @@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23557
23558 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23559 do { \
23560 + unsigned long _tmp; \
23561 __asm__ __volatile__ ( \
23562 _PRE_EFLAGS("0", "4", "2") \
23563 _op _suffix " %"_x"3,%1; " \
23564 @@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23565 /* Raw emulation: instruction has two explicit operands. */
23566 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23567 do { \
23568 - unsigned long _tmp; \
23569 - \
23570 switch ((ctxt)->dst.bytes) { \
23571 case 2: \
23572 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
23573 @@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23574
23575 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
23576 do { \
23577 - unsigned long _tmp; \
23578 switch ((ctxt)->dst.bytes) { \
23579 case 1: \
23580 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
23581 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
23582 index 9392f52..0e56d77 100644
23583 --- a/arch/x86/kvm/lapic.c
23584 +++ b/arch/x86/kvm/lapic.c
23585 @@ -55,7 +55,7 @@
23586 #define APIC_BUS_CYCLE_NS 1
23587
23588 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
23589 -#define apic_debug(fmt, arg...)
23590 +#define apic_debug(fmt, arg...) do {} while (0)
23591
23592 #define APIC_LVT_NUM 6
23593 /* 14 is the version for Xeon and Pentium 8.4.8*/
23594 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
23595 index 891eb6d..e027900 100644
23596 --- a/arch/x86/kvm/paging_tmpl.h
23597 +++ b/arch/x86/kvm/paging_tmpl.h
23598 @@ -208,7 +208,7 @@ retry_walk:
23599 if (unlikely(kvm_is_error_hva(host_addr)))
23600 goto error;
23601
23602 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
23603 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
23604 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
23605 goto error;
23606 walker->ptep_user[walker->level - 1] = ptep_user;
23607 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
23608 index d29d3cd..ec9d522 100644
23609 --- a/arch/x86/kvm/svm.c
23610 +++ b/arch/x86/kvm/svm.c
23611 @@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
23612 int cpu = raw_smp_processor_id();
23613
23614 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
23615 +
23616 + pax_open_kernel();
23617 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
23618 + pax_close_kernel();
23619 +
23620 load_TR_desc();
23621 }
23622
23623 @@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
23624 #endif
23625 #endif
23626
23627 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23628 + __set_fs(current_thread_info()->addr_limit);
23629 +#endif
23630 +
23631 reload_tss(vcpu);
23632
23633 local_irq_disable();
23634 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
23635 index 9120ae1..238abc0 100644
23636 --- a/arch/x86/kvm/vmx.c
23637 +++ b/arch/x86/kvm/vmx.c
23638 @@ -1370,7 +1370,11 @@ static void reload_tss(void)
23639 struct desc_struct *descs;
23640
23641 descs = (void *)gdt->address;
23642 +
23643 + pax_open_kernel();
23644 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
23645 + pax_close_kernel();
23646 +
23647 load_TR_desc();
23648 }
23649
23650 @@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
23651 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
23652 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
23653
23654 +#ifdef CONFIG_PAX_PER_CPU_PGD
23655 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23656 +#endif
23657 +
23658 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
23659 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
23660 vmx->loaded_vmcs->cpu = cpu;
23661 @@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
23662 if (!cpu_has_vmx_flexpriority())
23663 flexpriority_enabled = 0;
23664
23665 - if (!cpu_has_vmx_tpr_shadow())
23666 - kvm_x86_ops->update_cr8_intercept = NULL;
23667 + if (!cpu_has_vmx_tpr_shadow()) {
23668 + pax_open_kernel();
23669 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
23670 + pax_close_kernel();
23671 + }
23672
23673 if (enable_ept && !cpu_has_vmx_ept_2m_page())
23674 kvm_disable_largepages();
23675 @@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
23676
23677 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
23678 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
23679 +
23680 +#ifndef CONFIG_PAX_PER_CPU_PGD
23681 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23682 +#endif
23683
23684 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
23685 #ifdef CONFIG_X86_64
23686 @@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
23687 native_store_idt(&dt);
23688 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
23689
23690 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
23691 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
23692
23693 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
23694 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
23695 @@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23696 "jmp 2f \n\t"
23697 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
23698 "2: "
23699 +
23700 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23701 + "ljmp %[cs],$3f\n\t"
23702 + "3: "
23703 +#endif
23704 +
23705 /* Save guest registers, load host registers, keep flags */
23706 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
23707 "pop %0 \n\t"
23708 @@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23709 #endif
23710 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
23711 [wordsize]"i"(sizeof(ulong))
23712 +
23713 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23714 + ,[cs]"i"(__KERNEL_CS)
23715 +#endif
23716 +
23717 : "cc", "memory"
23718 #ifdef CONFIG_X86_64
23719 , "rax", "rbx", "rdi", "rsi"
23720 @@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23721 if (debugctlmsr)
23722 update_debugctlmsr(debugctlmsr);
23723
23724 -#ifndef CONFIG_X86_64
23725 +#ifdef CONFIG_X86_32
23726 /*
23727 * The sysexit path does not restore ds/es, so we must set them to
23728 * a reasonable value ourselves.
23729 @@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23730 * may be executed in interrupt context, which saves and restore segments
23731 * around it, nullifying its effect.
23732 */
23733 - loadsegment(ds, __USER_DS);
23734 - loadsegment(es, __USER_DS);
23735 + loadsegment(ds, __KERNEL_DS);
23736 + loadsegment(es, __KERNEL_DS);
23737 + loadsegment(ss, __KERNEL_DS);
23738 +
23739 +#ifdef CONFIG_PAX_KERNEXEC
23740 + loadsegment(fs, __KERNEL_PERCPU);
23741 +#endif
23742 +
23743 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23744 + __set_fs(current_thread_info()->addr_limit);
23745 +#endif
23746 +
23747 #endif
23748
23749 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
23750 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
23751 index c243b81..9eb193f 100644
23752 --- a/arch/x86/kvm/x86.c
23753 +++ b/arch/x86/kvm/x86.c
23754 @@ -1692,8 +1692,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
23755 {
23756 struct kvm *kvm = vcpu->kvm;
23757 int lm = is_long_mode(vcpu);
23758 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23759 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23760 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23761 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23762 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
23763 : kvm->arch.xen_hvm_config.blob_size_32;
23764 u32 page_num = data & ~PAGE_MASK;
23765 @@ -2571,6 +2571,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
23766 if (n < msr_list.nmsrs)
23767 goto out;
23768 r = -EFAULT;
23769 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
23770 + goto out;
23771 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
23772 num_msrs_to_save * sizeof(u32)))
23773 goto out;
23774 @@ -2700,7 +2702,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
23775 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
23776 struct kvm_interrupt *irq)
23777 {
23778 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
23779 + if (irq->irq >= KVM_NR_INTERRUPTS)
23780 return -EINVAL;
23781 if (irqchip_in_kernel(vcpu->kvm))
23782 return -ENXIO;
23783 @@ -5213,7 +5215,7 @@ static struct notifier_block pvclock_gtod_notifier = {
23784 };
23785 #endif
23786
23787 -int kvm_arch_init(void *opaque)
23788 +int kvm_arch_init(const void *opaque)
23789 {
23790 int r;
23791 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
23792 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
23793 index df4176c..23ce092 100644
23794 --- a/arch/x86/lguest/boot.c
23795 +++ b/arch/x86/lguest/boot.c
23796 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
23797 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
23798 * Launcher to reboot us.
23799 */
23800 -static void lguest_restart(char *reason)
23801 +static __noreturn void lguest_restart(char *reason)
23802 {
23803 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
23804 + BUG();
23805 }
23806
23807 /*G:050
23808 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
23809 index 00933d5..3a64af9 100644
23810 --- a/arch/x86/lib/atomic64_386_32.S
23811 +++ b/arch/x86/lib/atomic64_386_32.S
23812 @@ -48,6 +48,10 @@ BEGIN(read)
23813 movl (v), %eax
23814 movl 4(v), %edx
23815 RET_ENDP
23816 +BEGIN(read_unchecked)
23817 + movl (v), %eax
23818 + movl 4(v), %edx
23819 +RET_ENDP
23820 #undef v
23821
23822 #define v %esi
23823 @@ -55,6 +59,10 @@ BEGIN(set)
23824 movl %ebx, (v)
23825 movl %ecx, 4(v)
23826 RET_ENDP
23827 +BEGIN(set_unchecked)
23828 + movl %ebx, (v)
23829 + movl %ecx, 4(v)
23830 +RET_ENDP
23831 #undef v
23832
23833 #define v %esi
23834 @@ -70,6 +78,20 @@ RET_ENDP
23835 BEGIN(add)
23836 addl %eax, (v)
23837 adcl %edx, 4(v)
23838 +
23839 +#ifdef CONFIG_PAX_REFCOUNT
23840 + jno 0f
23841 + subl %eax, (v)
23842 + sbbl %edx, 4(v)
23843 + int $4
23844 +0:
23845 + _ASM_EXTABLE(0b, 0b)
23846 +#endif
23847 +
23848 +RET_ENDP
23849 +BEGIN(add_unchecked)
23850 + addl %eax, (v)
23851 + adcl %edx, 4(v)
23852 RET_ENDP
23853 #undef v
23854
23855 @@ -77,6 +99,24 @@ RET_ENDP
23856 BEGIN(add_return)
23857 addl (v), %eax
23858 adcl 4(v), %edx
23859 +
23860 +#ifdef CONFIG_PAX_REFCOUNT
23861 + into
23862 +1234:
23863 + _ASM_EXTABLE(1234b, 2f)
23864 +#endif
23865 +
23866 + movl %eax, (v)
23867 + movl %edx, 4(v)
23868 +
23869 +#ifdef CONFIG_PAX_REFCOUNT
23870 +2:
23871 +#endif
23872 +
23873 +RET_ENDP
23874 +BEGIN(add_return_unchecked)
23875 + addl (v), %eax
23876 + adcl 4(v), %edx
23877 movl %eax, (v)
23878 movl %edx, 4(v)
23879 RET_ENDP
23880 @@ -86,6 +126,20 @@ RET_ENDP
23881 BEGIN(sub)
23882 subl %eax, (v)
23883 sbbl %edx, 4(v)
23884 +
23885 +#ifdef CONFIG_PAX_REFCOUNT
23886 + jno 0f
23887 + addl %eax, (v)
23888 + adcl %edx, 4(v)
23889 + int $4
23890 +0:
23891 + _ASM_EXTABLE(0b, 0b)
23892 +#endif
23893 +
23894 +RET_ENDP
23895 +BEGIN(sub_unchecked)
23896 + subl %eax, (v)
23897 + sbbl %edx, 4(v)
23898 RET_ENDP
23899 #undef v
23900
23901 @@ -96,6 +150,27 @@ BEGIN(sub_return)
23902 sbbl $0, %edx
23903 addl (v), %eax
23904 adcl 4(v), %edx
23905 +
23906 +#ifdef CONFIG_PAX_REFCOUNT
23907 + into
23908 +1234:
23909 + _ASM_EXTABLE(1234b, 2f)
23910 +#endif
23911 +
23912 + movl %eax, (v)
23913 + movl %edx, 4(v)
23914 +
23915 +#ifdef CONFIG_PAX_REFCOUNT
23916 +2:
23917 +#endif
23918 +
23919 +RET_ENDP
23920 +BEGIN(sub_return_unchecked)
23921 + negl %edx
23922 + negl %eax
23923 + sbbl $0, %edx
23924 + addl (v), %eax
23925 + adcl 4(v), %edx
23926 movl %eax, (v)
23927 movl %edx, 4(v)
23928 RET_ENDP
23929 @@ -105,6 +180,20 @@ RET_ENDP
23930 BEGIN(inc)
23931 addl $1, (v)
23932 adcl $0, 4(v)
23933 +
23934 +#ifdef CONFIG_PAX_REFCOUNT
23935 + jno 0f
23936 + subl $1, (v)
23937 + sbbl $0, 4(v)
23938 + int $4
23939 +0:
23940 + _ASM_EXTABLE(0b, 0b)
23941 +#endif
23942 +
23943 +RET_ENDP
23944 +BEGIN(inc_unchecked)
23945 + addl $1, (v)
23946 + adcl $0, 4(v)
23947 RET_ENDP
23948 #undef v
23949
23950 @@ -114,6 +203,26 @@ BEGIN(inc_return)
23951 movl 4(v), %edx
23952 addl $1, %eax
23953 adcl $0, %edx
23954 +
23955 +#ifdef CONFIG_PAX_REFCOUNT
23956 + into
23957 +1234:
23958 + _ASM_EXTABLE(1234b, 2f)
23959 +#endif
23960 +
23961 + movl %eax, (v)
23962 + movl %edx, 4(v)
23963 +
23964 +#ifdef CONFIG_PAX_REFCOUNT
23965 +2:
23966 +#endif
23967 +
23968 +RET_ENDP
23969 +BEGIN(inc_return_unchecked)
23970 + movl (v), %eax
23971 + movl 4(v), %edx
23972 + addl $1, %eax
23973 + adcl $0, %edx
23974 movl %eax, (v)
23975 movl %edx, 4(v)
23976 RET_ENDP
23977 @@ -123,6 +232,20 @@ RET_ENDP
23978 BEGIN(dec)
23979 subl $1, (v)
23980 sbbl $0, 4(v)
23981 +
23982 +#ifdef CONFIG_PAX_REFCOUNT
23983 + jno 0f
23984 + addl $1, (v)
23985 + adcl $0, 4(v)
23986 + int $4
23987 +0:
23988 + _ASM_EXTABLE(0b, 0b)
23989 +#endif
23990 +
23991 +RET_ENDP
23992 +BEGIN(dec_unchecked)
23993 + subl $1, (v)
23994 + sbbl $0, 4(v)
23995 RET_ENDP
23996 #undef v
23997
23998 @@ -132,6 +255,26 @@ BEGIN(dec_return)
23999 movl 4(v), %edx
24000 subl $1, %eax
24001 sbbl $0, %edx
24002 +
24003 +#ifdef CONFIG_PAX_REFCOUNT
24004 + into
24005 +1234:
24006 + _ASM_EXTABLE(1234b, 2f)
24007 +#endif
24008 +
24009 + movl %eax, (v)
24010 + movl %edx, 4(v)
24011 +
24012 +#ifdef CONFIG_PAX_REFCOUNT
24013 +2:
24014 +#endif
24015 +
24016 +RET_ENDP
24017 +BEGIN(dec_return_unchecked)
24018 + movl (v), %eax
24019 + movl 4(v), %edx
24020 + subl $1, %eax
24021 + sbbl $0, %edx
24022 movl %eax, (v)
24023 movl %edx, 4(v)
24024 RET_ENDP
24025 @@ -143,6 +286,13 @@ BEGIN(add_unless)
24026 adcl %edx, %edi
24027 addl (v), %eax
24028 adcl 4(v), %edx
24029 +
24030 +#ifdef CONFIG_PAX_REFCOUNT
24031 + into
24032 +1234:
24033 + _ASM_EXTABLE(1234b, 2f)
24034 +#endif
24035 +
24036 cmpl %eax, %ecx
24037 je 3f
24038 1:
24039 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24040 1:
24041 addl $1, %eax
24042 adcl $0, %edx
24043 +
24044 +#ifdef CONFIG_PAX_REFCOUNT
24045 + into
24046 +1234:
24047 + _ASM_EXTABLE(1234b, 2f)
24048 +#endif
24049 +
24050 movl %eax, (v)
24051 movl %edx, 4(v)
24052 movl $1, %eax
24053 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24054 movl 4(v), %edx
24055 subl $1, %eax
24056 sbbl $0, %edx
24057 +
24058 +#ifdef CONFIG_PAX_REFCOUNT
24059 + into
24060 +1234:
24061 + _ASM_EXTABLE(1234b, 1f)
24062 +#endif
24063 +
24064 js 1f
24065 movl %eax, (v)
24066 movl %edx, 4(v)
24067 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24068 index f5cc9eb..51fa319 100644
24069 --- a/arch/x86/lib/atomic64_cx8_32.S
24070 +++ b/arch/x86/lib/atomic64_cx8_32.S
24071 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24072 CFI_STARTPROC
24073
24074 read64 %ecx
24075 + pax_force_retaddr
24076 ret
24077 CFI_ENDPROC
24078 ENDPROC(atomic64_read_cx8)
24079
24080 +ENTRY(atomic64_read_unchecked_cx8)
24081 + CFI_STARTPROC
24082 +
24083 + read64 %ecx
24084 + pax_force_retaddr
24085 + ret
24086 + CFI_ENDPROC
24087 +ENDPROC(atomic64_read_unchecked_cx8)
24088 +
24089 ENTRY(atomic64_set_cx8)
24090 CFI_STARTPROC
24091
24092 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24093 cmpxchg8b (%esi)
24094 jne 1b
24095
24096 + pax_force_retaddr
24097 ret
24098 CFI_ENDPROC
24099 ENDPROC(atomic64_set_cx8)
24100
24101 +ENTRY(atomic64_set_unchecked_cx8)
24102 + CFI_STARTPROC
24103 +
24104 +1:
24105 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
24106 + * are atomic on 586 and newer */
24107 + cmpxchg8b (%esi)
24108 + jne 1b
24109 +
24110 + pax_force_retaddr
24111 + ret
24112 + CFI_ENDPROC
24113 +ENDPROC(atomic64_set_unchecked_cx8)
24114 +
24115 ENTRY(atomic64_xchg_cx8)
24116 CFI_STARTPROC
24117
24118 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24119 cmpxchg8b (%esi)
24120 jne 1b
24121
24122 + pax_force_retaddr
24123 ret
24124 CFI_ENDPROC
24125 ENDPROC(atomic64_xchg_cx8)
24126
24127 -.macro addsub_return func ins insc
24128 -ENTRY(atomic64_\func\()_return_cx8)
24129 +.macro addsub_return func ins insc unchecked=""
24130 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24131 CFI_STARTPROC
24132 SAVE ebp
24133 SAVE ebx
24134 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24135 movl %edx, %ecx
24136 \ins\()l %esi, %ebx
24137 \insc\()l %edi, %ecx
24138 +
24139 +.ifb \unchecked
24140 +#ifdef CONFIG_PAX_REFCOUNT
24141 + into
24142 +2:
24143 + _ASM_EXTABLE(2b, 3f)
24144 +#endif
24145 +.endif
24146 +
24147 LOCK_PREFIX
24148 cmpxchg8b (%ebp)
24149 jne 1b
24150 -
24151 -10:
24152 movl %ebx, %eax
24153 movl %ecx, %edx
24154 +
24155 +.ifb \unchecked
24156 +#ifdef CONFIG_PAX_REFCOUNT
24157 +3:
24158 +#endif
24159 +.endif
24160 +
24161 RESTORE edi
24162 RESTORE esi
24163 RESTORE ebx
24164 RESTORE ebp
24165 + pax_force_retaddr
24166 ret
24167 CFI_ENDPROC
24168 -ENDPROC(atomic64_\func\()_return_cx8)
24169 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24170 .endm
24171
24172 addsub_return add add adc
24173 addsub_return sub sub sbb
24174 +addsub_return add add adc _unchecked
24175 +addsub_return sub sub sbb _unchecked
24176
24177 -.macro incdec_return func ins insc
24178 -ENTRY(atomic64_\func\()_return_cx8)
24179 +.macro incdec_return func ins insc unchecked=""
24180 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24181 CFI_STARTPROC
24182 SAVE ebx
24183
24184 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24185 movl %edx, %ecx
24186 \ins\()l $1, %ebx
24187 \insc\()l $0, %ecx
24188 +
24189 +.ifb \unchecked
24190 +#ifdef CONFIG_PAX_REFCOUNT
24191 + into
24192 +2:
24193 + _ASM_EXTABLE(2b, 3f)
24194 +#endif
24195 +.endif
24196 +
24197 LOCK_PREFIX
24198 cmpxchg8b (%esi)
24199 jne 1b
24200
24201 -10:
24202 movl %ebx, %eax
24203 movl %ecx, %edx
24204 +
24205 +.ifb \unchecked
24206 +#ifdef CONFIG_PAX_REFCOUNT
24207 +3:
24208 +#endif
24209 +.endif
24210 +
24211 RESTORE ebx
24212 + pax_force_retaddr
24213 ret
24214 CFI_ENDPROC
24215 -ENDPROC(atomic64_\func\()_return_cx8)
24216 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24217 .endm
24218
24219 incdec_return inc add adc
24220 incdec_return dec sub sbb
24221 +incdec_return inc add adc _unchecked
24222 +incdec_return dec sub sbb _unchecked
24223
24224 ENTRY(atomic64_dec_if_positive_cx8)
24225 CFI_STARTPROC
24226 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24227 movl %edx, %ecx
24228 subl $1, %ebx
24229 sbb $0, %ecx
24230 +
24231 +#ifdef CONFIG_PAX_REFCOUNT
24232 + into
24233 +1234:
24234 + _ASM_EXTABLE(1234b, 2f)
24235 +#endif
24236 +
24237 js 2f
24238 LOCK_PREFIX
24239 cmpxchg8b (%esi)
24240 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24241 movl %ebx, %eax
24242 movl %ecx, %edx
24243 RESTORE ebx
24244 + pax_force_retaddr
24245 ret
24246 CFI_ENDPROC
24247 ENDPROC(atomic64_dec_if_positive_cx8)
24248 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24249 movl %edx, %ecx
24250 addl %ebp, %ebx
24251 adcl %edi, %ecx
24252 +
24253 +#ifdef CONFIG_PAX_REFCOUNT
24254 + into
24255 +1234:
24256 + _ASM_EXTABLE(1234b, 3f)
24257 +#endif
24258 +
24259 LOCK_PREFIX
24260 cmpxchg8b (%esi)
24261 jne 1b
24262 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24263 CFI_ADJUST_CFA_OFFSET -8
24264 RESTORE ebx
24265 RESTORE ebp
24266 + pax_force_retaddr
24267 ret
24268 4:
24269 cmpl %edx, 4(%esp)
24270 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24271 xorl %ecx, %ecx
24272 addl $1, %ebx
24273 adcl %edx, %ecx
24274 +
24275 +#ifdef CONFIG_PAX_REFCOUNT
24276 + into
24277 +1234:
24278 + _ASM_EXTABLE(1234b, 3f)
24279 +#endif
24280 +
24281 LOCK_PREFIX
24282 cmpxchg8b (%esi)
24283 jne 1b
24284 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24285 movl $1, %eax
24286 3:
24287 RESTORE ebx
24288 + pax_force_retaddr
24289 ret
24290 CFI_ENDPROC
24291 ENDPROC(atomic64_inc_not_zero_cx8)
24292 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24293 index 2af5df3..62b1a5a 100644
24294 --- a/arch/x86/lib/checksum_32.S
24295 +++ b/arch/x86/lib/checksum_32.S
24296 @@ -29,7 +29,8 @@
24297 #include <asm/dwarf2.h>
24298 #include <asm/errno.h>
24299 #include <asm/asm.h>
24300 -
24301 +#include <asm/segment.h>
24302 +
24303 /*
24304 * computes a partial checksum, e.g. for TCP/UDP fragments
24305 */
24306 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24307
24308 #define ARGBASE 16
24309 #define FP 12
24310 -
24311 -ENTRY(csum_partial_copy_generic)
24312 +
24313 +ENTRY(csum_partial_copy_generic_to_user)
24314 CFI_STARTPROC
24315 +
24316 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24317 + pushl_cfi %gs
24318 + popl_cfi %es
24319 + jmp csum_partial_copy_generic
24320 +#endif
24321 +
24322 +ENTRY(csum_partial_copy_generic_from_user)
24323 +
24324 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24325 + pushl_cfi %gs
24326 + popl_cfi %ds
24327 +#endif
24328 +
24329 +ENTRY(csum_partial_copy_generic)
24330 subl $4,%esp
24331 CFI_ADJUST_CFA_OFFSET 4
24332 pushl_cfi %edi
24333 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24334 jmp 4f
24335 SRC(1: movw (%esi), %bx )
24336 addl $2, %esi
24337 -DST( movw %bx, (%edi) )
24338 +DST( movw %bx, %es:(%edi) )
24339 addl $2, %edi
24340 addw %bx, %ax
24341 adcl $0, %eax
24342 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24343 SRC(1: movl (%esi), %ebx )
24344 SRC( movl 4(%esi), %edx )
24345 adcl %ebx, %eax
24346 -DST( movl %ebx, (%edi) )
24347 +DST( movl %ebx, %es:(%edi) )
24348 adcl %edx, %eax
24349 -DST( movl %edx, 4(%edi) )
24350 +DST( movl %edx, %es:4(%edi) )
24351
24352 SRC( movl 8(%esi), %ebx )
24353 SRC( movl 12(%esi), %edx )
24354 adcl %ebx, %eax
24355 -DST( movl %ebx, 8(%edi) )
24356 +DST( movl %ebx, %es:8(%edi) )
24357 adcl %edx, %eax
24358 -DST( movl %edx, 12(%edi) )
24359 +DST( movl %edx, %es:12(%edi) )
24360
24361 SRC( movl 16(%esi), %ebx )
24362 SRC( movl 20(%esi), %edx )
24363 adcl %ebx, %eax
24364 -DST( movl %ebx, 16(%edi) )
24365 +DST( movl %ebx, %es:16(%edi) )
24366 adcl %edx, %eax
24367 -DST( movl %edx, 20(%edi) )
24368 +DST( movl %edx, %es:20(%edi) )
24369
24370 SRC( movl 24(%esi), %ebx )
24371 SRC( movl 28(%esi), %edx )
24372 adcl %ebx, %eax
24373 -DST( movl %ebx, 24(%edi) )
24374 +DST( movl %ebx, %es:24(%edi) )
24375 adcl %edx, %eax
24376 -DST( movl %edx, 28(%edi) )
24377 +DST( movl %edx, %es:28(%edi) )
24378
24379 lea 32(%esi), %esi
24380 lea 32(%edi), %edi
24381 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24382 shrl $2, %edx # This clears CF
24383 SRC(3: movl (%esi), %ebx )
24384 adcl %ebx, %eax
24385 -DST( movl %ebx, (%edi) )
24386 +DST( movl %ebx, %es:(%edi) )
24387 lea 4(%esi), %esi
24388 lea 4(%edi), %edi
24389 dec %edx
24390 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24391 jb 5f
24392 SRC( movw (%esi), %cx )
24393 leal 2(%esi), %esi
24394 -DST( movw %cx, (%edi) )
24395 +DST( movw %cx, %es:(%edi) )
24396 leal 2(%edi), %edi
24397 je 6f
24398 shll $16,%ecx
24399 SRC(5: movb (%esi), %cl )
24400 -DST( movb %cl, (%edi) )
24401 +DST( movb %cl, %es:(%edi) )
24402 6: addl %ecx, %eax
24403 adcl $0, %eax
24404 7:
24405 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24406
24407 6001:
24408 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24409 - movl $-EFAULT, (%ebx)
24410 + movl $-EFAULT, %ss:(%ebx)
24411
24412 # zero the complete destination - computing the rest
24413 # is too much work
24414 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24415
24416 6002:
24417 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24418 - movl $-EFAULT,(%ebx)
24419 + movl $-EFAULT,%ss:(%ebx)
24420 jmp 5000b
24421
24422 .previous
24423
24424 + pushl_cfi %ss
24425 + popl_cfi %ds
24426 + pushl_cfi %ss
24427 + popl_cfi %es
24428 popl_cfi %ebx
24429 CFI_RESTORE ebx
24430 popl_cfi %esi
24431 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24432 popl_cfi %ecx # equivalent to addl $4,%esp
24433 ret
24434 CFI_ENDPROC
24435 -ENDPROC(csum_partial_copy_generic)
24436 +ENDPROC(csum_partial_copy_generic_to_user)
24437
24438 #else
24439
24440 /* Version for PentiumII/PPro */
24441
24442 #define ROUND1(x) \
24443 + nop; nop; nop; \
24444 SRC(movl x(%esi), %ebx ) ; \
24445 addl %ebx, %eax ; \
24446 - DST(movl %ebx, x(%edi) ) ;
24447 + DST(movl %ebx, %es:x(%edi)) ;
24448
24449 #define ROUND(x) \
24450 + nop; nop; nop; \
24451 SRC(movl x(%esi), %ebx ) ; \
24452 adcl %ebx, %eax ; \
24453 - DST(movl %ebx, x(%edi) ) ;
24454 + DST(movl %ebx, %es:x(%edi)) ;
24455
24456 #define ARGBASE 12
24457 -
24458 -ENTRY(csum_partial_copy_generic)
24459 +
24460 +ENTRY(csum_partial_copy_generic_to_user)
24461 CFI_STARTPROC
24462 +
24463 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24464 + pushl_cfi %gs
24465 + popl_cfi %es
24466 + jmp csum_partial_copy_generic
24467 +#endif
24468 +
24469 +ENTRY(csum_partial_copy_generic_from_user)
24470 +
24471 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24472 + pushl_cfi %gs
24473 + popl_cfi %ds
24474 +#endif
24475 +
24476 +ENTRY(csum_partial_copy_generic)
24477 pushl_cfi %ebx
24478 CFI_REL_OFFSET ebx, 0
24479 pushl_cfi %edi
24480 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24481 subl %ebx, %edi
24482 lea -1(%esi),%edx
24483 andl $-32,%edx
24484 - lea 3f(%ebx,%ebx), %ebx
24485 + lea 3f(%ebx,%ebx,2), %ebx
24486 testl %esi, %esi
24487 jmp *%ebx
24488 1: addl $64,%esi
24489 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24490 jb 5f
24491 SRC( movw (%esi), %dx )
24492 leal 2(%esi), %esi
24493 -DST( movw %dx, (%edi) )
24494 +DST( movw %dx, %es:(%edi) )
24495 leal 2(%edi), %edi
24496 je 6f
24497 shll $16,%edx
24498 5:
24499 SRC( movb (%esi), %dl )
24500 -DST( movb %dl, (%edi) )
24501 +DST( movb %dl, %es:(%edi) )
24502 6: addl %edx, %eax
24503 adcl $0, %eax
24504 7:
24505 .section .fixup, "ax"
24506 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24507 - movl $-EFAULT, (%ebx)
24508 + movl $-EFAULT, %ss:(%ebx)
24509 # zero the complete destination (computing the rest is too much work)
24510 movl ARGBASE+8(%esp),%edi # dst
24511 movl ARGBASE+12(%esp),%ecx # len
24512 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24513 rep; stosb
24514 jmp 7b
24515 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24516 - movl $-EFAULT, (%ebx)
24517 + movl $-EFAULT, %ss:(%ebx)
24518 jmp 7b
24519 .previous
24520
24521 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24522 + pushl_cfi %ss
24523 + popl_cfi %ds
24524 + pushl_cfi %ss
24525 + popl_cfi %es
24526 +#endif
24527 +
24528 popl_cfi %esi
24529 CFI_RESTORE esi
24530 popl_cfi %edi
24531 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24532 CFI_RESTORE ebx
24533 ret
24534 CFI_ENDPROC
24535 -ENDPROC(csum_partial_copy_generic)
24536 +ENDPROC(csum_partial_copy_generic_to_user)
24537
24538 #undef ROUND
24539 #undef ROUND1
24540 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
24541 index f2145cf..cea889d 100644
24542 --- a/arch/x86/lib/clear_page_64.S
24543 +++ b/arch/x86/lib/clear_page_64.S
24544 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
24545 movl $4096/8,%ecx
24546 xorl %eax,%eax
24547 rep stosq
24548 + pax_force_retaddr
24549 ret
24550 CFI_ENDPROC
24551 ENDPROC(clear_page_c)
24552 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
24553 movl $4096,%ecx
24554 xorl %eax,%eax
24555 rep stosb
24556 + pax_force_retaddr
24557 ret
24558 CFI_ENDPROC
24559 ENDPROC(clear_page_c_e)
24560 @@ -43,6 +45,7 @@ ENTRY(clear_page)
24561 leaq 64(%rdi),%rdi
24562 jnz .Lloop
24563 nop
24564 + pax_force_retaddr
24565 ret
24566 CFI_ENDPROC
24567 .Lclear_page_end:
24568 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
24569
24570 #include <asm/cpufeature.h>
24571
24572 - .section .altinstr_replacement,"ax"
24573 + .section .altinstr_replacement,"a"
24574 1: .byte 0xeb /* jmp <disp8> */
24575 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
24576 2: .byte 0xeb /* jmp <disp8> */
24577 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
24578 index 1e572c5..2a162cd 100644
24579 --- a/arch/x86/lib/cmpxchg16b_emu.S
24580 +++ b/arch/x86/lib/cmpxchg16b_emu.S
24581 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
24582
24583 popf
24584 mov $1, %al
24585 + pax_force_retaddr
24586 ret
24587
24588 not_same:
24589 popf
24590 xor %al,%al
24591 + pax_force_retaddr
24592 ret
24593
24594 CFI_ENDPROC
24595 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
24596 index 176cca6..1166c50 100644
24597 --- a/arch/x86/lib/copy_page_64.S
24598 +++ b/arch/x86/lib/copy_page_64.S
24599 @@ -9,6 +9,7 @@ copy_page_rep:
24600 CFI_STARTPROC
24601 movl $4096/8, %ecx
24602 rep movsq
24603 + pax_force_retaddr
24604 ret
24605 CFI_ENDPROC
24606 ENDPROC(copy_page_rep)
24607 @@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
24608
24609 ENTRY(copy_page)
24610 CFI_STARTPROC
24611 - subq $2*8, %rsp
24612 - CFI_ADJUST_CFA_OFFSET 2*8
24613 + subq $3*8, %rsp
24614 + CFI_ADJUST_CFA_OFFSET 3*8
24615 movq %rbx, (%rsp)
24616 CFI_REL_OFFSET rbx, 0
24617 movq %r12, 1*8(%rsp)
24618 CFI_REL_OFFSET r12, 1*8
24619 + movq %r13, 2*8(%rsp)
24620 + CFI_REL_OFFSET r13, 2*8
24621
24622 movl $(4096/64)-5, %ecx
24623 .p2align 4
24624 @@ -36,7 +39,7 @@ ENTRY(copy_page)
24625 movq 0x8*2(%rsi), %rdx
24626 movq 0x8*3(%rsi), %r8
24627 movq 0x8*4(%rsi), %r9
24628 - movq 0x8*5(%rsi), %r10
24629 + movq 0x8*5(%rsi), %r13
24630 movq 0x8*6(%rsi), %r11
24631 movq 0x8*7(%rsi), %r12
24632
24633 @@ -47,7 +50,7 @@ ENTRY(copy_page)
24634 movq %rdx, 0x8*2(%rdi)
24635 movq %r8, 0x8*3(%rdi)
24636 movq %r9, 0x8*4(%rdi)
24637 - movq %r10, 0x8*5(%rdi)
24638 + movq %r13, 0x8*5(%rdi)
24639 movq %r11, 0x8*6(%rdi)
24640 movq %r12, 0x8*7(%rdi)
24641
24642 @@ -66,7 +69,7 @@ ENTRY(copy_page)
24643 movq 0x8*2(%rsi), %rdx
24644 movq 0x8*3(%rsi), %r8
24645 movq 0x8*4(%rsi), %r9
24646 - movq 0x8*5(%rsi), %r10
24647 + movq 0x8*5(%rsi), %r13
24648 movq 0x8*6(%rsi), %r11
24649 movq 0x8*7(%rsi), %r12
24650
24651 @@ -75,7 +78,7 @@ ENTRY(copy_page)
24652 movq %rdx, 0x8*2(%rdi)
24653 movq %r8, 0x8*3(%rdi)
24654 movq %r9, 0x8*4(%rdi)
24655 - movq %r10, 0x8*5(%rdi)
24656 + movq %r13, 0x8*5(%rdi)
24657 movq %r11, 0x8*6(%rdi)
24658 movq %r12, 0x8*7(%rdi)
24659
24660 @@ -87,8 +90,11 @@ ENTRY(copy_page)
24661 CFI_RESTORE rbx
24662 movq 1*8(%rsp), %r12
24663 CFI_RESTORE r12
24664 - addq $2*8, %rsp
24665 - CFI_ADJUST_CFA_OFFSET -2*8
24666 + movq 2*8(%rsp), %r13
24667 + CFI_RESTORE r13
24668 + addq $3*8, %rsp
24669 + CFI_ADJUST_CFA_OFFSET -3*8
24670 + pax_force_retaddr
24671 ret
24672 .Lcopy_page_end:
24673 CFI_ENDPROC
24674 @@ -99,7 +105,7 @@ ENDPROC(copy_page)
24675
24676 #include <asm/cpufeature.h>
24677
24678 - .section .altinstr_replacement,"ax"
24679 + .section .altinstr_replacement,"a"
24680 1: .byte 0xeb /* jmp <disp8> */
24681 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
24682 2:
24683 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
24684 index a30ca15..d25fab6 100644
24685 --- a/arch/x86/lib/copy_user_64.S
24686 +++ b/arch/x86/lib/copy_user_64.S
24687 @@ -18,6 +18,7 @@
24688 #include <asm/alternative-asm.h>
24689 #include <asm/asm.h>
24690 #include <asm/smap.h>
24691 +#include <asm/pgtable.h>
24692
24693 /*
24694 * By placing feature2 after feature1 in altinstructions section, we logically
24695 @@ -31,7 +32,7 @@
24696 .byte 0xe9 /* 32bit jump */
24697 .long \orig-1f /* by default jump to orig */
24698 1:
24699 - .section .altinstr_replacement,"ax"
24700 + .section .altinstr_replacement,"a"
24701 2: .byte 0xe9 /* near jump with 32bit immediate */
24702 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
24703 3: .byte 0xe9 /* near jump with 32bit immediate */
24704 @@ -70,47 +71,20 @@
24705 #endif
24706 .endm
24707
24708 -/* Standard copy_to_user with segment limit checking */
24709 -ENTRY(_copy_to_user)
24710 - CFI_STARTPROC
24711 - GET_THREAD_INFO(%rax)
24712 - movq %rdi,%rcx
24713 - addq %rdx,%rcx
24714 - jc bad_to_user
24715 - cmpq TI_addr_limit(%rax),%rcx
24716 - ja bad_to_user
24717 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24718 - copy_user_generic_unrolled,copy_user_generic_string, \
24719 - copy_user_enhanced_fast_string
24720 - CFI_ENDPROC
24721 -ENDPROC(_copy_to_user)
24722 -
24723 -/* Standard copy_from_user with segment limit checking */
24724 -ENTRY(_copy_from_user)
24725 - CFI_STARTPROC
24726 - GET_THREAD_INFO(%rax)
24727 - movq %rsi,%rcx
24728 - addq %rdx,%rcx
24729 - jc bad_from_user
24730 - cmpq TI_addr_limit(%rax),%rcx
24731 - ja bad_from_user
24732 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24733 - copy_user_generic_unrolled,copy_user_generic_string, \
24734 - copy_user_enhanced_fast_string
24735 - CFI_ENDPROC
24736 -ENDPROC(_copy_from_user)
24737 -
24738 .section .fixup,"ax"
24739 /* must zero dest */
24740 ENTRY(bad_from_user)
24741 bad_from_user:
24742 CFI_STARTPROC
24743 + testl %edx,%edx
24744 + js bad_to_user
24745 movl %edx,%ecx
24746 xorl %eax,%eax
24747 rep
24748 stosb
24749 bad_to_user:
24750 movl %edx,%eax
24751 + pax_force_retaddr
24752 ret
24753 CFI_ENDPROC
24754 ENDPROC(bad_from_user)
24755 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
24756 jz 17f
24757 1: movq (%rsi),%r8
24758 2: movq 1*8(%rsi),%r9
24759 -3: movq 2*8(%rsi),%r10
24760 +3: movq 2*8(%rsi),%rax
24761 4: movq 3*8(%rsi),%r11
24762 5: movq %r8,(%rdi)
24763 6: movq %r9,1*8(%rdi)
24764 -7: movq %r10,2*8(%rdi)
24765 +7: movq %rax,2*8(%rdi)
24766 8: movq %r11,3*8(%rdi)
24767 9: movq 4*8(%rsi),%r8
24768 10: movq 5*8(%rsi),%r9
24769 -11: movq 6*8(%rsi),%r10
24770 +11: movq 6*8(%rsi),%rax
24771 12: movq 7*8(%rsi),%r11
24772 13: movq %r8,4*8(%rdi)
24773 14: movq %r9,5*8(%rdi)
24774 -15: movq %r10,6*8(%rdi)
24775 +15: movq %rax,6*8(%rdi)
24776 16: movq %r11,7*8(%rdi)
24777 leaq 64(%rsi),%rsi
24778 leaq 64(%rdi),%rdi
24779 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
24780 jnz 21b
24781 23: xor %eax,%eax
24782 ASM_CLAC
24783 + pax_force_retaddr
24784 ret
24785
24786 .section .fixup,"ax"
24787 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
24788 movsb
24789 4: xorl %eax,%eax
24790 ASM_CLAC
24791 + pax_force_retaddr
24792 ret
24793
24794 .section .fixup,"ax"
24795 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
24796 movsb
24797 2: xorl %eax,%eax
24798 ASM_CLAC
24799 + pax_force_retaddr
24800 ret
24801
24802 .section .fixup,"ax"
24803 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
24804 index 6a4f43c..f5f9e26 100644
24805 --- a/arch/x86/lib/copy_user_nocache_64.S
24806 +++ b/arch/x86/lib/copy_user_nocache_64.S
24807 @@ -8,6 +8,7 @@
24808
24809 #include <linux/linkage.h>
24810 #include <asm/dwarf2.h>
24811 +#include <asm/alternative-asm.h>
24812
24813 #define FIX_ALIGNMENT 1
24814
24815 @@ -16,6 +17,7 @@
24816 #include <asm/thread_info.h>
24817 #include <asm/asm.h>
24818 #include <asm/smap.h>
24819 +#include <asm/pgtable.h>
24820
24821 .macro ALIGN_DESTINATION
24822 #ifdef FIX_ALIGNMENT
24823 @@ -49,6 +51,15 @@
24824 */
24825 ENTRY(__copy_user_nocache)
24826 CFI_STARTPROC
24827 +
24828 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24829 + mov $PAX_USER_SHADOW_BASE,%rcx
24830 + cmp %rcx,%rsi
24831 + jae 1f
24832 + add %rcx,%rsi
24833 +1:
24834 +#endif
24835 +
24836 ASM_STAC
24837 cmpl $8,%edx
24838 jb 20f /* less then 8 bytes, go to byte copy loop */
24839 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
24840 jz 17f
24841 1: movq (%rsi),%r8
24842 2: movq 1*8(%rsi),%r9
24843 -3: movq 2*8(%rsi),%r10
24844 +3: movq 2*8(%rsi),%rax
24845 4: movq 3*8(%rsi),%r11
24846 5: movnti %r8,(%rdi)
24847 6: movnti %r9,1*8(%rdi)
24848 -7: movnti %r10,2*8(%rdi)
24849 +7: movnti %rax,2*8(%rdi)
24850 8: movnti %r11,3*8(%rdi)
24851 9: movq 4*8(%rsi),%r8
24852 10: movq 5*8(%rsi),%r9
24853 -11: movq 6*8(%rsi),%r10
24854 +11: movq 6*8(%rsi),%rax
24855 12: movq 7*8(%rsi),%r11
24856 13: movnti %r8,4*8(%rdi)
24857 14: movnti %r9,5*8(%rdi)
24858 -15: movnti %r10,6*8(%rdi)
24859 +15: movnti %rax,6*8(%rdi)
24860 16: movnti %r11,7*8(%rdi)
24861 leaq 64(%rsi),%rsi
24862 leaq 64(%rdi),%rdi
24863 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
24864 23: xorl %eax,%eax
24865 ASM_CLAC
24866 sfence
24867 + pax_force_retaddr
24868 ret
24869
24870 .section .fixup,"ax"
24871 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
24872 index 2419d5f..953ee51 100644
24873 --- a/arch/x86/lib/csum-copy_64.S
24874 +++ b/arch/x86/lib/csum-copy_64.S
24875 @@ -9,6 +9,7 @@
24876 #include <asm/dwarf2.h>
24877 #include <asm/errno.h>
24878 #include <asm/asm.h>
24879 +#include <asm/alternative-asm.h>
24880
24881 /*
24882 * Checksum copy with exception handling.
24883 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
24884 CFI_RESTORE rbp
24885 addq $7*8, %rsp
24886 CFI_ADJUST_CFA_OFFSET -7*8
24887 + pax_force_retaddr 0, 1
24888 ret
24889 CFI_RESTORE_STATE
24890
24891 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
24892 index 25b7ae8..169fafc 100644
24893 --- a/arch/x86/lib/csum-wrappers_64.c
24894 +++ b/arch/x86/lib/csum-wrappers_64.c
24895 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
24896 len -= 2;
24897 }
24898 }
24899 - isum = csum_partial_copy_generic((__force const void *)src,
24900 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
24901 dst, len, isum, errp, NULL);
24902 if (unlikely(*errp))
24903 goto out_err;
24904 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
24905 }
24906
24907 *errp = 0;
24908 - return csum_partial_copy_generic(src, (void __force *)dst,
24909 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
24910 len, isum, NULL, errp);
24911 }
24912 EXPORT_SYMBOL(csum_partial_copy_to_user);
24913 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
24914 index 156b9c8..b144132 100644
24915 --- a/arch/x86/lib/getuser.S
24916 +++ b/arch/x86/lib/getuser.S
24917 @@ -34,17 +34,40 @@
24918 #include <asm/thread_info.h>
24919 #include <asm/asm.h>
24920 #include <asm/smap.h>
24921 +#include <asm/segment.h>
24922 +#include <asm/pgtable.h>
24923 +#include <asm/alternative-asm.h>
24924 +
24925 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24926 +#define __copyuser_seg gs;
24927 +#else
24928 +#define __copyuser_seg
24929 +#endif
24930
24931 .text
24932 ENTRY(__get_user_1)
24933 CFI_STARTPROC
24934 +
24935 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24936 GET_THREAD_INFO(%_ASM_DX)
24937 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24938 jae bad_get_user
24939 ASM_STAC
24940 -1: movzb (%_ASM_AX),%edx
24941 +
24942 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24943 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24944 + cmp %_ASM_DX,%_ASM_AX
24945 + jae 1234f
24946 + add %_ASM_DX,%_ASM_AX
24947 +1234:
24948 +#endif
24949 +
24950 +#endif
24951 +
24952 +1: __copyuser_seg movzb (%_ASM_AX),%edx
24953 xor %eax,%eax
24954 ASM_CLAC
24955 + pax_force_retaddr
24956 ret
24957 CFI_ENDPROC
24958 ENDPROC(__get_user_1)
24959 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
24960 ENTRY(__get_user_2)
24961 CFI_STARTPROC
24962 add $1,%_ASM_AX
24963 +
24964 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24965 jc bad_get_user
24966 GET_THREAD_INFO(%_ASM_DX)
24967 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24968 jae bad_get_user
24969 ASM_STAC
24970 -2: movzwl -1(%_ASM_AX),%edx
24971 +
24972 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24973 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24974 + cmp %_ASM_DX,%_ASM_AX
24975 + jae 1234f
24976 + add %_ASM_DX,%_ASM_AX
24977 +1234:
24978 +#endif
24979 +
24980 +#endif
24981 +
24982 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
24983 xor %eax,%eax
24984 ASM_CLAC
24985 + pax_force_retaddr
24986 ret
24987 CFI_ENDPROC
24988 ENDPROC(__get_user_2)
24989 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
24990 ENTRY(__get_user_4)
24991 CFI_STARTPROC
24992 add $3,%_ASM_AX
24993 +
24994 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24995 jc bad_get_user
24996 GET_THREAD_INFO(%_ASM_DX)
24997 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24998 jae bad_get_user
24999 ASM_STAC
25000 -3: mov -3(%_ASM_AX),%edx
25001 +
25002 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25003 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25004 + cmp %_ASM_DX,%_ASM_AX
25005 + jae 1234f
25006 + add %_ASM_DX,%_ASM_AX
25007 +1234:
25008 +#endif
25009 +
25010 +#endif
25011 +
25012 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
25013 xor %eax,%eax
25014 ASM_CLAC
25015 + pax_force_retaddr
25016 ret
25017 CFI_ENDPROC
25018 ENDPROC(__get_user_4)
25019 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
25020 GET_THREAD_INFO(%_ASM_DX)
25021 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25022 jae bad_get_user
25023 +
25024 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25025 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
25026 + cmp %_ASM_DX,%_ASM_AX
25027 + jae 1234f
25028 + add %_ASM_DX,%_ASM_AX
25029 +1234:
25030 +#endif
25031 +
25032 ASM_STAC
25033 4: movq -7(%_ASM_AX),%_ASM_DX
25034 xor %eax,%eax
25035 ASM_CLAC
25036 + pax_force_retaddr
25037 ret
25038 CFI_ENDPROC
25039 ENDPROC(__get_user_8)
25040 @@ -101,6 +162,7 @@ bad_get_user:
25041 xor %edx,%edx
25042 mov $(-EFAULT),%_ASM_AX
25043 ASM_CLAC
25044 + pax_force_retaddr
25045 ret
25046 CFI_ENDPROC
25047 END(bad_get_user)
25048 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25049 index 54fcffe..7be149e 100644
25050 --- a/arch/x86/lib/insn.c
25051 +++ b/arch/x86/lib/insn.c
25052 @@ -20,8 +20,10 @@
25053
25054 #ifdef __KERNEL__
25055 #include <linux/string.h>
25056 +#include <asm/pgtable_types.h>
25057 #else
25058 #include <string.h>
25059 +#define ktla_ktva(addr) addr
25060 #endif
25061 #include <asm/inat.h>
25062 #include <asm/insn.h>
25063 @@ -53,8 +55,8 @@
25064 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25065 {
25066 memset(insn, 0, sizeof(*insn));
25067 - insn->kaddr = kaddr;
25068 - insn->next_byte = kaddr;
25069 + insn->kaddr = ktla_ktva(kaddr);
25070 + insn->next_byte = ktla_ktva(kaddr);
25071 insn->x86_64 = x86_64 ? 1 : 0;
25072 insn->opnd_bytes = 4;
25073 if (x86_64)
25074 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25075 index 05a95e7..326f2fa 100644
25076 --- a/arch/x86/lib/iomap_copy_64.S
25077 +++ b/arch/x86/lib/iomap_copy_64.S
25078 @@ -17,6 +17,7 @@
25079
25080 #include <linux/linkage.h>
25081 #include <asm/dwarf2.h>
25082 +#include <asm/alternative-asm.h>
25083
25084 /*
25085 * override generic version in lib/iomap_copy.c
25086 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25087 CFI_STARTPROC
25088 movl %edx,%ecx
25089 rep movsd
25090 + pax_force_retaddr
25091 ret
25092 CFI_ENDPROC
25093 ENDPROC(__iowrite32_copy)
25094 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25095 index 1c273be..da9cc0e 100644
25096 --- a/arch/x86/lib/memcpy_64.S
25097 +++ b/arch/x86/lib/memcpy_64.S
25098 @@ -33,6 +33,7 @@
25099 rep movsq
25100 movl %edx, %ecx
25101 rep movsb
25102 + pax_force_retaddr
25103 ret
25104 .Lmemcpy_e:
25105 .previous
25106 @@ -49,6 +50,7 @@
25107 movq %rdi, %rax
25108 movq %rdx, %rcx
25109 rep movsb
25110 + pax_force_retaddr
25111 ret
25112 .Lmemcpy_e_e:
25113 .previous
25114 @@ -76,13 +78,13 @@ ENTRY(memcpy)
25115 */
25116 movq 0*8(%rsi), %r8
25117 movq 1*8(%rsi), %r9
25118 - movq 2*8(%rsi), %r10
25119 + movq 2*8(%rsi), %rcx
25120 movq 3*8(%rsi), %r11
25121 leaq 4*8(%rsi), %rsi
25122
25123 movq %r8, 0*8(%rdi)
25124 movq %r9, 1*8(%rdi)
25125 - movq %r10, 2*8(%rdi)
25126 + movq %rcx, 2*8(%rdi)
25127 movq %r11, 3*8(%rdi)
25128 leaq 4*8(%rdi), %rdi
25129 jae .Lcopy_forward_loop
25130 @@ -105,12 +107,12 @@ ENTRY(memcpy)
25131 subq $0x20, %rdx
25132 movq -1*8(%rsi), %r8
25133 movq -2*8(%rsi), %r9
25134 - movq -3*8(%rsi), %r10
25135 + movq -3*8(%rsi), %rcx
25136 movq -4*8(%rsi), %r11
25137 leaq -4*8(%rsi), %rsi
25138 movq %r8, -1*8(%rdi)
25139 movq %r9, -2*8(%rdi)
25140 - movq %r10, -3*8(%rdi)
25141 + movq %rcx, -3*8(%rdi)
25142 movq %r11, -4*8(%rdi)
25143 leaq -4*8(%rdi), %rdi
25144 jae .Lcopy_backward_loop
25145 @@ -130,12 +132,13 @@ ENTRY(memcpy)
25146 */
25147 movq 0*8(%rsi), %r8
25148 movq 1*8(%rsi), %r9
25149 - movq -2*8(%rsi, %rdx), %r10
25150 + movq -2*8(%rsi, %rdx), %rcx
25151 movq -1*8(%rsi, %rdx), %r11
25152 movq %r8, 0*8(%rdi)
25153 movq %r9, 1*8(%rdi)
25154 - movq %r10, -2*8(%rdi, %rdx)
25155 + movq %rcx, -2*8(%rdi, %rdx)
25156 movq %r11, -1*8(%rdi, %rdx)
25157 + pax_force_retaddr
25158 retq
25159 .p2align 4
25160 .Lless_16bytes:
25161 @@ -148,6 +151,7 @@ ENTRY(memcpy)
25162 movq -1*8(%rsi, %rdx), %r9
25163 movq %r8, 0*8(%rdi)
25164 movq %r9, -1*8(%rdi, %rdx)
25165 + pax_force_retaddr
25166 retq
25167 .p2align 4
25168 .Lless_8bytes:
25169 @@ -161,6 +165,7 @@ ENTRY(memcpy)
25170 movl -4(%rsi, %rdx), %r8d
25171 movl %ecx, (%rdi)
25172 movl %r8d, -4(%rdi, %rdx)
25173 + pax_force_retaddr
25174 retq
25175 .p2align 4
25176 .Lless_3bytes:
25177 @@ -179,6 +184,7 @@ ENTRY(memcpy)
25178 movb %cl, (%rdi)
25179
25180 .Lend:
25181 + pax_force_retaddr
25182 retq
25183 CFI_ENDPROC
25184 ENDPROC(memcpy)
25185 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25186 index ee16461..c39c199 100644
25187 --- a/arch/x86/lib/memmove_64.S
25188 +++ b/arch/x86/lib/memmove_64.S
25189 @@ -61,13 +61,13 @@ ENTRY(memmove)
25190 5:
25191 sub $0x20, %rdx
25192 movq 0*8(%rsi), %r11
25193 - movq 1*8(%rsi), %r10
25194 + movq 1*8(%rsi), %rcx
25195 movq 2*8(%rsi), %r9
25196 movq 3*8(%rsi), %r8
25197 leaq 4*8(%rsi), %rsi
25198
25199 movq %r11, 0*8(%rdi)
25200 - movq %r10, 1*8(%rdi)
25201 + movq %rcx, 1*8(%rdi)
25202 movq %r9, 2*8(%rdi)
25203 movq %r8, 3*8(%rdi)
25204 leaq 4*8(%rdi), %rdi
25205 @@ -81,10 +81,10 @@ ENTRY(memmove)
25206 4:
25207 movq %rdx, %rcx
25208 movq -8(%rsi, %rdx), %r11
25209 - lea -8(%rdi, %rdx), %r10
25210 + lea -8(%rdi, %rdx), %r9
25211 shrq $3, %rcx
25212 rep movsq
25213 - movq %r11, (%r10)
25214 + movq %r11, (%r9)
25215 jmp 13f
25216 .Lmemmove_end_forward:
25217
25218 @@ -95,14 +95,14 @@ ENTRY(memmove)
25219 7:
25220 movq %rdx, %rcx
25221 movq (%rsi), %r11
25222 - movq %rdi, %r10
25223 + movq %rdi, %r9
25224 leaq -8(%rsi, %rdx), %rsi
25225 leaq -8(%rdi, %rdx), %rdi
25226 shrq $3, %rcx
25227 std
25228 rep movsq
25229 cld
25230 - movq %r11, (%r10)
25231 + movq %r11, (%r9)
25232 jmp 13f
25233
25234 /*
25235 @@ -127,13 +127,13 @@ ENTRY(memmove)
25236 8:
25237 subq $0x20, %rdx
25238 movq -1*8(%rsi), %r11
25239 - movq -2*8(%rsi), %r10
25240 + movq -2*8(%rsi), %rcx
25241 movq -3*8(%rsi), %r9
25242 movq -4*8(%rsi), %r8
25243 leaq -4*8(%rsi), %rsi
25244
25245 movq %r11, -1*8(%rdi)
25246 - movq %r10, -2*8(%rdi)
25247 + movq %rcx, -2*8(%rdi)
25248 movq %r9, -3*8(%rdi)
25249 movq %r8, -4*8(%rdi)
25250 leaq -4*8(%rdi), %rdi
25251 @@ -151,11 +151,11 @@ ENTRY(memmove)
25252 * Move data from 16 bytes to 31 bytes.
25253 */
25254 movq 0*8(%rsi), %r11
25255 - movq 1*8(%rsi), %r10
25256 + movq 1*8(%rsi), %rcx
25257 movq -2*8(%rsi, %rdx), %r9
25258 movq -1*8(%rsi, %rdx), %r8
25259 movq %r11, 0*8(%rdi)
25260 - movq %r10, 1*8(%rdi)
25261 + movq %rcx, 1*8(%rdi)
25262 movq %r9, -2*8(%rdi, %rdx)
25263 movq %r8, -1*8(%rdi, %rdx)
25264 jmp 13f
25265 @@ -167,9 +167,9 @@ ENTRY(memmove)
25266 * Move data from 8 bytes to 15 bytes.
25267 */
25268 movq 0*8(%rsi), %r11
25269 - movq -1*8(%rsi, %rdx), %r10
25270 + movq -1*8(%rsi, %rdx), %r9
25271 movq %r11, 0*8(%rdi)
25272 - movq %r10, -1*8(%rdi, %rdx)
25273 + movq %r9, -1*8(%rdi, %rdx)
25274 jmp 13f
25275 10:
25276 cmpq $4, %rdx
25277 @@ -178,9 +178,9 @@ ENTRY(memmove)
25278 * Move data from 4 bytes to 7 bytes.
25279 */
25280 movl (%rsi), %r11d
25281 - movl -4(%rsi, %rdx), %r10d
25282 + movl -4(%rsi, %rdx), %r9d
25283 movl %r11d, (%rdi)
25284 - movl %r10d, -4(%rdi, %rdx)
25285 + movl %r9d, -4(%rdi, %rdx)
25286 jmp 13f
25287 11:
25288 cmp $2, %rdx
25289 @@ -189,9 +189,9 @@ ENTRY(memmove)
25290 * Move data from 2 bytes to 3 bytes.
25291 */
25292 movw (%rsi), %r11w
25293 - movw -2(%rsi, %rdx), %r10w
25294 + movw -2(%rsi, %rdx), %r9w
25295 movw %r11w, (%rdi)
25296 - movw %r10w, -2(%rdi, %rdx)
25297 + movw %r9w, -2(%rdi, %rdx)
25298 jmp 13f
25299 12:
25300 cmp $1, %rdx
25301 @@ -202,6 +202,7 @@ ENTRY(memmove)
25302 movb (%rsi), %r11b
25303 movb %r11b, (%rdi)
25304 13:
25305 + pax_force_retaddr
25306 retq
25307 CFI_ENDPROC
25308
25309 @@ -210,6 +211,7 @@ ENTRY(memmove)
25310 /* Forward moving data. */
25311 movq %rdx, %rcx
25312 rep movsb
25313 + pax_force_retaddr
25314 retq
25315 .Lmemmove_end_forward_efs:
25316 .previous
25317 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25318 index 2dcb380..963660a 100644
25319 --- a/arch/x86/lib/memset_64.S
25320 +++ b/arch/x86/lib/memset_64.S
25321 @@ -30,6 +30,7 @@
25322 movl %edx,%ecx
25323 rep stosb
25324 movq %r9,%rax
25325 + pax_force_retaddr
25326 ret
25327 .Lmemset_e:
25328 .previous
25329 @@ -52,6 +53,7 @@
25330 movq %rdx,%rcx
25331 rep stosb
25332 movq %r9,%rax
25333 + pax_force_retaddr
25334 ret
25335 .Lmemset_e_e:
25336 .previous
25337 @@ -59,7 +61,7 @@
25338 ENTRY(memset)
25339 ENTRY(__memset)
25340 CFI_STARTPROC
25341 - movq %rdi,%r10
25342 + movq %rdi,%r11
25343
25344 /* expand byte value */
25345 movzbl %sil,%ecx
25346 @@ -117,7 +119,8 @@ ENTRY(__memset)
25347 jnz .Lloop_1
25348
25349 .Lende:
25350 - movq %r10,%rax
25351 + movq %r11,%rax
25352 + pax_force_retaddr
25353 ret
25354
25355 CFI_RESTORE_STATE
25356 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25357 index c9f2d9b..e7fd2c0 100644
25358 --- a/arch/x86/lib/mmx_32.c
25359 +++ b/arch/x86/lib/mmx_32.c
25360 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25361 {
25362 void *p;
25363 int i;
25364 + unsigned long cr0;
25365
25366 if (unlikely(in_interrupt()))
25367 return __memcpy(to, from, len);
25368 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25369 kernel_fpu_begin();
25370
25371 __asm__ __volatile__ (
25372 - "1: prefetch (%0)\n" /* This set is 28 bytes */
25373 - " prefetch 64(%0)\n"
25374 - " prefetch 128(%0)\n"
25375 - " prefetch 192(%0)\n"
25376 - " prefetch 256(%0)\n"
25377 + "1: prefetch (%1)\n" /* This set is 28 bytes */
25378 + " prefetch 64(%1)\n"
25379 + " prefetch 128(%1)\n"
25380 + " prefetch 192(%1)\n"
25381 + " prefetch 256(%1)\n"
25382 "2: \n"
25383 ".section .fixup, \"ax\"\n"
25384 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25385 + "3: \n"
25386 +
25387 +#ifdef CONFIG_PAX_KERNEXEC
25388 + " movl %%cr0, %0\n"
25389 + " movl %0, %%eax\n"
25390 + " andl $0xFFFEFFFF, %%eax\n"
25391 + " movl %%eax, %%cr0\n"
25392 +#endif
25393 +
25394 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25395 +
25396 +#ifdef CONFIG_PAX_KERNEXEC
25397 + " movl %0, %%cr0\n"
25398 +#endif
25399 +
25400 " jmp 2b\n"
25401 ".previous\n"
25402 _ASM_EXTABLE(1b, 3b)
25403 - : : "r" (from));
25404 + : "=&r" (cr0) : "r" (from) : "ax");
25405
25406 for ( ; i > 5; i--) {
25407 __asm__ __volatile__ (
25408 - "1: prefetch 320(%0)\n"
25409 - "2: movq (%0), %%mm0\n"
25410 - " movq 8(%0), %%mm1\n"
25411 - " movq 16(%0), %%mm2\n"
25412 - " movq 24(%0), %%mm3\n"
25413 - " movq %%mm0, (%1)\n"
25414 - " movq %%mm1, 8(%1)\n"
25415 - " movq %%mm2, 16(%1)\n"
25416 - " movq %%mm3, 24(%1)\n"
25417 - " movq 32(%0), %%mm0\n"
25418 - " movq 40(%0), %%mm1\n"
25419 - " movq 48(%0), %%mm2\n"
25420 - " movq 56(%0), %%mm3\n"
25421 - " movq %%mm0, 32(%1)\n"
25422 - " movq %%mm1, 40(%1)\n"
25423 - " movq %%mm2, 48(%1)\n"
25424 - " movq %%mm3, 56(%1)\n"
25425 + "1: prefetch 320(%1)\n"
25426 + "2: movq (%1), %%mm0\n"
25427 + " movq 8(%1), %%mm1\n"
25428 + " movq 16(%1), %%mm2\n"
25429 + " movq 24(%1), %%mm3\n"
25430 + " movq %%mm0, (%2)\n"
25431 + " movq %%mm1, 8(%2)\n"
25432 + " movq %%mm2, 16(%2)\n"
25433 + " movq %%mm3, 24(%2)\n"
25434 + " movq 32(%1), %%mm0\n"
25435 + " movq 40(%1), %%mm1\n"
25436 + " movq 48(%1), %%mm2\n"
25437 + " movq 56(%1), %%mm3\n"
25438 + " movq %%mm0, 32(%2)\n"
25439 + " movq %%mm1, 40(%2)\n"
25440 + " movq %%mm2, 48(%2)\n"
25441 + " movq %%mm3, 56(%2)\n"
25442 ".section .fixup, \"ax\"\n"
25443 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25444 + "3:\n"
25445 +
25446 +#ifdef CONFIG_PAX_KERNEXEC
25447 + " movl %%cr0, %0\n"
25448 + " movl %0, %%eax\n"
25449 + " andl $0xFFFEFFFF, %%eax\n"
25450 + " movl %%eax, %%cr0\n"
25451 +#endif
25452 +
25453 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25454 +
25455 +#ifdef CONFIG_PAX_KERNEXEC
25456 + " movl %0, %%cr0\n"
25457 +#endif
25458 +
25459 " jmp 2b\n"
25460 ".previous\n"
25461 _ASM_EXTABLE(1b, 3b)
25462 - : : "r" (from), "r" (to) : "memory");
25463 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25464
25465 from += 64;
25466 to += 64;
25467 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25468 static void fast_copy_page(void *to, void *from)
25469 {
25470 int i;
25471 + unsigned long cr0;
25472
25473 kernel_fpu_begin();
25474
25475 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25476 * but that is for later. -AV
25477 */
25478 __asm__ __volatile__(
25479 - "1: prefetch (%0)\n"
25480 - " prefetch 64(%0)\n"
25481 - " prefetch 128(%0)\n"
25482 - " prefetch 192(%0)\n"
25483 - " prefetch 256(%0)\n"
25484 + "1: prefetch (%1)\n"
25485 + " prefetch 64(%1)\n"
25486 + " prefetch 128(%1)\n"
25487 + " prefetch 192(%1)\n"
25488 + " prefetch 256(%1)\n"
25489 "2: \n"
25490 ".section .fixup, \"ax\"\n"
25491 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25492 + "3: \n"
25493 +
25494 +#ifdef CONFIG_PAX_KERNEXEC
25495 + " movl %%cr0, %0\n"
25496 + " movl %0, %%eax\n"
25497 + " andl $0xFFFEFFFF, %%eax\n"
25498 + " movl %%eax, %%cr0\n"
25499 +#endif
25500 +
25501 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25502 +
25503 +#ifdef CONFIG_PAX_KERNEXEC
25504 + " movl %0, %%cr0\n"
25505 +#endif
25506 +
25507 " jmp 2b\n"
25508 ".previous\n"
25509 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
25510 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25511
25512 for (i = 0; i < (4096-320)/64; i++) {
25513 __asm__ __volatile__ (
25514 - "1: prefetch 320(%0)\n"
25515 - "2: movq (%0), %%mm0\n"
25516 - " movntq %%mm0, (%1)\n"
25517 - " movq 8(%0), %%mm1\n"
25518 - " movntq %%mm1, 8(%1)\n"
25519 - " movq 16(%0), %%mm2\n"
25520 - " movntq %%mm2, 16(%1)\n"
25521 - " movq 24(%0), %%mm3\n"
25522 - " movntq %%mm3, 24(%1)\n"
25523 - " movq 32(%0), %%mm4\n"
25524 - " movntq %%mm4, 32(%1)\n"
25525 - " movq 40(%0), %%mm5\n"
25526 - " movntq %%mm5, 40(%1)\n"
25527 - " movq 48(%0), %%mm6\n"
25528 - " movntq %%mm6, 48(%1)\n"
25529 - " movq 56(%0), %%mm7\n"
25530 - " movntq %%mm7, 56(%1)\n"
25531 + "1: prefetch 320(%1)\n"
25532 + "2: movq (%1), %%mm0\n"
25533 + " movntq %%mm0, (%2)\n"
25534 + " movq 8(%1), %%mm1\n"
25535 + " movntq %%mm1, 8(%2)\n"
25536 + " movq 16(%1), %%mm2\n"
25537 + " movntq %%mm2, 16(%2)\n"
25538 + " movq 24(%1), %%mm3\n"
25539 + " movntq %%mm3, 24(%2)\n"
25540 + " movq 32(%1), %%mm4\n"
25541 + " movntq %%mm4, 32(%2)\n"
25542 + " movq 40(%1), %%mm5\n"
25543 + " movntq %%mm5, 40(%2)\n"
25544 + " movq 48(%1), %%mm6\n"
25545 + " movntq %%mm6, 48(%2)\n"
25546 + " movq 56(%1), %%mm7\n"
25547 + " movntq %%mm7, 56(%2)\n"
25548 ".section .fixup, \"ax\"\n"
25549 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25550 + "3:\n"
25551 +
25552 +#ifdef CONFIG_PAX_KERNEXEC
25553 + " movl %%cr0, %0\n"
25554 + " movl %0, %%eax\n"
25555 + " andl $0xFFFEFFFF, %%eax\n"
25556 + " movl %%eax, %%cr0\n"
25557 +#endif
25558 +
25559 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25560 +
25561 +#ifdef CONFIG_PAX_KERNEXEC
25562 + " movl %0, %%cr0\n"
25563 +#endif
25564 +
25565 " jmp 2b\n"
25566 ".previous\n"
25567 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
25568 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25569
25570 from += 64;
25571 to += 64;
25572 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
25573 static void fast_copy_page(void *to, void *from)
25574 {
25575 int i;
25576 + unsigned long cr0;
25577
25578 kernel_fpu_begin();
25579
25580 __asm__ __volatile__ (
25581 - "1: prefetch (%0)\n"
25582 - " prefetch 64(%0)\n"
25583 - " prefetch 128(%0)\n"
25584 - " prefetch 192(%0)\n"
25585 - " prefetch 256(%0)\n"
25586 + "1: prefetch (%1)\n"
25587 + " prefetch 64(%1)\n"
25588 + " prefetch 128(%1)\n"
25589 + " prefetch 192(%1)\n"
25590 + " prefetch 256(%1)\n"
25591 "2: \n"
25592 ".section .fixup, \"ax\"\n"
25593 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25594 + "3: \n"
25595 +
25596 +#ifdef CONFIG_PAX_KERNEXEC
25597 + " movl %%cr0, %0\n"
25598 + " movl %0, %%eax\n"
25599 + " andl $0xFFFEFFFF, %%eax\n"
25600 + " movl %%eax, %%cr0\n"
25601 +#endif
25602 +
25603 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25604 +
25605 +#ifdef CONFIG_PAX_KERNEXEC
25606 + " movl %0, %%cr0\n"
25607 +#endif
25608 +
25609 " jmp 2b\n"
25610 ".previous\n"
25611 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
25612 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25613
25614 for (i = 0; i < 4096/64; i++) {
25615 __asm__ __volatile__ (
25616 - "1: prefetch 320(%0)\n"
25617 - "2: movq (%0), %%mm0\n"
25618 - " movq 8(%0), %%mm1\n"
25619 - " movq 16(%0), %%mm2\n"
25620 - " movq 24(%0), %%mm3\n"
25621 - " movq %%mm0, (%1)\n"
25622 - " movq %%mm1, 8(%1)\n"
25623 - " movq %%mm2, 16(%1)\n"
25624 - " movq %%mm3, 24(%1)\n"
25625 - " movq 32(%0), %%mm0\n"
25626 - " movq 40(%0), %%mm1\n"
25627 - " movq 48(%0), %%mm2\n"
25628 - " movq 56(%0), %%mm3\n"
25629 - " movq %%mm0, 32(%1)\n"
25630 - " movq %%mm1, 40(%1)\n"
25631 - " movq %%mm2, 48(%1)\n"
25632 - " movq %%mm3, 56(%1)\n"
25633 + "1: prefetch 320(%1)\n"
25634 + "2: movq (%1), %%mm0\n"
25635 + " movq 8(%1), %%mm1\n"
25636 + " movq 16(%1), %%mm2\n"
25637 + " movq 24(%1), %%mm3\n"
25638 + " movq %%mm0, (%2)\n"
25639 + " movq %%mm1, 8(%2)\n"
25640 + " movq %%mm2, 16(%2)\n"
25641 + " movq %%mm3, 24(%2)\n"
25642 + " movq 32(%1), %%mm0\n"
25643 + " movq 40(%1), %%mm1\n"
25644 + " movq 48(%1), %%mm2\n"
25645 + " movq 56(%1), %%mm3\n"
25646 + " movq %%mm0, 32(%2)\n"
25647 + " movq %%mm1, 40(%2)\n"
25648 + " movq %%mm2, 48(%2)\n"
25649 + " movq %%mm3, 56(%2)\n"
25650 ".section .fixup, \"ax\"\n"
25651 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25652 + "3:\n"
25653 +
25654 +#ifdef CONFIG_PAX_KERNEXEC
25655 + " movl %%cr0, %0\n"
25656 + " movl %0, %%eax\n"
25657 + " andl $0xFFFEFFFF, %%eax\n"
25658 + " movl %%eax, %%cr0\n"
25659 +#endif
25660 +
25661 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25662 +
25663 +#ifdef CONFIG_PAX_KERNEXEC
25664 + " movl %0, %%cr0\n"
25665 +#endif
25666 +
25667 " jmp 2b\n"
25668 ".previous\n"
25669 _ASM_EXTABLE(1b, 3b)
25670 - : : "r" (from), "r" (to) : "memory");
25671 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25672
25673 from += 64;
25674 to += 64;
25675 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
25676 index f6d13ee..aca5f0b 100644
25677 --- a/arch/x86/lib/msr-reg.S
25678 +++ b/arch/x86/lib/msr-reg.S
25679 @@ -3,6 +3,7 @@
25680 #include <asm/dwarf2.h>
25681 #include <asm/asm.h>
25682 #include <asm/msr.h>
25683 +#include <asm/alternative-asm.h>
25684
25685 #ifdef CONFIG_X86_64
25686 /*
25687 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
25688 CFI_STARTPROC
25689 pushq_cfi %rbx
25690 pushq_cfi %rbp
25691 - movq %rdi, %r10 /* Save pointer */
25692 + movq %rdi, %r9 /* Save pointer */
25693 xorl %r11d, %r11d /* Return value */
25694 movl (%rdi), %eax
25695 movl 4(%rdi), %ecx
25696 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
25697 movl 28(%rdi), %edi
25698 CFI_REMEMBER_STATE
25699 1: \op
25700 -2: movl %eax, (%r10)
25701 +2: movl %eax, (%r9)
25702 movl %r11d, %eax /* Return value */
25703 - movl %ecx, 4(%r10)
25704 - movl %edx, 8(%r10)
25705 - movl %ebx, 12(%r10)
25706 - movl %ebp, 20(%r10)
25707 - movl %esi, 24(%r10)
25708 - movl %edi, 28(%r10)
25709 + movl %ecx, 4(%r9)
25710 + movl %edx, 8(%r9)
25711 + movl %ebx, 12(%r9)
25712 + movl %ebp, 20(%r9)
25713 + movl %esi, 24(%r9)
25714 + movl %edi, 28(%r9)
25715 popq_cfi %rbp
25716 popq_cfi %rbx
25717 + pax_force_retaddr
25718 ret
25719 3:
25720 CFI_RESTORE_STATE
25721 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
25722 index fc6ba17..04471c5 100644
25723 --- a/arch/x86/lib/putuser.S
25724 +++ b/arch/x86/lib/putuser.S
25725 @@ -16,7 +16,9 @@
25726 #include <asm/errno.h>
25727 #include <asm/asm.h>
25728 #include <asm/smap.h>
25729 -
25730 +#include <asm/segment.h>
25731 +#include <asm/pgtable.h>
25732 +#include <asm/alternative-asm.h>
25733
25734 /*
25735 * __put_user_X
25736 @@ -30,57 +32,125 @@
25737 * as they get called from within inline assembly.
25738 */
25739
25740 -#define ENTER CFI_STARTPROC ; \
25741 - GET_THREAD_INFO(%_ASM_BX)
25742 -#define EXIT ASM_CLAC ; \
25743 - ret ; \
25744 +#define ENTER CFI_STARTPROC
25745 +#define EXIT ASM_CLAC ; \
25746 + pax_force_retaddr ; \
25747 + ret ; \
25748 CFI_ENDPROC
25749
25750 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25751 +#define _DEST %_ASM_CX,%_ASM_BX
25752 +#else
25753 +#define _DEST %_ASM_CX
25754 +#endif
25755 +
25756 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25757 +#define __copyuser_seg gs;
25758 +#else
25759 +#define __copyuser_seg
25760 +#endif
25761 +
25762 .text
25763 ENTRY(__put_user_1)
25764 ENTER
25765 +
25766 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25767 + GET_THREAD_INFO(%_ASM_BX)
25768 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
25769 jae bad_put_user
25770 ASM_STAC
25771 -1: movb %al,(%_ASM_CX)
25772 +
25773 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25774 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25775 + cmp %_ASM_BX,%_ASM_CX
25776 + jb 1234f
25777 + xor %ebx,%ebx
25778 +1234:
25779 +#endif
25780 +
25781 +#endif
25782 +
25783 +1: __copyuser_seg movb %al,(_DEST)
25784 xor %eax,%eax
25785 EXIT
25786 ENDPROC(__put_user_1)
25787
25788 ENTRY(__put_user_2)
25789 ENTER
25790 +
25791 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25792 + GET_THREAD_INFO(%_ASM_BX)
25793 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25794 sub $1,%_ASM_BX
25795 cmp %_ASM_BX,%_ASM_CX
25796 jae bad_put_user
25797 ASM_STAC
25798 -2: movw %ax,(%_ASM_CX)
25799 +
25800 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25801 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25802 + cmp %_ASM_BX,%_ASM_CX
25803 + jb 1234f
25804 + xor %ebx,%ebx
25805 +1234:
25806 +#endif
25807 +
25808 +#endif
25809 +
25810 +2: __copyuser_seg movw %ax,(_DEST)
25811 xor %eax,%eax
25812 EXIT
25813 ENDPROC(__put_user_2)
25814
25815 ENTRY(__put_user_4)
25816 ENTER
25817 +
25818 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25819 + GET_THREAD_INFO(%_ASM_BX)
25820 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25821 sub $3,%_ASM_BX
25822 cmp %_ASM_BX,%_ASM_CX
25823 jae bad_put_user
25824 ASM_STAC
25825 -3: movl %eax,(%_ASM_CX)
25826 +
25827 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25828 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25829 + cmp %_ASM_BX,%_ASM_CX
25830 + jb 1234f
25831 + xor %ebx,%ebx
25832 +1234:
25833 +#endif
25834 +
25835 +#endif
25836 +
25837 +3: __copyuser_seg movl %eax,(_DEST)
25838 xor %eax,%eax
25839 EXIT
25840 ENDPROC(__put_user_4)
25841
25842 ENTRY(__put_user_8)
25843 ENTER
25844 +
25845 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25846 + GET_THREAD_INFO(%_ASM_BX)
25847 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25848 sub $7,%_ASM_BX
25849 cmp %_ASM_BX,%_ASM_CX
25850 jae bad_put_user
25851 ASM_STAC
25852 -4: mov %_ASM_AX,(%_ASM_CX)
25853 +
25854 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25855 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25856 + cmp %_ASM_BX,%_ASM_CX
25857 + jb 1234f
25858 + xor %ebx,%ebx
25859 +1234:
25860 +#endif
25861 +
25862 +#endif
25863 +
25864 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
25865 #ifdef CONFIG_X86_32
25866 -5: movl %edx,4(%_ASM_CX)
25867 +5: __copyuser_seg movl %edx,4(_DEST)
25868 #endif
25869 xor %eax,%eax
25870 EXIT
25871 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
25872 index 1cad221..de671ee 100644
25873 --- a/arch/x86/lib/rwlock.S
25874 +++ b/arch/x86/lib/rwlock.S
25875 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
25876 FRAME
25877 0: LOCK_PREFIX
25878 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25879 +
25880 +#ifdef CONFIG_PAX_REFCOUNT
25881 + jno 1234f
25882 + LOCK_PREFIX
25883 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25884 + int $4
25885 +1234:
25886 + _ASM_EXTABLE(1234b, 1234b)
25887 +#endif
25888 +
25889 1: rep; nop
25890 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
25891 jne 1b
25892 LOCK_PREFIX
25893 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25894 +
25895 +#ifdef CONFIG_PAX_REFCOUNT
25896 + jno 1234f
25897 + LOCK_PREFIX
25898 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25899 + int $4
25900 +1234:
25901 + _ASM_EXTABLE(1234b, 1234b)
25902 +#endif
25903 +
25904 jnz 0b
25905 ENDFRAME
25906 + pax_force_retaddr
25907 ret
25908 CFI_ENDPROC
25909 END(__write_lock_failed)
25910 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
25911 FRAME
25912 0: LOCK_PREFIX
25913 READ_LOCK_SIZE(inc) (%__lock_ptr)
25914 +
25915 +#ifdef CONFIG_PAX_REFCOUNT
25916 + jno 1234f
25917 + LOCK_PREFIX
25918 + READ_LOCK_SIZE(dec) (%__lock_ptr)
25919 + int $4
25920 +1234:
25921 + _ASM_EXTABLE(1234b, 1234b)
25922 +#endif
25923 +
25924 1: rep; nop
25925 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
25926 js 1b
25927 LOCK_PREFIX
25928 READ_LOCK_SIZE(dec) (%__lock_ptr)
25929 +
25930 +#ifdef CONFIG_PAX_REFCOUNT
25931 + jno 1234f
25932 + LOCK_PREFIX
25933 + READ_LOCK_SIZE(inc) (%__lock_ptr)
25934 + int $4
25935 +1234:
25936 + _ASM_EXTABLE(1234b, 1234b)
25937 +#endif
25938 +
25939 js 0b
25940 ENDFRAME
25941 + pax_force_retaddr
25942 ret
25943 CFI_ENDPROC
25944 END(__read_lock_failed)
25945 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
25946 index 5dff5f0..cadebf4 100644
25947 --- a/arch/x86/lib/rwsem.S
25948 +++ b/arch/x86/lib/rwsem.S
25949 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
25950 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25951 CFI_RESTORE __ASM_REG(dx)
25952 restore_common_regs
25953 + pax_force_retaddr
25954 ret
25955 CFI_ENDPROC
25956 ENDPROC(call_rwsem_down_read_failed)
25957 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
25958 movq %rax,%rdi
25959 call rwsem_down_write_failed
25960 restore_common_regs
25961 + pax_force_retaddr
25962 ret
25963 CFI_ENDPROC
25964 ENDPROC(call_rwsem_down_write_failed)
25965 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
25966 movq %rax,%rdi
25967 call rwsem_wake
25968 restore_common_regs
25969 -1: ret
25970 +1: pax_force_retaddr
25971 + ret
25972 CFI_ENDPROC
25973 ENDPROC(call_rwsem_wake)
25974
25975 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
25976 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25977 CFI_RESTORE __ASM_REG(dx)
25978 restore_common_regs
25979 + pax_force_retaddr
25980 ret
25981 CFI_ENDPROC
25982 ENDPROC(call_rwsem_downgrade_wake)
25983 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
25984 index a63efd6..ccecad8 100644
25985 --- a/arch/x86/lib/thunk_64.S
25986 +++ b/arch/x86/lib/thunk_64.S
25987 @@ -8,6 +8,7 @@
25988 #include <linux/linkage.h>
25989 #include <asm/dwarf2.h>
25990 #include <asm/calling.h>
25991 +#include <asm/alternative-asm.h>
25992
25993 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
25994 .macro THUNK name, func, put_ret_addr_in_rdi=0
25995 @@ -41,5 +42,6 @@
25996 SAVE_ARGS
25997 restore:
25998 RESTORE_ARGS
25999 + pax_force_retaddr
26000 ret
26001 CFI_ENDPROC
26002 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26003 index f0312d7..9c39d63 100644
26004 --- a/arch/x86/lib/usercopy_32.c
26005 +++ b/arch/x86/lib/usercopy_32.c
26006 @@ -42,11 +42,13 @@ do { \
26007 int __d0; \
26008 might_fault(); \
26009 __asm__ __volatile__( \
26010 + __COPYUSER_SET_ES \
26011 ASM_STAC "\n" \
26012 "0: rep; stosl\n" \
26013 " movl %2,%0\n" \
26014 "1: rep; stosb\n" \
26015 "2: " ASM_CLAC "\n" \
26016 + __COPYUSER_RESTORE_ES \
26017 ".section .fixup,\"ax\"\n" \
26018 "3: lea 0(%2,%0,4),%0\n" \
26019 " jmp 2b\n" \
26020 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26021
26022 #ifdef CONFIG_X86_INTEL_USERCOPY
26023 static unsigned long
26024 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
26025 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26026 {
26027 int d0, d1;
26028 __asm__ __volatile__(
26029 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26030 " .align 2,0x90\n"
26031 "3: movl 0(%4), %%eax\n"
26032 "4: movl 4(%4), %%edx\n"
26033 - "5: movl %%eax, 0(%3)\n"
26034 - "6: movl %%edx, 4(%3)\n"
26035 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26036 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26037 "7: movl 8(%4), %%eax\n"
26038 "8: movl 12(%4),%%edx\n"
26039 - "9: movl %%eax, 8(%3)\n"
26040 - "10: movl %%edx, 12(%3)\n"
26041 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26042 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26043 "11: movl 16(%4), %%eax\n"
26044 "12: movl 20(%4), %%edx\n"
26045 - "13: movl %%eax, 16(%3)\n"
26046 - "14: movl %%edx, 20(%3)\n"
26047 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26048 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26049 "15: movl 24(%4), %%eax\n"
26050 "16: movl 28(%4), %%edx\n"
26051 - "17: movl %%eax, 24(%3)\n"
26052 - "18: movl %%edx, 28(%3)\n"
26053 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26054 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26055 "19: movl 32(%4), %%eax\n"
26056 "20: movl 36(%4), %%edx\n"
26057 - "21: movl %%eax, 32(%3)\n"
26058 - "22: movl %%edx, 36(%3)\n"
26059 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26060 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26061 "23: movl 40(%4), %%eax\n"
26062 "24: movl 44(%4), %%edx\n"
26063 - "25: movl %%eax, 40(%3)\n"
26064 - "26: movl %%edx, 44(%3)\n"
26065 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26066 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26067 "27: movl 48(%4), %%eax\n"
26068 "28: movl 52(%4), %%edx\n"
26069 - "29: movl %%eax, 48(%3)\n"
26070 - "30: movl %%edx, 52(%3)\n"
26071 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26072 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26073 "31: movl 56(%4), %%eax\n"
26074 "32: movl 60(%4), %%edx\n"
26075 - "33: movl %%eax, 56(%3)\n"
26076 - "34: movl %%edx, 60(%3)\n"
26077 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26078 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26079 " addl $-64, %0\n"
26080 " addl $64, %4\n"
26081 " addl $64, %3\n"
26082 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26083 " shrl $2, %0\n"
26084 " andl $3, %%eax\n"
26085 " cld\n"
26086 + __COPYUSER_SET_ES
26087 "99: rep; movsl\n"
26088 "36: movl %%eax, %0\n"
26089 "37: rep; movsb\n"
26090 "100:\n"
26091 + __COPYUSER_RESTORE_ES
26092 ".section .fixup,\"ax\"\n"
26093 "101: lea 0(%%eax,%0,4),%0\n"
26094 " jmp 100b\n"
26095 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26096 }
26097
26098 static unsigned long
26099 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26100 +{
26101 + int d0, d1;
26102 + __asm__ __volatile__(
26103 + " .align 2,0x90\n"
26104 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26105 + " cmpl $67, %0\n"
26106 + " jbe 3f\n"
26107 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26108 + " .align 2,0x90\n"
26109 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26110 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26111 + "5: movl %%eax, 0(%3)\n"
26112 + "6: movl %%edx, 4(%3)\n"
26113 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26114 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26115 + "9: movl %%eax, 8(%3)\n"
26116 + "10: movl %%edx, 12(%3)\n"
26117 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26118 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26119 + "13: movl %%eax, 16(%3)\n"
26120 + "14: movl %%edx, 20(%3)\n"
26121 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26122 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26123 + "17: movl %%eax, 24(%3)\n"
26124 + "18: movl %%edx, 28(%3)\n"
26125 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26126 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26127 + "21: movl %%eax, 32(%3)\n"
26128 + "22: movl %%edx, 36(%3)\n"
26129 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26130 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26131 + "25: movl %%eax, 40(%3)\n"
26132 + "26: movl %%edx, 44(%3)\n"
26133 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26134 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26135 + "29: movl %%eax, 48(%3)\n"
26136 + "30: movl %%edx, 52(%3)\n"
26137 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26138 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26139 + "33: movl %%eax, 56(%3)\n"
26140 + "34: movl %%edx, 60(%3)\n"
26141 + " addl $-64, %0\n"
26142 + " addl $64, %4\n"
26143 + " addl $64, %3\n"
26144 + " cmpl $63, %0\n"
26145 + " ja 1b\n"
26146 + "35: movl %0, %%eax\n"
26147 + " shrl $2, %0\n"
26148 + " andl $3, %%eax\n"
26149 + " cld\n"
26150 + "99: rep; "__copyuser_seg" movsl\n"
26151 + "36: movl %%eax, %0\n"
26152 + "37: rep; "__copyuser_seg" movsb\n"
26153 + "100:\n"
26154 + ".section .fixup,\"ax\"\n"
26155 + "101: lea 0(%%eax,%0,4),%0\n"
26156 + " jmp 100b\n"
26157 + ".previous\n"
26158 + _ASM_EXTABLE(1b,100b)
26159 + _ASM_EXTABLE(2b,100b)
26160 + _ASM_EXTABLE(3b,100b)
26161 + _ASM_EXTABLE(4b,100b)
26162 + _ASM_EXTABLE(5b,100b)
26163 + _ASM_EXTABLE(6b,100b)
26164 + _ASM_EXTABLE(7b,100b)
26165 + _ASM_EXTABLE(8b,100b)
26166 + _ASM_EXTABLE(9b,100b)
26167 + _ASM_EXTABLE(10b,100b)
26168 + _ASM_EXTABLE(11b,100b)
26169 + _ASM_EXTABLE(12b,100b)
26170 + _ASM_EXTABLE(13b,100b)
26171 + _ASM_EXTABLE(14b,100b)
26172 + _ASM_EXTABLE(15b,100b)
26173 + _ASM_EXTABLE(16b,100b)
26174 + _ASM_EXTABLE(17b,100b)
26175 + _ASM_EXTABLE(18b,100b)
26176 + _ASM_EXTABLE(19b,100b)
26177 + _ASM_EXTABLE(20b,100b)
26178 + _ASM_EXTABLE(21b,100b)
26179 + _ASM_EXTABLE(22b,100b)
26180 + _ASM_EXTABLE(23b,100b)
26181 + _ASM_EXTABLE(24b,100b)
26182 + _ASM_EXTABLE(25b,100b)
26183 + _ASM_EXTABLE(26b,100b)
26184 + _ASM_EXTABLE(27b,100b)
26185 + _ASM_EXTABLE(28b,100b)
26186 + _ASM_EXTABLE(29b,100b)
26187 + _ASM_EXTABLE(30b,100b)
26188 + _ASM_EXTABLE(31b,100b)
26189 + _ASM_EXTABLE(32b,100b)
26190 + _ASM_EXTABLE(33b,100b)
26191 + _ASM_EXTABLE(34b,100b)
26192 + _ASM_EXTABLE(35b,100b)
26193 + _ASM_EXTABLE(36b,100b)
26194 + _ASM_EXTABLE(37b,100b)
26195 + _ASM_EXTABLE(99b,101b)
26196 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
26197 + : "1"(to), "2"(from), "0"(size)
26198 + : "eax", "edx", "memory");
26199 + return size;
26200 +}
26201 +
26202 +static unsigned long __size_overflow(3)
26203 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26204 {
26205 int d0, d1;
26206 __asm__ __volatile__(
26207 " .align 2,0x90\n"
26208 - "0: movl 32(%4), %%eax\n"
26209 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26210 " cmpl $67, %0\n"
26211 " jbe 2f\n"
26212 - "1: movl 64(%4), %%eax\n"
26213 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26214 " .align 2,0x90\n"
26215 - "2: movl 0(%4), %%eax\n"
26216 - "21: movl 4(%4), %%edx\n"
26217 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26218 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26219 " movl %%eax, 0(%3)\n"
26220 " movl %%edx, 4(%3)\n"
26221 - "3: movl 8(%4), %%eax\n"
26222 - "31: movl 12(%4),%%edx\n"
26223 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26224 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26225 " movl %%eax, 8(%3)\n"
26226 " movl %%edx, 12(%3)\n"
26227 - "4: movl 16(%4), %%eax\n"
26228 - "41: movl 20(%4), %%edx\n"
26229 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26230 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26231 " movl %%eax, 16(%3)\n"
26232 " movl %%edx, 20(%3)\n"
26233 - "10: movl 24(%4), %%eax\n"
26234 - "51: movl 28(%4), %%edx\n"
26235 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26236 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26237 " movl %%eax, 24(%3)\n"
26238 " movl %%edx, 28(%3)\n"
26239 - "11: movl 32(%4), %%eax\n"
26240 - "61: movl 36(%4), %%edx\n"
26241 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26242 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26243 " movl %%eax, 32(%3)\n"
26244 " movl %%edx, 36(%3)\n"
26245 - "12: movl 40(%4), %%eax\n"
26246 - "71: movl 44(%4), %%edx\n"
26247 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26248 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26249 " movl %%eax, 40(%3)\n"
26250 " movl %%edx, 44(%3)\n"
26251 - "13: movl 48(%4), %%eax\n"
26252 - "81: movl 52(%4), %%edx\n"
26253 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26254 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26255 " movl %%eax, 48(%3)\n"
26256 " movl %%edx, 52(%3)\n"
26257 - "14: movl 56(%4), %%eax\n"
26258 - "91: movl 60(%4), %%edx\n"
26259 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26260 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26261 " movl %%eax, 56(%3)\n"
26262 " movl %%edx, 60(%3)\n"
26263 " addl $-64, %0\n"
26264 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26265 " shrl $2, %0\n"
26266 " andl $3, %%eax\n"
26267 " cld\n"
26268 - "6: rep; movsl\n"
26269 + "6: rep; "__copyuser_seg" movsl\n"
26270 " movl %%eax,%0\n"
26271 - "7: rep; movsb\n"
26272 + "7: rep; "__copyuser_seg" movsb\n"
26273 "8:\n"
26274 ".section .fixup,\"ax\"\n"
26275 "9: lea 0(%%eax,%0,4),%0\n"
26276 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26277 * hyoshiok@miraclelinux.com
26278 */
26279
26280 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26281 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26282 const void __user *from, unsigned long size)
26283 {
26284 int d0, d1;
26285
26286 __asm__ __volatile__(
26287 " .align 2,0x90\n"
26288 - "0: movl 32(%4), %%eax\n"
26289 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26290 " cmpl $67, %0\n"
26291 " jbe 2f\n"
26292 - "1: movl 64(%4), %%eax\n"
26293 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26294 " .align 2,0x90\n"
26295 - "2: movl 0(%4), %%eax\n"
26296 - "21: movl 4(%4), %%edx\n"
26297 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26298 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26299 " movnti %%eax, 0(%3)\n"
26300 " movnti %%edx, 4(%3)\n"
26301 - "3: movl 8(%4), %%eax\n"
26302 - "31: movl 12(%4),%%edx\n"
26303 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26304 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26305 " movnti %%eax, 8(%3)\n"
26306 " movnti %%edx, 12(%3)\n"
26307 - "4: movl 16(%4), %%eax\n"
26308 - "41: movl 20(%4), %%edx\n"
26309 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26310 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26311 " movnti %%eax, 16(%3)\n"
26312 " movnti %%edx, 20(%3)\n"
26313 - "10: movl 24(%4), %%eax\n"
26314 - "51: movl 28(%4), %%edx\n"
26315 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26316 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26317 " movnti %%eax, 24(%3)\n"
26318 " movnti %%edx, 28(%3)\n"
26319 - "11: movl 32(%4), %%eax\n"
26320 - "61: movl 36(%4), %%edx\n"
26321 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26322 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26323 " movnti %%eax, 32(%3)\n"
26324 " movnti %%edx, 36(%3)\n"
26325 - "12: movl 40(%4), %%eax\n"
26326 - "71: movl 44(%4), %%edx\n"
26327 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26328 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26329 " movnti %%eax, 40(%3)\n"
26330 " movnti %%edx, 44(%3)\n"
26331 - "13: movl 48(%4), %%eax\n"
26332 - "81: movl 52(%4), %%edx\n"
26333 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26334 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26335 " movnti %%eax, 48(%3)\n"
26336 " movnti %%edx, 52(%3)\n"
26337 - "14: movl 56(%4), %%eax\n"
26338 - "91: movl 60(%4), %%edx\n"
26339 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26340 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26341 " movnti %%eax, 56(%3)\n"
26342 " movnti %%edx, 60(%3)\n"
26343 " addl $-64, %0\n"
26344 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26345 " shrl $2, %0\n"
26346 " andl $3, %%eax\n"
26347 " cld\n"
26348 - "6: rep; movsl\n"
26349 + "6: rep; "__copyuser_seg" movsl\n"
26350 " movl %%eax,%0\n"
26351 - "7: rep; movsb\n"
26352 + "7: rep; "__copyuser_seg" movsb\n"
26353 "8:\n"
26354 ".section .fixup,\"ax\"\n"
26355 "9: lea 0(%%eax,%0,4),%0\n"
26356 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26357 return size;
26358 }
26359
26360 -static unsigned long __copy_user_intel_nocache(void *to,
26361 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26362 const void __user *from, unsigned long size)
26363 {
26364 int d0, d1;
26365
26366 __asm__ __volatile__(
26367 " .align 2,0x90\n"
26368 - "0: movl 32(%4), %%eax\n"
26369 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26370 " cmpl $67, %0\n"
26371 " jbe 2f\n"
26372 - "1: movl 64(%4), %%eax\n"
26373 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26374 " .align 2,0x90\n"
26375 - "2: movl 0(%4), %%eax\n"
26376 - "21: movl 4(%4), %%edx\n"
26377 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26378 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26379 " movnti %%eax, 0(%3)\n"
26380 " movnti %%edx, 4(%3)\n"
26381 - "3: movl 8(%4), %%eax\n"
26382 - "31: movl 12(%4),%%edx\n"
26383 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26384 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26385 " movnti %%eax, 8(%3)\n"
26386 " movnti %%edx, 12(%3)\n"
26387 - "4: movl 16(%4), %%eax\n"
26388 - "41: movl 20(%4), %%edx\n"
26389 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26390 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26391 " movnti %%eax, 16(%3)\n"
26392 " movnti %%edx, 20(%3)\n"
26393 - "10: movl 24(%4), %%eax\n"
26394 - "51: movl 28(%4), %%edx\n"
26395 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26396 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26397 " movnti %%eax, 24(%3)\n"
26398 " movnti %%edx, 28(%3)\n"
26399 - "11: movl 32(%4), %%eax\n"
26400 - "61: movl 36(%4), %%edx\n"
26401 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26402 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26403 " movnti %%eax, 32(%3)\n"
26404 " movnti %%edx, 36(%3)\n"
26405 - "12: movl 40(%4), %%eax\n"
26406 - "71: movl 44(%4), %%edx\n"
26407 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26408 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26409 " movnti %%eax, 40(%3)\n"
26410 " movnti %%edx, 44(%3)\n"
26411 - "13: movl 48(%4), %%eax\n"
26412 - "81: movl 52(%4), %%edx\n"
26413 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26414 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26415 " movnti %%eax, 48(%3)\n"
26416 " movnti %%edx, 52(%3)\n"
26417 - "14: movl 56(%4), %%eax\n"
26418 - "91: movl 60(%4), %%edx\n"
26419 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26420 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26421 " movnti %%eax, 56(%3)\n"
26422 " movnti %%edx, 60(%3)\n"
26423 " addl $-64, %0\n"
26424 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26425 " shrl $2, %0\n"
26426 " andl $3, %%eax\n"
26427 " cld\n"
26428 - "6: rep; movsl\n"
26429 + "6: rep; "__copyuser_seg" movsl\n"
26430 " movl %%eax,%0\n"
26431 - "7: rep; movsb\n"
26432 + "7: rep; "__copyuser_seg" movsb\n"
26433 "8:\n"
26434 ".section .fixup,\"ax\"\n"
26435 "9: lea 0(%%eax,%0,4),%0\n"
26436 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26437 */
26438 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26439 unsigned long size);
26440 -unsigned long __copy_user_intel(void __user *to, const void *from,
26441 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26442 + unsigned long size);
26443 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26444 unsigned long size);
26445 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26446 const void __user *from, unsigned long size);
26447 #endif /* CONFIG_X86_INTEL_USERCOPY */
26448
26449 /* Generic arbitrary sized copy. */
26450 -#define __copy_user(to, from, size) \
26451 +#define __copy_user(to, from, size, prefix, set, restore) \
26452 do { \
26453 int __d0, __d1, __d2; \
26454 __asm__ __volatile__( \
26455 + set \
26456 " cmp $7,%0\n" \
26457 " jbe 1f\n" \
26458 " movl %1,%0\n" \
26459 " negl %0\n" \
26460 " andl $7,%0\n" \
26461 " subl %0,%3\n" \
26462 - "4: rep; movsb\n" \
26463 + "4: rep; "prefix"movsb\n" \
26464 " movl %3,%0\n" \
26465 " shrl $2,%0\n" \
26466 " andl $3,%3\n" \
26467 " .align 2,0x90\n" \
26468 - "0: rep; movsl\n" \
26469 + "0: rep; "prefix"movsl\n" \
26470 " movl %3,%0\n" \
26471 - "1: rep; movsb\n" \
26472 + "1: rep; "prefix"movsb\n" \
26473 "2:\n" \
26474 + restore \
26475 ".section .fixup,\"ax\"\n" \
26476 "5: addl %3,%0\n" \
26477 " jmp 2b\n" \
26478 @@ -538,14 +650,14 @@ do { \
26479 " negl %0\n" \
26480 " andl $7,%0\n" \
26481 " subl %0,%3\n" \
26482 - "4: rep; movsb\n" \
26483 + "4: rep; "__copyuser_seg"movsb\n" \
26484 " movl %3,%0\n" \
26485 " shrl $2,%0\n" \
26486 " andl $3,%3\n" \
26487 " .align 2,0x90\n" \
26488 - "0: rep; movsl\n" \
26489 + "0: rep; "__copyuser_seg"movsl\n" \
26490 " movl %3,%0\n" \
26491 - "1: rep; movsb\n" \
26492 + "1: rep; "__copyuser_seg"movsb\n" \
26493 "2:\n" \
26494 ".section .fixup,\"ax\"\n" \
26495 "5: addl %3,%0\n" \
26496 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26497 {
26498 stac();
26499 if (movsl_is_ok(to, from, n))
26500 - __copy_user(to, from, n);
26501 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26502 else
26503 - n = __copy_user_intel(to, from, n);
26504 + n = __generic_copy_to_user_intel(to, from, n);
26505 clac();
26506 return n;
26507 }
26508 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26509 {
26510 stac();
26511 if (movsl_is_ok(to, from, n))
26512 - __copy_user(to, from, n);
26513 + __copy_user(to, from, n, __copyuser_seg, "", "");
26514 else
26515 - n = __copy_user_intel((void __user *)to,
26516 - (const void *)from, n);
26517 + n = __generic_copy_from_user_intel(to, from, n);
26518 clac();
26519 return n;
26520 }
26521 @@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26522 if (n > 64 && cpu_has_xmm2)
26523 n = __copy_user_intel_nocache(to, from, n);
26524 else
26525 - __copy_user(to, from, n);
26526 + __copy_user(to, from, n, __copyuser_seg, "", "");
26527 #else
26528 - __copy_user(to, from, n);
26529 + __copy_user(to, from, n, __copyuser_seg, "", "");
26530 #endif
26531 clac();
26532 return n;
26533 }
26534 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
26535
26536 -/**
26537 - * copy_to_user: - Copy a block of data into user space.
26538 - * @to: Destination address, in user space.
26539 - * @from: Source address, in kernel space.
26540 - * @n: Number of bytes to copy.
26541 - *
26542 - * Context: User context only. This function may sleep.
26543 - *
26544 - * Copy data from kernel space to user space.
26545 - *
26546 - * Returns number of bytes that could not be copied.
26547 - * On success, this will be zero.
26548 - */
26549 -unsigned long
26550 -copy_to_user(void __user *to, const void *from, unsigned long n)
26551 -{
26552 - if (access_ok(VERIFY_WRITE, to, n))
26553 - n = __copy_to_user(to, from, n);
26554 - return n;
26555 -}
26556 -EXPORT_SYMBOL(copy_to_user);
26557 -
26558 -/**
26559 - * copy_from_user: - Copy a block of data from user space.
26560 - * @to: Destination address, in kernel space.
26561 - * @from: Source address, in user space.
26562 - * @n: Number of bytes to copy.
26563 - *
26564 - * Context: User context only. This function may sleep.
26565 - *
26566 - * Copy data from user space to kernel space.
26567 - *
26568 - * Returns number of bytes that could not be copied.
26569 - * On success, this will be zero.
26570 - *
26571 - * If some data could not be copied, this function will pad the copied
26572 - * data to the requested size using zero bytes.
26573 - */
26574 -unsigned long
26575 -_copy_from_user(void *to, const void __user *from, unsigned long n)
26576 -{
26577 - if (access_ok(VERIFY_READ, from, n))
26578 - n = __copy_from_user(to, from, n);
26579 - else
26580 - memset(to, 0, n);
26581 - return n;
26582 -}
26583 -EXPORT_SYMBOL(_copy_from_user);
26584 -
26585 void copy_from_user_overflow(void)
26586 {
26587 WARN(1, "Buffer overflow detected!\n");
26588 }
26589 EXPORT_SYMBOL(copy_from_user_overflow);
26590 +
26591 +void copy_to_user_overflow(void)
26592 +{
26593 + WARN(1, "Buffer overflow detected!\n");
26594 +}
26595 +EXPORT_SYMBOL(copy_to_user_overflow);
26596 +
26597 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26598 +void __set_fs(mm_segment_t x)
26599 +{
26600 + switch (x.seg) {
26601 + case 0:
26602 + loadsegment(gs, 0);
26603 + break;
26604 + case TASK_SIZE_MAX:
26605 + loadsegment(gs, __USER_DS);
26606 + break;
26607 + case -1UL:
26608 + loadsegment(gs, __KERNEL_DS);
26609 + break;
26610 + default:
26611 + BUG();
26612 + }
26613 + return;
26614 +}
26615 +EXPORT_SYMBOL(__set_fs);
26616 +
26617 +void set_fs(mm_segment_t x)
26618 +{
26619 + current_thread_info()->addr_limit = x;
26620 + __set_fs(x);
26621 +}
26622 +EXPORT_SYMBOL(set_fs);
26623 +#endif
26624 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
26625 index 05928aa..b33dea1 100644
26626 --- a/arch/x86/lib/usercopy_64.c
26627 +++ b/arch/x86/lib/usercopy_64.c
26628 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
26629 _ASM_EXTABLE(0b,3b)
26630 _ASM_EXTABLE(1b,2b)
26631 : [size8] "=&c"(size), [dst] "=&D" (__d0)
26632 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
26633 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
26634 [zero] "r" (0UL), [eight] "r" (8UL));
26635 clac();
26636 return size;
26637 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
26638 }
26639 EXPORT_SYMBOL(clear_user);
26640
26641 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
26642 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
26643 {
26644 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
26645 - return copy_user_generic((__force void *)to, (__force void *)from, len);
26646 - }
26647 - return len;
26648 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
26649 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
26650 + return len;
26651 }
26652 EXPORT_SYMBOL(copy_in_user);
26653
26654 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
26655 * it is not necessary to optimize tail handling.
26656 */
26657 unsigned long
26658 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26659 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
26660 {
26661 char c;
26662 unsigned zero_len;
26663 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26664 clac();
26665 return len;
26666 }
26667 +
26668 +void copy_from_user_overflow(void)
26669 +{
26670 + WARN(1, "Buffer overflow detected!\n");
26671 +}
26672 +EXPORT_SYMBOL(copy_from_user_overflow);
26673 +
26674 +void copy_to_user_overflow(void)
26675 +{
26676 + WARN(1, "Buffer overflow detected!\n");
26677 +}
26678 +EXPORT_SYMBOL(copy_to_user_overflow);
26679 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
26680 index 903ec1e..c4166b2 100644
26681 --- a/arch/x86/mm/extable.c
26682 +++ b/arch/x86/mm/extable.c
26683 @@ -6,12 +6,24 @@
26684 static inline unsigned long
26685 ex_insn_addr(const struct exception_table_entry *x)
26686 {
26687 - return (unsigned long)&x->insn + x->insn;
26688 + unsigned long reloc = 0;
26689 +
26690 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26691 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26692 +#endif
26693 +
26694 + return (unsigned long)&x->insn + x->insn + reloc;
26695 }
26696 static inline unsigned long
26697 ex_fixup_addr(const struct exception_table_entry *x)
26698 {
26699 - return (unsigned long)&x->fixup + x->fixup;
26700 + unsigned long reloc = 0;
26701 +
26702 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26703 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26704 +#endif
26705 +
26706 + return (unsigned long)&x->fixup + x->fixup + reloc;
26707 }
26708
26709 int fixup_exception(struct pt_regs *regs)
26710 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
26711 unsigned long new_ip;
26712
26713 #ifdef CONFIG_PNPBIOS
26714 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
26715 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
26716 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
26717 extern u32 pnp_bios_is_utter_crap;
26718 pnp_bios_is_utter_crap = 1;
26719 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
26720 i += 4;
26721 p->fixup -= i;
26722 i += 4;
26723 +
26724 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26725 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
26726 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26727 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26728 +#endif
26729 +
26730 }
26731 }
26732
26733 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
26734 index fb674fd..272f369 100644
26735 --- a/arch/x86/mm/fault.c
26736 +++ b/arch/x86/mm/fault.c
26737 @@ -13,12 +13,19 @@
26738 #include <linux/perf_event.h> /* perf_sw_event */
26739 #include <linux/hugetlb.h> /* hstate_index_to_shift */
26740 #include <linux/prefetch.h> /* prefetchw */
26741 +#include <linux/unistd.h>
26742 +#include <linux/compiler.h>
26743
26744 #include <asm/traps.h> /* dotraplinkage, ... */
26745 #include <asm/pgalloc.h> /* pgd_*(), ... */
26746 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
26747 #include <asm/fixmap.h> /* VSYSCALL_START */
26748 #include <asm/context_tracking.h> /* exception_enter(), ... */
26749 +#include <asm/tlbflush.h>
26750 +
26751 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26752 +#include <asm/stacktrace.h>
26753 +#endif
26754
26755 /*
26756 * Page fault error code bits:
26757 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
26758 int ret = 0;
26759
26760 /* kprobe_running() needs smp_processor_id() */
26761 - if (kprobes_built_in() && !user_mode_vm(regs)) {
26762 + if (kprobes_built_in() && !user_mode(regs)) {
26763 preempt_disable();
26764 if (kprobe_running() && kprobe_fault_handler(regs, 14))
26765 ret = 1;
26766 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
26767 return !instr_lo || (instr_lo>>1) == 1;
26768 case 0x00:
26769 /* Prefetch instruction is 0x0F0D or 0x0F18 */
26770 - if (probe_kernel_address(instr, opcode))
26771 + if (user_mode(regs)) {
26772 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26773 + return 0;
26774 + } else if (probe_kernel_address(instr, opcode))
26775 return 0;
26776
26777 *prefetch = (instr_lo == 0xF) &&
26778 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
26779 while (instr < max_instr) {
26780 unsigned char opcode;
26781
26782 - if (probe_kernel_address(instr, opcode))
26783 + if (user_mode(regs)) {
26784 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26785 + break;
26786 + } else if (probe_kernel_address(instr, opcode))
26787 break;
26788
26789 instr++;
26790 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
26791 force_sig_info(si_signo, &info, tsk);
26792 }
26793
26794 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26795 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
26796 +#endif
26797 +
26798 +#ifdef CONFIG_PAX_EMUTRAMP
26799 +static int pax_handle_fetch_fault(struct pt_regs *regs);
26800 +#endif
26801 +
26802 +#ifdef CONFIG_PAX_PAGEEXEC
26803 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
26804 +{
26805 + pgd_t *pgd;
26806 + pud_t *pud;
26807 + pmd_t *pmd;
26808 +
26809 + pgd = pgd_offset(mm, address);
26810 + if (!pgd_present(*pgd))
26811 + return NULL;
26812 + pud = pud_offset(pgd, address);
26813 + if (!pud_present(*pud))
26814 + return NULL;
26815 + pmd = pmd_offset(pud, address);
26816 + if (!pmd_present(*pmd))
26817 + return NULL;
26818 + return pmd;
26819 +}
26820 +#endif
26821 +
26822 DEFINE_SPINLOCK(pgd_lock);
26823 LIST_HEAD(pgd_list);
26824
26825 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
26826 for (address = VMALLOC_START & PMD_MASK;
26827 address >= TASK_SIZE && address < FIXADDR_TOP;
26828 address += PMD_SIZE) {
26829 +
26830 +#ifdef CONFIG_PAX_PER_CPU_PGD
26831 + unsigned long cpu;
26832 +#else
26833 struct page *page;
26834 +#endif
26835
26836 spin_lock(&pgd_lock);
26837 +
26838 +#ifdef CONFIG_PAX_PER_CPU_PGD
26839 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26840 + pgd_t *pgd = get_cpu_pgd(cpu);
26841 + pmd_t *ret;
26842 +#else
26843 list_for_each_entry(page, &pgd_list, lru) {
26844 + pgd_t *pgd = page_address(page);
26845 spinlock_t *pgt_lock;
26846 pmd_t *ret;
26847
26848 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
26849 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26850
26851 spin_lock(pgt_lock);
26852 - ret = vmalloc_sync_one(page_address(page), address);
26853 +#endif
26854 +
26855 + ret = vmalloc_sync_one(pgd, address);
26856 +
26857 +#ifndef CONFIG_PAX_PER_CPU_PGD
26858 spin_unlock(pgt_lock);
26859 +#endif
26860
26861 if (!ret)
26862 break;
26863 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26864 * an interrupt in the middle of a task switch..
26865 */
26866 pgd_paddr = read_cr3();
26867 +
26868 +#ifdef CONFIG_PAX_PER_CPU_PGD
26869 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
26870 +#endif
26871 +
26872 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
26873 if (!pmd_k)
26874 return -1;
26875 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26876 * happen within a race in page table update. In the later
26877 * case just flush:
26878 */
26879 +
26880 +#ifdef CONFIG_PAX_PER_CPU_PGD
26881 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
26882 + pgd = pgd_offset_cpu(smp_processor_id(), address);
26883 +#else
26884 pgd = pgd_offset(current->active_mm, address);
26885 +#endif
26886 +
26887 pgd_ref = pgd_offset_k(address);
26888 if (pgd_none(*pgd_ref))
26889 return -1;
26890 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
26891 static int is_errata100(struct pt_regs *regs, unsigned long address)
26892 {
26893 #ifdef CONFIG_X86_64
26894 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
26895 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
26896 return 1;
26897 #endif
26898 return 0;
26899 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
26900 }
26901
26902 static const char nx_warning[] = KERN_CRIT
26903 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
26904 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
26905
26906 static void
26907 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26908 @@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26909 if (!oops_may_print())
26910 return;
26911
26912 - if (error_code & PF_INSTR) {
26913 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
26914 unsigned int level;
26915
26916 pte_t *pte = lookup_address(address, &level);
26917
26918 if (pte && pte_present(*pte) && !pte_exec(*pte))
26919 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
26920 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
26921 }
26922
26923 +#ifdef CONFIG_PAX_KERNEXEC
26924 + if (init_mm.start_code <= address && address < init_mm.end_code) {
26925 + if (current->signal->curr_ip)
26926 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
26927 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
26928 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26929 + else
26930 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
26931 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26932 + }
26933 +#endif
26934 +
26935 printk(KERN_ALERT "BUG: unable to handle kernel ");
26936 if (address < PAGE_SIZE)
26937 printk(KERN_CONT "NULL pointer dereference");
26938 @@ -748,6 +830,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
26939 return;
26940 }
26941 #endif
26942 +
26943 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26944 + if (pax_is_fetch_fault(regs, error_code, address)) {
26945 +
26946 +#ifdef CONFIG_PAX_EMUTRAMP
26947 + switch (pax_handle_fetch_fault(regs)) {
26948 + case 2:
26949 + return;
26950 + }
26951 +#endif
26952 +
26953 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26954 + do_group_exit(SIGKILL);
26955 + }
26956 +#endif
26957 +
26958 /* Kernel addresses are always protection faults: */
26959 if (address >= TASK_SIZE)
26960 error_code |= PF_PROT;
26961 @@ -833,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
26962 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
26963 printk(KERN_ERR
26964 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
26965 - tsk->comm, tsk->pid, address);
26966 + tsk->comm, task_pid_nr(tsk), address);
26967 code = BUS_MCEERR_AR;
26968 }
26969 #endif
26970 @@ -896,6 +994,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
26971 return 1;
26972 }
26973
26974 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26975 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
26976 +{
26977 + pte_t *pte;
26978 + pmd_t *pmd;
26979 + spinlock_t *ptl;
26980 + unsigned char pte_mask;
26981 +
26982 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
26983 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
26984 + return 0;
26985 +
26986 + /* PaX: it's our fault, let's handle it if we can */
26987 +
26988 + /* PaX: take a look at read faults before acquiring any locks */
26989 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
26990 + /* instruction fetch attempt from a protected page in user mode */
26991 + up_read(&mm->mmap_sem);
26992 +
26993 +#ifdef CONFIG_PAX_EMUTRAMP
26994 + switch (pax_handle_fetch_fault(regs)) {
26995 + case 2:
26996 + return 1;
26997 + }
26998 +#endif
26999 +
27000 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27001 + do_group_exit(SIGKILL);
27002 + }
27003 +
27004 + pmd = pax_get_pmd(mm, address);
27005 + if (unlikely(!pmd))
27006 + return 0;
27007 +
27008 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27009 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27010 + pte_unmap_unlock(pte, ptl);
27011 + return 0;
27012 + }
27013 +
27014 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27015 + /* write attempt to a protected page in user mode */
27016 + pte_unmap_unlock(pte, ptl);
27017 + return 0;
27018 + }
27019 +
27020 +#ifdef CONFIG_SMP
27021 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27022 +#else
27023 + if (likely(address > get_limit(regs->cs)))
27024 +#endif
27025 + {
27026 + set_pte(pte, pte_mkread(*pte));
27027 + __flush_tlb_one(address);
27028 + pte_unmap_unlock(pte, ptl);
27029 + up_read(&mm->mmap_sem);
27030 + return 1;
27031 + }
27032 +
27033 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27034 +
27035 + /*
27036 + * PaX: fill DTLB with user rights and retry
27037 + */
27038 + __asm__ __volatile__ (
27039 + "orb %2,(%1)\n"
27040 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27041 +/*
27042 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27043 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27044 + * page fault when examined during a TLB load attempt. this is true not only
27045 + * for PTEs holding a non-present entry but also present entries that will
27046 + * raise a page fault (such as those set up by PaX, or the copy-on-write
27047 + * mechanism). in effect it means that we do *not* need to flush the TLBs
27048 + * for our target pages since their PTEs are simply not in the TLBs at all.
27049 +
27050 + * the best thing in omitting it is that we gain around 15-20% speed in the
27051 + * fast path of the page fault handler and can get rid of tracing since we
27052 + * can no longer flush unintended entries.
27053 + */
27054 + "invlpg (%0)\n"
27055 +#endif
27056 + __copyuser_seg"testb $0,(%0)\n"
27057 + "xorb %3,(%1)\n"
27058 + :
27059 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27060 + : "memory", "cc");
27061 + pte_unmap_unlock(pte, ptl);
27062 + up_read(&mm->mmap_sem);
27063 + return 1;
27064 +}
27065 +#endif
27066 +
27067 /*
27068 * Handle a spurious fault caused by a stale TLB entry.
27069 *
27070 @@ -968,6 +1159,9 @@ int show_unhandled_signals = 1;
27071 static inline int
27072 access_error(unsigned long error_code, struct vm_area_struct *vma)
27073 {
27074 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27075 + return 1;
27076 +
27077 if (error_code & PF_WRITE) {
27078 /* write, present and write, not present: */
27079 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27080 @@ -996,7 +1190,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27081 if (error_code & PF_USER)
27082 return false;
27083
27084 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27085 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27086 return false;
27087
27088 return true;
27089 @@ -1012,18 +1206,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27090 {
27091 struct vm_area_struct *vma;
27092 struct task_struct *tsk;
27093 - unsigned long address;
27094 struct mm_struct *mm;
27095 int fault;
27096 int write = error_code & PF_WRITE;
27097 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27098 (write ? FAULT_FLAG_WRITE : 0);
27099
27100 - tsk = current;
27101 - mm = tsk->mm;
27102 -
27103 /* Get the faulting address: */
27104 - address = read_cr2();
27105 + unsigned long address = read_cr2();
27106 +
27107 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27108 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
27109 + if (!search_exception_tables(regs->ip)) {
27110 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27111 + bad_area_nosemaphore(regs, error_code, address);
27112 + return;
27113 + }
27114 + if (address < PAX_USER_SHADOW_BASE) {
27115 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27116 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27117 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27118 + } else
27119 + address -= PAX_USER_SHADOW_BASE;
27120 + }
27121 +#endif
27122 +
27123 + tsk = current;
27124 + mm = tsk->mm;
27125
27126 /*
27127 * Detect and handle instructions that would cause a page fault for
27128 @@ -1084,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27129 * User-mode registers count as a user access even for any
27130 * potential system fault or CPU buglet:
27131 */
27132 - if (user_mode_vm(regs)) {
27133 + if (user_mode(regs)) {
27134 local_irq_enable();
27135 error_code |= PF_USER;
27136 } else {
27137 @@ -1146,6 +1355,11 @@ retry:
27138 might_sleep();
27139 }
27140
27141 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27142 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27143 + return;
27144 +#endif
27145 +
27146 vma = find_vma(mm, address);
27147 if (unlikely(!vma)) {
27148 bad_area(regs, error_code, address);
27149 @@ -1157,18 +1371,24 @@ retry:
27150 bad_area(regs, error_code, address);
27151 return;
27152 }
27153 - if (error_code & PF_USER) {
27154 - /*
27155 - * Accessing the stack below %sp is always a bug.
27156 - * The large cushion allows instructions like enter
27157 - * and pusha to work. ("enter $65535, $31" pushes
27158 - * 32 pointers and then decrements %sp by 65535.)
27159 - */
27160 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27161 - bad_area(regs, error_code, address);
27162 - return;
27163 - }
27164 + /*
27165 + * Accessing the stack below %sp is always a bug.
27166 + * The large cushion allows instructions like enter
27167 + * and pusha to work. ("enter $65535, $31" pushes
27168 + * 32 pointers and then decrements %sp by 65535.)
27169 + */
27170 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27171 + bad_area(regs, error_code, address);
27172 + return;
27173 }
27174 +
27175 +#ifdef CONFIG_PAX_SEGMEXEC
27176 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27177 + bad_area(regs, error_code, address);
27178 + return;
27179 + }
27180 +#endif
27181 +
27182 if (unlikely(expand_stack(vma, address))) {
27183 bad_area(regs, error_code, address);
27184 return;
27185 @@ -1232,3 +1452,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27186 __do_page_fault(regs, error_code);
27187 exception_exit(regs);
27188 }
27189 +
27190 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27191 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27192 +{
27193 + struct mm_struct *mm = current->mm;
27194 + unsigned long ip = regs->ip;
27195 +
27196 + if (v8086_mode(regs))
27197 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27198 +
27199 +#ifdef CONFIG_PAX_PAGEEXEC
27200 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27201 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27202 + return true;
27203 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27204 + return true;
27205 + return false;
27206 + }
27207 +#endif
27208 +
27209 +#ifdef CONFIG_PAX_SEGMEXEC
27210 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27211 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27212 + return true;
27213 + return false;
27214 + }
27215 +#endif
27216 +
27217 + return false;
27218 +}
27219 +#endif
27220 +
27221 +#ifdef CONFIG_PAX_EMUTRAMP
27222 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27223 +{
27224 + int err;
27225 +
27226 + do { /* PaX: libffi trampoline emulation */
27227 + unsigned char mov, jmp;
27228 + unsigned int addr1, addr2;
27229 +
27230 +#ifdef CONFIG_X86_64
27231 + if ((regs->ip + 9) >> 32)
27232 + break;
27233 +#endif
27234 +
27235 + err = get_user(mov, (unsigned char __user *)regs->ip);
27236 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27237 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27238 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27239 +
27240 + if (err)
27241 + break;
27242 +
27243 + if (mov == 0xB8 && jmp == 0xE9) {
27244 + regs->ax = addr1;
27245 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27246 + return 2;
27247 + }
27248 + } while (0);
27249 +
27250 + do { /* PaX: gcc trampoline emulation #1 */
27251 + unsigned char mov1, mov2;
27252 + unsigned short jmp;
27253 + unsigned int addr1, addr2;
27254 +
27255 +#ifdef CONFIG_X86_64
27256 + if ((regs->ip + 11) >> 32)
27257 + break;
27258 +#endif
27259 +
27260 + err = get_user(mov1, (unsigned char __user *)regs->ip);
27261 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27262 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27263 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27264 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27265 +
27266 + if (err)
27267 + break;
27268 +
27269 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27270 + regs->cx = addr1;
27271 + regs->ax = addr2;
27272 + regs->ip = addr2;
27273 + return 2;
27274 + }
27275 + } while (0);
27276 +
27277 + do { /* PaX: gcc trampoline emulation #2 */
27278 + unsigned char mov, jmp;
27279 + unsigned int addr1, addr2;
27280 +
27281 +#ifdef CONFIG_X86_64
27282 + if ((regs->ip + 9) >> 32)
27283 + break;
27284 +#endif
27285 +
27286 + err = get_user(mov, (unsigned char __user *)regs->ip);
27287 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27288 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27289 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27290 +
27291 + if (err)
27292 + break;
27293 +
27294 + if (mov == 0xB9 && jmp == 0xE9) {
27295 + regs->cx = addr1;
27296 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27297 + return 2;
27298 + }
27299 + } while (0);
27300 +
27301 + return 1; /* PaX in action */
27302 +}
27303 +
27304 +#ifdef CONFIG_X86_64
27305 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27306 +{
27307 + int err;
27308 +
27309 + do { /* PaX: libffi trampoline emulation */
27310 + unsigned short mov1, mov2, jmp1;
27311 + unsigned char stcclc, jmp2;
27312 + unsigned long addr1, addr2;
27313 +
27314 + err = get_user(mov1, (unsigned short __user *)regs->ip);
27315 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27316 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27317 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27318 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27319 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27320 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27321 +
27322 + if (err)
27323 + break;
27324 +
27325 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27326 + regs->r11 = addr1;
27327 + regs->r10 = addr2;
27328 + if (stcclc == 0xF8)
27329 + regs->flags &= ~X86_EFLAGS_CF;
27330 + else
27331 + regs->flags |= X86_EFLAGS_CF;
27332 + regs->ip = addr1;
27333 + return 2;
27334 + }
27335 + } while (0);
27336 +
27337 + do { /* PaX: gcc trampoline emulation #1 */
27338 + unsigned short mov1, mov2, jmp1;
27339 + unsigned char jmp2;
27340 + unsigned int addr1;
27341 + unsigned long addr2;
27342 +
27343 + err = get_user(mov1, (unsigned short __user *)regs->ip);
27344 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27345 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27346 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27347 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27348 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27349 +
27350 + if (err)
27351 + break;
27352 +
27353 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27354 + regs->r11 = addr1;
27355 + regs->r10 = addr2;
27356 + regs->ip = addr1;
27357 + return 2;
27358 + }
27359 + } while (0);
27360 +
27361 + do { /* PaX: gcc trampoline emulation #2 */
27362 + unsigned short mov1, mov2, jmp1;
27363 + unsigned char jmp2;
27364 + unsigned long addr1, addr2;
27365 +
27366 + err = get_user(mov1, (unsigned short __user *)regs->ip);
27367 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27368 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27369 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27370 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27371 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27372 +
27373 + if (err)
27374 + break;
27375 +
27376 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27377 + regs->r11 = addr1;
27378 + regs->r10 = addr2;
27379 + regs->ip = addr1;
27380 + return 2;
27381 + }
27382 + } while (0);
27383 +
27384 + return 1; /* PaX in action */
27385 +}
27386 +#endif
27387 +
27388 +/*
27389 + * PaX: decide what to do with offenders (regs->ip = fault address)
27390 + *
27391 + * returns 1 when task should be killed
27392 + * 2 when gcc trampoline was detected
27393 + */
27394 +static int pax_handle_fetch_fault(struct pt_regs *regs)
27395 +{
27396 + if (v8086_mode(regs))
27397 + return 1;
27398 +
27399 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27400 + return 1;
27401 +
27402 +#ifdef CONFIG_X86_32
27403 + return pax_handle_fetch_fault_32(regs);
27404 +#else
27405 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27406 + return pax_handle_fetch_fault_32(regs);
27407 + else
27408 + return pax_handle_fetch_fault_64(regs);
27409 +#endif
27410 +}
27411 +#endif
27412 +
27413 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27414 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27415 +{
27416 + long i;
27417 +
27418 + printk(KERN_ERR "PAX: bytes at PC: ");
27419 + for (i = 0; i < 20; i++) {
27420 + unsigned char c;
27421 + if (get_user(c, (unsigned char __force_user *)pc+i))
27422 + printk(KERN_CONT "?? ");
27423 + else
27424 + printk(KERN_CONT "%02x ", c);
27425 + }
27426 + printk("\n");
27427 +
27428 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27429 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
27430 + unsigned long c;
27431 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
27432 +#ifdef CONFIG_X86_32
27433 + printk(KERN_CONT "???????? ");
27434 +#else
27435 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27436 + printk(KERN_CONT "???????? ???????? ");
27437 + else
27438 + printk(KERN_CONT "???????????????? ");
27439 +#endif
27440 + } else {
27441 +#ifdef CONFIG_X86_64
27442 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27443 + printk(KERN_CONT "%08x ", (unsigned int)c);
27444 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27445 + } else
27446 +#endif
27447 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27448 + }
27449 + }
27450 + printk("\n");
27451 +}
27452 +#endif
27453 +
27454 +/**
27455 + * probe_kernel_write(): safely attempt to write to a location
27456 + * @dst: address to write to
27457 + * @src: pointer to the data that shall be written
27458 + * @size: size of the data chunk
27459 + *
27460 + * Safely write to address @dst from the buffer at @src. If a kernel fault
27461 + * happens, handle that and return -EFAULT.
27462 + */
27463 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27464 +{
27465 + long ret;
27466 + mm_segment_t old_fs = get_fs();
27467 +
27468 + set_fs(KERNEL_DS);
27469 + pagefault_disable();
27470 + pax_open_kernel();
27471 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27472 + pax_close_kernel();
27473 + pagefault_enable();
27474 + set_fs(old_fs);
27475 +
27476 + return ret ? -EFAULT : 0;
27477 +}
27478 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27479 index dd74e46..7d26398 100644
27480 --- a/arch/x86/mm/gup.c
27481 +++ b/arch/x86/mm/gup.c
27482 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27483 addr = start;
27484 len = (unsigned long) nr_pages << PAGE_SHIFT;
27485 end = start + len;
27486 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27487 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27488 (void __user *)start, len)))
27489 return 0;
27490
27491 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27492 index 6f31ee5..8ee4164 100644
27493 --- a/arch/x86/mm/highmem_32.c
27494 +++ b/arch/x86/mm/highmem_32.c
27495 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27496 idx = type + KM_TYPE_NR*smp_processor_id();
27497 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27498 BUG_ON(!pte_none(*(kmap_pte-idx)));
27499 +
27500 + pax_open_kernel();
27501 set_pte(kmap_pte-idx, mk_pte(page, prot));
27502 + pax_close_kernel();
27503 +
27504 arch_flush_lazy_mmu_mode();
27505
27506 return (void *)vaddr;
27507 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27508 index ae1aa71..56316db 100644
27509 --- a/arch/x86/mm/hugetlbpage.c
27510 +++ b/arch/x86/mm/hugetlbpage.c
27511 @@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27512 info.flags = 0;
27513 info.length = len;
27514 info.low_limit = TASK_UNMAPPED_BASE;
27515 +
27516 +#ifdef CONFIG_PAX_RANDMMAP
27517 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27518 + info.low_limit += current->mm->delta_mmap;
27519 +#endif
27520 +
27521 info.high_limit = TASK_SIZE;
27522 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
27523 info.align_offset = 0;
27524 @@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
27525 VM_BUG_ON(addr != -ENOMEM);
27526 info.flags = 0;
27527 info.low_limit = TASK_UNMAPPED_BASE;
27528 +
27529 +#ifdef CONFIG_PAX_RANDMMAP
27530 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27531 + info.low_limit += current->mm->delta_mmap;
27532 +#endif
27533 +
27534 info.high_limit = TASK_SIZE;
27535 addr = vm_unmapped_area(&info);
27536 }
27537 @@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27538 struct hstate *h = hstate_file(file);
27539 struct mm_struct *mm = current->mm;
27540 struct vm_area_struct *vma;
27541 + unsigned long pax_task_size = TASK_SIZE;
27542 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
27543
27544 if (len & ~huge_page_mask(h))
27545 return -EINVAL;
27546 - if (len > TASK_SIZE)
27547 +
27548 +#ifdef CONFIG_PAX_SEGMEXEC
27549 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27550 + pax_task_size = SEGMEXEC_TASK_SIZE;
27551 +#endif
27552 +
27553 + pax_task_size -= PAGE_SIZE;
27554 +
27555 + if (len > pax_task_size)
27556 return -ENOMEM;
27557
27558 if (flags & MAP_FIXED) {
27559 @@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27560 return addr;
27561 }
27562
27563 +#ifdef CONFIG_PAX_RANDMMAP
27564 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27565 +#endif
27566 +
27567 if (addr) {
27568 addr = ALIGN(addr, huge_page_size(h));
27569 vma = find_vma(mm, addr);
27570 - if (TASK_SIZE - len >= addr &&
27571 - (!vma || addr + len <= vma->vm_start))
27572 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27573 return addr;
27574 }
27575 if (mm->get_unmapped_area == arch_get_unmapped_area)
27576 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
27577 index d7aea41..0fc945b 100644
27578 --- a/arch/x86/mm/init.c
27579 +++ b/arch/x86/mm/init.c
27580 @@ -4,6 +4,7 @@
27581 #include <linux/swap.h>
27582 #include <linux/memblock.h>
27583 #include <linux/bootmem.h> /* for max_low_pfn */
27584 +#include <linux/tboot.h>
27585
27586 #include <asm/cacheflush.h>
27587 #include <asm/e820.h>
27588 @@ -16,6 +17,8 @@
27589 #include <asm/tlb.h>
27590 #include <asm/proto.h>
27591 #include <asm/dma.h> /* for MAX_DMA_PFN */
27592 +#include <asm/desc.h>
27593 +#include <asm/bios_ebda.h>
27594
27595 unsigned long __initdata pgt_buf_start;
27596 unsigned long __meminitdata pgt_buf_end;
27597 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
27598 {
27599 int i;
27600 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
27601 - unsigned long start = 0, good_end;
27602 + unsigned long start = 0x100000, good_end;
27603 phys_addr_t base;
27604
27605 for (i = 0; i < nr_range; i++) {
27606 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
27607 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
27608 * mmio resources as well as potential bios/acpi data regions.
27609 */
27610 +
27611 +#ifdef CONFIG_GRKERNSEC_KMEM
27612 +static unsigned int ebda_start __read_only;
27613 +static unsigned int ebda_end __read_only;
27614 +#endif
27615 +
27616 int devmem_is_allowed(unsigned long pagenr)
27617 {
27618 - if (pagenr < 256)
27619 +#ifdef CONFIG_GRKERNSEC_KMEM
27620 + /* allow BDA */
27621 + if (!pagenr)
27622 return 1;
27623 + /* allow EBDA */
27624 + if (pagenr >= ebda_start && pagenr < ebda_end)
27625 + return 1;
27626 + /* if tboot is in use, allow access to its hardcoded serial log range */
27627 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
27628 + return 1;
27629 +#else
27630 + if (!pagenr)
27631 + return 1;
27632 +#ifdef CONFIG_VM86
27633 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
27634 + return 1;
27635 +#endif
27636 +#endif
27637 +
27638 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
27639 + return 1;
27640 +#ifdef CONFIG_GRKERNSEC_KMEM
27641 + /* throw out everything else below 1MB */
27642 + if (pagenr <= 256)
27643 + return 0;
27644 +#endif
27645 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
27646 return 0;
27647 if (!page_is_ram(pagenr))
27648 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
27649 #endif
27650 }
27651
27652 +#ifdef CONFIG_GRKERNSEC_KMEM
27653 +static inline void gr_init_ebda(void)
27654 +{
27655 + unsigned int ebda_addr;
27656 + unsigned int ebda_size = 0;
27657 +
27658 + ebda_addr = get_bios_ebda();
27659 + if (ebda_addr) {
27660 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
27661 + ebda_size <<= 10;
27662 + }
27663 + if (ebda_addr && ebda_size) {
27664 + ebda_start = ebda_addr >> PAGE_SHIFT;
27665 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
27666 + } else {
27667 + ebda_start = 0x9f000 >> PAGE_SHIFT;
27668 + ebda_end = 0xa0000 >> PAGE_SHIFT;
27669 + }
27670 +}
27671 +#else
27672 +static inline void gr_init_ebda(void) { }
27673 +#endif
27674 +
27675 void free_initmem(void)
27676 {
27677 +#ifdef CONFIG_PAX_KERNEXEC
27678 +#ifdef CONFIG_X86_32
27679 + /* PaX: limit KERNEL_CS to actual size */
27680 + unsigned long addr, limit;
27681 + struct desc_struct d;
27682 + int cpu;
27683 +#else
27684 + pgd_t *pgd;
27685 + pud_t *pud;
27686 + pmd_t *pmd;
27687 + unsigned long addr, end;
27688 +#endif
27689 +#endif
27690 +
27691 + gr_init_ebda();
27692 +
27693 +#ifdef CONFIG_PAX_KERNEXEC
27694 +#ifdef CONFIG_X86_32
27695 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
27696 + limit = (limit - 1UL) >> PAGE_SHIFT;
27697 +
27698 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
27699 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27700 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
27701 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
27702 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
27703 + }
27704 +
27705 + /* PaX: make KERNEL_CS read-only */
27706 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
27707 + if (!paravirt_enabled())
27708 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
27709 +/*
27710 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
27711 + pgd = pgd_offset_k(addr);
27712 + pud = pud_offset(pgd, addr);
27713 + pmd = pmd_offset(pud, addr);
27714 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27715 + }
27716 +*/
27717 +#ifdef CONFIG_X86_PAE
27718 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
27719 +/*
27720 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
27721 + pgd = pgd_offset_k(addr);
27722 + pud = pud_offset(pgd, addr);
27723 + pmd = pmd_offset(pud, addr);
27724 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27725 + }
27726 +*/
27727 +#endif
27728 +
27729 +#ifdef CONFIG_MODULES
27730 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
27731 +#endif
27732 +
27733 +#else
27734 + /* PaX: make kernel code/rodata read-only, rest non-executable */
27735 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
27736 + pgd = pgd_offset_k(addr);
27737 + pud = pud_offset(pgd, addr);
27738 + pmd = pmd_offset(pud, addr);
27739 + if (!pmd_present(*pmd))
27740 + continue;
27741 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
27742 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27743 + else
27744 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27745 + }
27746 +
27747 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
27748 + end = addr + KERNEL_IMAGE_SIZE;
27749 + for (; addr < end; addr += PMD_SIZE) {
27750 + pgd = pgd_offset_k(addr);
27751 + pud = pud_offset(pgd, addr);
27752 + pmd = pmd_offset(pud, addr);
27753 + if (!pmd_present(*pmd))
27754 + continue;
27755 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
27756 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27757 + }
27758 +#endif
27759 +
27760 + flush_tlb_all();
27761 +#endif
27762 +
27763 free_init_pages("unused kernel memory",
27764 (unsigned long)(&__init_begin),
27765 (unsigned long)(&__init_end));
27766 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
27767 index 745d66b..56bf568 100644
27768 --- a/arch/x86/mm/init_32.c
27769 +++ b/arch/x86/mm/init_32.c
27770 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
27771 }
27772
27773 /*
27774 - * Creates a middle page table and puts a pointer to it in the
27775 - * given global directory entry. This only returns the gd entry
27776 - * in non-PAE compilation mode, since the middle layer is folded.
27777 - */
27778 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
27779 -{
27780 - pud_t *pud;
27781 - pmd_t *pmd_table;
27782 -
27783 -#ifdef CONFIG_X86_PAE
27784 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
27785 - if (after_bootmem)
27786 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
27787 - else
27788 - pmd_table = (pmd_t *)alloc_low_page();
27789 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
27790 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
27791 - pud = pud_offset(pgd, 0);
27792 - BUG_ON(pmd_table != pmd_offset(pud, 0));
27793 -
27794 - return pmd_table;
27795 - }
27796 -#endif
27797 - pud = pud_offset(pgd, 0);
27798 - pmd_table = pmd_offset(pud, 0);
27799 -
27800 - return pmd_table;
27801 -}
27802 -
27803 -/*
27804 * Create a page table and place a pointer to it in a middle page
27805 * directory entry:
27806 */
27807 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
27808 page_table = (pte_t *)alloc_low_page();
27809
27810 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
27811 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27812 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
27813 +#else
27814 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
27815 +#endif
27816 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
27817 }
27818
27819 return pte_offset_kernel(pmd, 0);
27820 }
27821
27822 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
27823 +{
27824 + pud_t *pud;
27825 + pmd_t *pmd_table;
27826 +
27827 + pud = pud_offset(pgd, 0);
27828 + pmd_table = pmd_offset(pud, 0);
27829 +
27830 + return pmd_table;
27831 +}
27832 +
27833 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
27834 {
27835 int pgd_idx = pgd_index(vaddr);
27836 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27837 int pgd_idx, pmd_idx;
27838 unsigned long vaddr;
27839 pgd_t *pgd;
27840 + pud_t *pud;
27841 pmd_t *pmd;
27842 pte_t *pte = NULL;
27843
27844 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27845 pgd = pgd_base + pgd_idx;
27846
27847 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
27848 - pmd = one_md_table_init(pgd);
27849 - pmd = pmd + pmd_index(vaddr);
27850 + pud = pud_offset(pgd, vaddr);
27851 + pmd = pmd_offset(pud, vaddr);
27852 +
27853 +#ifdef CONFIG_X86_PAE
27854 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27855 +#endif
27856 +
27857 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
27858 pmd++, pmd_idx++) {
27859 pte = page_table_kmap_check(one_page_table_init(pmd),
27860 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27861 }
27862 }
27863
27864 -static inline int is_kernel_text(unsigned long addr)
27865 +static inline int is_kernel_text(unsigned long start, unsigned long end)
27866 {
27867 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
27868 - return 1;
27869 - return 0;
27870 + if ((start > ktla_ktva((unsigned long)_etext) ||
27871 + end <= ktla_ktva((unsigned long)_stext)) &&
27872 + (start > ktla_ktva((unsigned long)_einittext) ||
27873 + end <= ktla_ktva((unsigned long)_sinittext)) &&
27874 +
27875 +#ifdef CONFIG_ACPI_SLEEP
27876 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
27877 +#endif
27878 +
27879 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
27880 + return 0;
27881 + return 1;
27882 }
27883
27884 /*
27885 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
27886 unsigned long last_map_addr = end;
27887 unsigned long start_pfn, end_pfn;
27888 pgd_t *pgd_base = swapper_pg_dir;
27889 - int pgd_idx, pmd_idx, pte_ofs;
27890 + unsigned int pgd_idx, pmd_idx, pte_ofs;
27891 unsigned long pfn;
27892 pgd_t *pgd;
27893 + pud_t *pud;
27894 pmd_t *pmd;
27895 pte_t *pte;
27896 unsigned pages_2m, pages_4k;
27897 @@ -280,8 +281,13 @@ repeat:
27898 pfn = start_pfn;
27899 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27900 pgd = pgd_base + pgd_idx;
27901 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
27902 - pmd = one_md_table_init(pgd);
27903 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
27904 + pud = pud_offset(pgd, 0);
27905 + pmd = pmd_offset(pud, 0);
27906 +
27907 +#ifdef CONFIG_X86_PAE
27908 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27909 +#endif
27910
27911 if (pfn >= end_pfn)
27912 continue;
27913 @@ -293,14 +299,13 @@ repeat:
27914 #endif
27915 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
27916 pmd++, pmd_idx++) {
27917 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
27918 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
27919
27920 /*
27921 * Map with big pages if possible, otherwise
27922 * create normal page tables:
27923 */
27924 if (use_pse) {
27925 - unsigned int addr2;
27926 pgprot_t prot = PAGE_KERNEL_LARGE;
27927 /*
27928 * first pass will use the same initial
27929 @@ -310,11 +315,7 @@ repeat:
27930 __pgprot(PTE_IDENT_ATTR |
27931 _PAGE_PSE);
27932
27933 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
27934 - PAGE_OFFSET + PAGE_SIZE-1;
27935 -
27936 - if (is_kernel_text(addr) ||
27937 - is_kernel_text(addr2))
27938 + if (is_kernel_text(address, address + PMD_SIZE))
27939 prot = PAGE_KERNEL_LARGE_EXEC;
27940
27941 pages_2m++;
27942 @@ -331,7 +332,7 @@ repeat:
27943 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27944 pte += pte_ofs;
27945 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
27946 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
27947 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
27948 pgprot_t prot = PAGE_KERNEL;
27949 /*
27950 * first pass will use the same initial
27951 @@ -339,7 +340,7 @@ repeat:
27952 */
27953 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
27954
27955 - if (is_kernel_text(addr))
27956 + if (is_kernel_text(address, address + PAGE_SIZE))
27957 prot = PAGE_KERNEL_EXEC;
27958
27959 pages_4k++;
27960 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
27961
27962 pud = pud_offset(pgd, va);
27963 pmd = pmd_offset(pud, va);
27964 - if (!pmd_present(*pmd))
27965 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
27966 break;
27967
27968 pte = pte_offset_kernel(pmd, va);
27969 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
27970
27971 static void __init pagetable_init(void)
27972 {
27973 - pgd_t *pgd_base = swapper_pg_dir;
27974 -
27975 - permanent_kmaps_init(pgd_base);
27976 + permanent_kmaps_init(swapper_pg_dir);
27977 }
27978
27979 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27980 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27981 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27982
27983 /* user-defined highmem size */
27984 @@ -728,6 +727,12 @@ void __init mem_init(void)
27985
27986 pci_iommu_alloc();
27987
27988 +#ifdef CONFIG_PAX_PER_CPU_PGD
27989 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
27990 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27991 + KERNEL_PGD_PTRS);
27992 +#endif
27993 +
27994 #ifdef CONFIG_FLATMEM
27995 BUG_ON(!mem_map);
27996 #endif
27997 @@ -754,7 +759,7 @@ void __init mem_init(void)
27998 reservedpages++;
27999
28000 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28001 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28002 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28003 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28004
28005 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28006 @@ -795,10 +800,10 @@ void __init mem_init(void)
28007 ((unsigned long)&__init_end -
28008 (unsigned long)&__init_begin) >> 10,
28009
28010 - (unsigned long)&_etext, (unsigned long)&_edata,
28011 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28012 + (unsigned long)&_sdata, (unsigned long)&_edata,
28013 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28014
28015 - (unsigned long)&_text, (unsigned long)&_etext,
28016 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28017 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28018
28019 /*
28020 @@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
28021 if (!kernel_set_to_readonly)
28022 return;
28023
28024 + start = ktla_ktva(start);
28025 pr_debug("Set kernel text: %lx - %lx for read write\n",
28026 start, start+size);
28027
28028 @@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
28029 if (!kernel_set_to_readonly)
28030 return;
28031
28032 + start = ktla_ktva(start);
28033 pr_debug("Set kernel text: %lx - %lx for read only\n",
28034 start, start+size);
28035
28036 @@ -918,6 +925,7 @@ void mark_rodata_ro(void)
28037 unsigned long start = PFN_ALIGN(_text);
28038 unsigned long size = PFN_ALIGN(_etext) - start;
28039
28040 + start = ktla_ktva(start);
28041 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28042 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28043 size >> 10);
28044 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28045 index 75c9a6a..498d677 100644
28046 --- a/arch/x86/mm/init_64.c
28047 +++ b/arch/x86/mm/init_64.c
28048 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28049 * around without checking the pgd every time.
28050 */
28051
28052 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28053 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28054 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28055
28056 int force_personality32;
28057 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28058
28059 for (address = start; address <= end; address += PGDIR_SIZE) {
28060 const pgd_t *pgd_ref = pgd_offset_k(address);
28061 +
28062 +#ifdef CONFIG_PAX_PER_CPU_PGD
28063 + unsigned long cpu;
28064 +#else
28065 struct page *page;
28066 +#endif
28067
28068 if (pgd_none(*pgd_ref))
28069 continue;
28070
28071 spin_lock(&pgd_lock);
28072 +
28073 +#ifdef CONFIG_PAX_PER_CPU_PGD
28074 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28075 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
28076 +#else
28077 list_for_each_entry(page, &pgd_list, lru) {
28078 pgd_t *pgd;
28079 spinlock_t *pgt_lock;
28080 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28081 /* the pgt_lock only for Xen */
28082 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28083 spin_lock(pgt_lock);
28084 +#endif
28085
28086 if (pgd_none(*pgd))
28087 set_pgd(pgd, *pgd_ref);
28088 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28089 BUG_ON(pgd_page_vaddr(*pgd)
28090 != pgd_page_vaddr(*pgd_ref));
28091
28092 +#ifndef CONFIG_PAX_PER_CPU_PGD
28093 spin_unlock(pgt_lock);
28094 +#endif
28095 +
28096 }
28097 spin_unlock(&pgd_lock);
28098 }
28099 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28100 {
28101 if (pgd_none(*pgd)) {
28102 pud_t *pud = (pud_t *)spp_getpage();
28103 - pgd_populate(&init_mm, pgd, pud);
28104 + pgd_populate_kernel(&init_mm, pgd, pud);
28105 if (pud != pud_offset(pgd, 0))
28106 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28107 pud, pud_offset(pgd, 0));
28108 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28109 {
28110 if (pud_none(*pud)) {
28111 pmd_t *pmd = (pmd_t *) spp_getpage();
28112 - pud_populate(&init_mm, pud, pmd);
28113 + pud_populate_kernel(&init_mm, pud, pmd);
28114 if (pmd != pmd_offset(pud, 0))
28115 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28116 pmd, pmd_offset(pud, 0));
28117 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28118 pmd = fill_pmd(pud, vaddr);
28119 pte = fill_pte(pmd, vaddr);
28120
28121 + pax_open_kernel();
28122 set_pte(pte, new_pte);
28123 + pax_close_kernel();
28124
28125 /*
28126 * It's enough to flush this one mapping.
28127 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28128 pgd = pgd_offset_k((unsigned long)__va(phys));
28129 if (pgd_none(*pgd)) {
28130 pud = (pud_t *) spp_getpage();
28131 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28132 - _PAGE_USER));
28133 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28134 }
28135 pud = pud_offset(pgd, (unsigned long)__va(phys));
28136 if (pud_none(*pud)) {
28137 pmd = (pmd_t *) spp_getpage();
28138 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28139 - _PAGE_USER));
28140 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28141 }
28142 pmd = pmd_offset(pud, phys);
28143 BUG_ON(!pmd_none(*pmd));
28144 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
28145 if (pfn >= pgt_buf_top)
28146 panic("alloc_low_page: ran out of memory");
28147
28148 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28149 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28150 clear_page(adr);
28151 *phys = pfn * PAGE_SIZE;
28152 return adr;
28153 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
28154
28155 phys = __pa(virt);
28156 left = phys & (PAGE_SIZE - 1);
28157 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28158 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28159 adr = (void *)(((unsigned long)adr) | left);
28160
28161 return adr;
28162 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28163 unmap_low_page(pmd);
28164
28165 spin_lock(&init_mm.page_table_lock);
28166 - pud_populate(&init_mm, pud, __va(pmd_phys));
28167 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
28168 spin_unlock(&init_mm.page_table_lock);
28169 }
28170 __flush_tlb_all();
28171 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
28172 unmap_low_page(pud);
28173
28174 spin_lock(&init_mm.page_table_lock);
28175 - pgd_populate(&init_mm, pgd, __va(pud_phys));
28176 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
28177 spin_unlock(&init_mm.page_table_lock);
28178 pgd_changed = true;
28179 }
28180 @@ -693,6 +707,12 @@ void __init mem_init(void)
28181
28182 pci_iommu_alloc();
28183
28184 +#ifdef CONFIG_PAX_PER_CPU_PGD
28185 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28186 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28187 + KERNEL_PGD_PTRS);
28188 +#endif
28189 +
28190 /* clear_bss() already clear the empty_zero_page */
28191
28192 reservedpages = 0;
28193 @@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
28194 static struct vm_area_struct gate_vma = {
28195 .vm_start = VSYSCALL_START,
28196 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28197 - .vm_page_prot = PAGE_READONLY_EXEC,
28198 - .vm_flags = VM_READ | VM_EXEC
28199 + .vm_page_prot = PAGE_READONLY,
28200 + .vm_flags = VM_READ
28201 };
28202
28203 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28204 @@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
28205
28206 const char *arch_vma_name(struct vm_area_struct *vma)
28207 {
28208 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28209 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28210 return "[vdso]";
28211 if (vma == &gate_vma)
28212 return "[vsyscall]";
28213 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28214 index 7b179b4..6bd1777 100644
28215 --- a/arch/x86/mm/iomap_32.c
28216 +++ b/arch/x86/mm/iomap_32.c
28217 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28218 type = kmap_atomic_idx_push();
28219 idx = type + KM_TYPE_NR * smp_processor_id();
28220 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28221 +
28222 + pax_open_kernel();
28223 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28224 + pax_close_kernel();
28225 +
28226 arch_flush_lazy_mmu_mode();
28227
28228 return (void *)vaddr;
28229 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28230 index 78fe3f1..2f9433c 100644
28231 --- a/arch/x86/mm/ioremap.c
28232 +++ b/arch/x86/mm/ioremap.c
28233 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28234 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28235 int is_ram = page_is_ram(pfn);
28236
28237 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28238 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28239 return NULL;
28240 WARN_ON_ONCE(is_ram);
28241 }
28242 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28243 *
28244 * Caller must ensure there is only one unmapping for the same pointer.
28245 */
28246 -void iounmap(volatile void __iomem *addr)
28247 +void iounmap(const volatile void __iomem *addr)
28248 {
28249 struct vm_struct *p, *o;
28250
28251 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28252
28253 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28254 if (page_is_ram(start >> PAGE_SHIFT))
28255 +#ifdef CONFIG_HIGHMEM
28256 + if ((start >> PAGE_SHIFT) < max_low_pfn)
28257 +#endif
28258 return __va(phys);
28259
28260 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28261 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
28262 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28263
28264 static __initdata int after_paging_init;
28265 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28266 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28267
28268 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28269 {
28270 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
28271 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28272
28273 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28274 - memset(bm_pte, 0, sizeof(bm_pte));
28275 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
28276 + pmd_populate_user(&init_mm, pmd, bm_pte);
28277
28278 /*
28279 * The boot-ioremap range spans multiple pmds, for which
28280 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28281 index d87dd6d..bf3fa66 100644
28282 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
28283 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28284 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28285 * memory (e.g. tracked pages)? For now, we need this to avoid
28286 * invoking kmemcheck for PnP BIOS calls.
28287 */
28288 - if (regs->flags & X86_VM_MASK)
28289 + if (v8086_mode(regs))
28290 return false;
28291 - if (regs->cs != __KERNEL_CS)
28292 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28293 return false;
28294
28295 pte = kmemcheck_pte_lookup(address);
28296 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28297 index 845df68..1d8d29f 100644
28298 --- a/arch/x86/mm/mmap.c
28299 +++ b/arch/x86/mm/mmap.c
28300 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28301 * Leave an at least ~128 MB hole with possible stack randomization.
28302 */
28303 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28304 -#define MAX_GAP (TASK_SIZE/6*5)
28305 +#define MAX_GAP (pax_task_size/6*5)
28306
28307 static int mmap_is_legacy(void)
28308 {
28309 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28310 return rnd << PAGE_SHIFT;
28311 }
28312
28313 -static unsigned long mmap_base(void)
28314 +static unsigned long mmap_base(struct mm_struct *mm)
28315 {
28316 unsigned long gap = rlimit(RLIMIT_STACK);
28317 + unsigned long pax_task_size = TASK_SIZE;
28318 +
28319 +#ifdef CONFIG_PAX_SEGMEXEC
28320 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
28321 + pax_task_size = SEGMEXEC_TASK_SIZE;
28322 +#endif
28323
28324 if (gap < MIN_GAP)
28325 gap = MIN_GAP;
28326 else if (gap > MAX_GAP)
28327 gap = MAX_GAP;
28328
28329 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28330 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28331 }
28332
28333 /*
28334 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28335 * does, but not when emulating X86_32
28336 */
28337 -static unsigned long mmap_legacy_base(void)
28338 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
28339 {
28340 - if (mmap_is_ia32())
28341 + if (mmap_is_ia32()) {
28342 +
28343 +#ifdef CONFIG_PAX_SEGMEXEC
28344 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
28345 + return SEGMEXEC_TASK_UNMAPPED_BASE;
28346 + else
28347 +#endif
28348 +
28349 return TASK_UNMAPPED_BASE;
28350 - else
28351 + } else
28352 return TASK_UNMAPPED_BASE + mmap_rnd();
28353 }
28354
28355 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28356 void arch_pick_mmap_layout(struct mm_struct *mm)
28357 {
28358 if (mmap_is_legacy()) {
28359 - mm->mmap_base = mmap_legacy_base();
28360 + mm->mmap_base = mmap_legacy_base(mm);
28361 +
28362 +#ifdef CONFIG_PAX_RANDMMAP
28363 + if (mm->pax_flags & MF_PAX_RANDMMAP)
28364 + mm->mmap_base += mm->delta_mmap;
28365 +#endif
28366 +
28367 mm->get_unmapped_area = arch_get_unmapped_area;
28368 mm->unmap_area = arch_unmap_area;
28369 } else {
28370 - mm->mmap_base = mmap_base();
28371 + mm->mmap_base = mmap_base(mm);
28372 +
28373 +#ifdef CONFIG_PAX_RANDMMAP
28374 + if (mm->pax_flags & MF_PAX_RANDMMAP)
28375 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28376 +#endif
28377 +
28378 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28379 mm->unmap_area = arch_unmap_area_topdown;
28380 }
28381 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28382 index dc0b727..f612039 100644
28383 --- a/arch/x86/mm/mmio-mod.c
28384 +++ b/arch/x86/mm/mmio-mod.c
28385 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28386 break;
28387 default:
28388 {
28389 - unsigned char *ip = (unsigned char *)instptr;
28390 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28391 my_trace->opcode = MMIO_UNKNOWN_OP;
28392 my_trace->width = 0;
28393 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28394 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28395 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28396 void __iomem *addr)
28397 {
28398 - static atomic_t next_id;
28399 + static atomic_unchecked_t next_id;
28400 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28401 /* These are page-unaligned. */
28402 struct mmiotrace_map map = {
28403 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28404 .private = trace
28405 },
28406 .phys = offset,
28407 - .id = atomic_inc_return(&next_id)
28408 + .id = atomic_inc_return_unchecked(&next_id)
28409 };
28410 map.map_id = trace->id;
28411
28412 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28413 ioremap_trace_core(offset, size, addr);
28414 }
28415
28416 -static void iounmap_trace_core(volatile void __iomem *addr)
28417 +static void iounmap_trace_core(const volatile void __iomem *addr)
28418 {
28419 struct mmiotrace_map map = {
28420 .phys = 0,
28421 @@ -328,7 +328,7 @@ not_enabled:
28422 }
28423 }
28424
28425 -void mmiotrace_iounmap(volatile void __iomem *addr)
28426 +void mmiotrace_iounmap(const volatile void __iomem *addr)
28427 {
28428 might_sleep();
28429 if (is_enabled()) /* recheck and proper locking in *_core() */
28430 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28431 index b008656..773eac2 100644
28432 --- a/arch/x86/mm/pageattr-test.c
28433 +++ b/arch/x86/mm/pageattr-test.c
28434 @@ -36,7 +36,7 @@ enum {
28435
28436 static int pte_testbit(pte_t pte)
28437 {
28438 - return pte_flags(pte) & _PAGE_UNUSED1;
28439 + return pte_flags(pte) & _PAGE_CPA_TEST;
28440 }
28441
28442 struct split_state {
28443 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28444 index a718e0d..77419bc 100644
28445 --- a/arch/x86/mm/pageattr.c
28446 +++ b/arch/x86/mm/pageattr.c
28447 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28448 */
28449 #ifdef CONFIG_PCI_BIOS
28450 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28451 - pgprot_val(forbidden) |= _PAGE_NX;
28452 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28453 #endif
28454
28455 /*
28456 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28457 * Does not cover __inittext since that is gone later on. On
28458 * 64bit we do not enforce !NX on the low mapping
28459 */
28460 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
28461 - pgprot_val(forbidden) |= _PAGE_NX;
28462 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28463 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28464
28465 +#ifdef CONFIG_DEBUG_RODATA
28466 /*
28467 * The .rodata section needs to be read-only. Using the pfn
28468 * catches all aliases.
28469 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28470 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
28471 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
28472 pgprot_val(forbidden) |= _PAGE_RW;
28473 +#endif
28474
28475 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28476 /*
28477 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28478 }
28479 #endif
28480
28481 +#ifdef CONFIG_PAX_KERNEXEC
28482 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28483 + pgprot_val(forbidden) |= _PAGE_RW;
28484 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28485 + }
28486 +#endif
28487 +
28488 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28489
28490 return prot;
28491 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
28492 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28493 {
28494 /* change init_mm */
28495 + pax_open_kernel();
28496 set_pte_atomic(kpte, pte);
28497 +
28498 #ifdef CONFIG_X86_32
28499 if (!SHARED_KERNEL_PMD) {
28500 +
28501 +#ifdef CONFIG_PAX_PER_CPU_PGD
28502 + unsigned long cpu;
28503 +#else
28504 struct page *page;
28505 +#endif
28506
28507 +#ifdef CONFIG_PAX_PER_CPU_PGD
28508 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28509 + pgd_t *pgd = get_cpu_pgd(cpu);
28510 +#else
28511 list_for_each_entry(page, &pgd_list, lru) {
28512 - pgd_t *pgd;
28513 + pgd_t *pgd = (pgd_t *)page_address(page);
28514 +#endif
28515 +
28516 pud_t *pud;
28517 pmd_t *pmd;
28518
28519 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
28520 + pgd += pgd_index(address);
28521 pud = pud_offset(pgd, address);
28522 pmd = pmd_offset(pud, address);
28523 set_pte_atomic((pte_t *)pmd, pte);
28524 }
28525 }
28526 #endif
28527 + pax_close_kernel();
28528 }
28529
28530 static int
28531 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
28532 index 0eb572e..92f5c1e 100644
28533 --- a/arch/x86/mm/pat.c
28534 +++ b/arch/x86/mm/pat.c
28535 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
28536
28537 if (!entry) {
28538 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
28539 - current->comm, current->pid, start, end - 1);
28540 + current->comm, task_pid_nr(current), start, end - 1);
28541 return -EINVAL;
28542 }
28543
28544 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28545
28546 while (cursor < to) {
28547 if (!devmem_is_allowed(pfn)) {
28548 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
28549 - current->comm, from, to - 1);
28550 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
28551 + current->comm, from, to - 1, cursor);
28552 return 0;
28553 }
28554 cursor += PAGE_SIZE;
28555 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
28556 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
28557 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
28558 "for [mem %#010Lx-%#010Lx]\n",
28559 - current->comm, current->pid,
28560 + current->comm, task_pid_nr(current),
28561 cattr_name(flags),
28562 base, (unsigned long long)(base + size-1));
28563 return -EINVAL;
28564 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28565 flags = lookup_memtype(paddr);
28566 if (want_flags != flags) {
28567 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
28568 - current->comm, current->pid,
28569 + current->comm, task_pid_nr(current),
28570 cattr_name(want_flags),
28571 (unsigned long long)paddr,
28572 (unsigned long long)(paddr + size - 1),
28573 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28574 free_memtype(paddr, paddr + size);
28575 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
28576 " for [mem %#010Lx-%#010Lx], got %s\n",
28577 - current->comm, current->pid,
28578 + current->comm, task_pid_nr(current),
28579 cattr_name(want_flags),
28580 (unsigned long long)paddr,
28581 (unsigned long long)(paddr + size - 1),
28582 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
28583 index 9f0614d..92ae64a 100644
28584 --- a/arch/x86/mm/pf_in.c
28585 +++ b/arch/x86/mm/pf_in.c
28586 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
28587 int i;
28588 enum reason_type rv = OTHERS;
28589
28590 - p = (unsigned char *)ins_addr;
28591 + p = (unsigned char *)ktla_ktva(ins_addr);
28592 p += skip_prefix(p, &prf);
28593 p += get_opcode(p, &opcode);
28594
28595 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
28596 struct prefix_bits prf;
28597 int i;
28598
28599 - p = (unsigned char *)ins_addr;
28600 + p = (unsigned char *)ktla_ktva(ins_addr);
28601 p += skip_prefix(p, &prf);
28602 p += get_opcode(p, &opcode);
28603
28604 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
28605 struct prefix_bits prf;
28606 int i;
28607
28608 - p = (unsigned char *)ins_addr;
28609 + p = (unsigned char *)ktla_ktva(ins_addr);
28610 p += skip_prefix(p, &prf);
28611 p += get_opcode(p, &opcode);
28612
28613 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
28614 struct prefix_bits prf;
28615 int i;
28616
28617 - p = (unsigned char *)ins_addr;
28618 + p = (unsigned char *)ktla_ktva(ins_addr);
28619 p += skip_prefix(p, &prf);
28620 p += get_opcode(p, &opcode);
28621 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
28622 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
28623 struct prefix_bits prf;
28624 int i;
28625
28626 - p = (unsigned char *)ins_addr;
28627 + p = (unsigned char *)ktla_ktva(ins_addr);
28628 p += skip_prefix(p, &prf);
28629 p += get_opcode(p, &opcode);
28630 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
28631 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
28632 index e27fbf8..8b56dc9 100644
28633 --- a/arch/x86/mm/pgtable.c
28634 +++ b/arch/x86/mm/pgtable.c
28635 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
28636 list_del(&page->lru);
28637 }
28638
28639 -#define UNSHARED_PTRS_PER_PGD \
28640 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28641 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28642 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
28643
28644 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
28645 +{
28646 + unsigned int count = USER_PGD_PTRS;
28647
28648 + while (count--)
28649 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
28650 +}
28651 +#endif
28652 +
28653 +#ifdef CONFIG_PAX_PER_CPU_PGD
28654 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
28655 +{
28656 + unsigned int count = USER_PGD_PTRS;
28657 +
28658 + while (count--) {
28659 + pgd_t pgd;
28660 +
28661 +#ifdef CONFIG_X86_64
28662 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
28663 +#else
28664 + pgd = *src++;
28665 +#endif
28666 +
28667 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28668 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
28669 +#endif
28670 +
28671 + *dst++ = pgd;
28672 + }
28673 +
28674 +}
28675 +#endif
28676 +
28677 +#ifdef CONFIG_X86_64
28678 +#define pxd_t pud_t
28679 +#define pyd_t pgd_t
28680 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
28681 +#define pxd_free(mm, pud) pud_free((mm), (pud))
28682 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
28683 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
28684 +#define PYD_SIZE PGDIR_SIZE
28685 +#else
28686 +#define pxd_t pmd_t
28687 +#define pyd_t pud_t
28688 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
28689 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
28690 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
28691 +#define pyd_offset(mm, address) pud_offset((mm), (address))
28692 +#define PYD_SIZE PUD_SIZE
28693 +#endif
28694 +
28695 +#ifdef CONFIG_PAX_PER_CPU_PGD
28696 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
28697 +static inline void pgd_dtor(pgd_t *pgd) {}
28698 +#else
28699 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
28700 {
28701 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
28702 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
28703 pgd_list_del(pgd);
28704 spin_unlock(&pgd_lock);
28705 }
28706 +#endif
28707
28708 /*
28709 * List of all pgd's needed for non-PAE so it can invalidate entries
28710 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
28711 * -- nyc
28712 */
28713
28714 -#ifdef CONFIG_X86_PAE
28715 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
28716 /*
28717 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
28718 * updating the top-level pagetable entries to guarantee the
28719 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
28720 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
28721 * and initialize the kernel pmds here.
28722 */
28723 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
28724 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28725
28726 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28727 {
28728 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28729 */
28730 flush_tlb_mm(mm);
28731 }
28732 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
28733 +#define PREALLOCATED_PXDS USER_PGD_PTRS
28734 #else /* !CONFIG_X86_PAE */
28735
28736 /* No need to prepopulate any pagetable entries in non-PAE modes. */
28737 -#define PREALLOCATED_PMDS 0
28738 +#define PREALLOCATED_PXDS 0
28739
28740 #endif /* CONFIG_X86_PAE */
28741
28742 -static void free_pmds(pmd_t *pmds[])
28743 +static void free_pxds(pxd_t *pxds[])
28744 {
28745 int i;
28746
28747 - for(i = 0; i < PREALLOCATED_PMDS; i++)
28748 - if (pmds[i])
28749 - free_page((unsigned long)pmds[i]);
28750 + for(i = 0; i < PREALLOCATED_PXDS; i++)
28751 + if (pxds[i])
28752 + free_page((unsigned long)pxds[i]);
28753 }
28754
28755 -static int preallocate_pmds(pmd_t *pmds[])
28756 +static int preallocate_pxds(pxd_t *pxds[])
28757 {
28758 int i;
28759 bool failed = false;
28760
28761 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
28762 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
28763 - if (pmd == NULL)
28764 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
28765 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
28766 + if (pxd == NULL)
28767 failed = true;
28768 - pmds[i] = pmd;
28769 + pxds[i] = pxd;
28770 }
28771
28772 if (failed) {
28773 - free_pmds(pmds);
28774 + free_pxds(pxds);
28775 return -ENOMEM;
28776 }
28777
28778 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
28779 * preallocate which never got a corresponding vma will need to be
28780 * freed manually.
28781 */
28782 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
28783 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
28784 {
28785 int i;
28786
28787 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
28788 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
28789 pgd_t pgd = pgdp[i];
28790
28791 if (pgd_val(pgd) != 0) {
28792 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
28793 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
28794
28795 - pgdp[i] = native_make_pgd(0);
28796 + set_pgd(pgdp + i, native_make_pgd(0));
28797
28798 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
28799 - pmd_free(mm, pmd);
28800 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
28801 + pxd_free(mm, pxd);
28802 }
28803 }
28804 }
28805
28806 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
28807 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
28808 {
28809 - pud_t *pud;
28810 + pyd_t *pyd;
28811 unsigned long addr;
28812 int i;
28813
28814 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
28815 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
28816 return;
28817
28818 - pud = pud_offset(pgd, 0);
28819 +#ifdef CONFIG_X86_64
28820 + pyd = pyd_offset(mm, 0L);
28821 +#else
28822 + pyd = pyd_offset(pgd, 0L);
28823 +#endif
28824
28825 - for (addr = i = 0; i < PREALLOCATED_PMDS;
28826 - i++, pud++, addr += PUD_SIZE) {
28827 - pmd_t *pmd = pmds[i];
28828 + for (addr = i = 0; i < PREALLOCATED_PXDS;
28829 + i++, pyd++, addr += PYD_SIZE) {
28830 + pxd_t *pxd = pxds[i];
28831
28832 if (i >= KERNEL_PGD_BOUNDARY)
28833 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28834 - sizeof(pmd_t) * PTRS_PER_PMD);
28835 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28836 + sizeof(pxd_t) * PTRS_PER_PMD);
28837
28838 - pud_populate(mm, pud, pmd);
28839 + pyd_populate(mm, pyd, pxd);
28840 }
28841 }
28842
28843 pgd_t *pgd_alloc(struct mm_struct *mm)
28844 {
28845 pgd_t *pgd;
28846 - pmd_t *pmds[PREALLOCATED_PMDS];
28847 + pxd_t *pxds[PREALLOCATED_PXDS];
28848
28849 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
28850
28851 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28852
28853 mm->pgd = pgd;
28854
28855 - if (preallocate_pmds(pmds) != 0)
28856 + if (preallocate_pxds(pxds) != 0)
28857 goto out_free_pgd;
28858
28859 if (paravirt_pgd_alloc(mm) != 0)
28860 - goto out_free_pmds;
28861 + goto out_free_pxds;
28862
28863 /*
28864 * Make sure that pre-populating the pmds is atomic with
28865 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28866 spin_lock(&pgd_lock);
28867
28868 pgd_ctor(mm, pgd);
28869 - pgd_prepopulate_pmd(mm, pgd, pmds);
28870 + pgd_prepopulate_pxd(mm, pgd, pxds);
28871
28872 spin_unlock(&pgd_lock);
28873
28874 return pgd;
28875
28876 -out_free_pmds:
28877 - free_pmds(pmds);
28878 +out_free_pxds:
28879 + free_pxds(pxds);
28880 out_free_pgd:
28881 free_page((unsigned long)pgd);
28882 out:
28883 @@ -295,7 +356,7 @@ out:
28884
28885 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
28886 {
28887 - pgd_mop_up_pmds(mm, pgd);
28888 + pgd_mop_up_pxds(mm, pgd);
28889 pgd_dtor(pgd);
28890 paravirt_pgd_free(mm, pgd);
28891 free_page((unsigned long)pgd);
28892 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
28893 index a69bcb8..19068ab 100644
28894 --- a/arch/x86/mm/pgtable_32.c
28895 +++ b/arch/x86/mm/pgtable_32.c
28896 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
28897 return;
28898 }
28899 pte = pte_offset_kernel(pmd, vaddr);
28900 +
28901 + pax_open_kernel();
28902 if (pte_val(pteval))
28903 set_pte_at(&init_mm, vaddr, pte, pteval);
28904 else
28905 pte_clear(&init_mm, vaddr, pte);
28906 + pax_close_kernel();
28907
28908 /*
28909 * It's enough to flush this one mapping.
28910 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
28911 index 410531d..0f16030 100644
28912 --- a/arch/x86/mm/setup_nx.c
28913 +++ b/arch/x86/mm/setup_nx.c
28914 @@ -5,8 +5,10 @@
28915 #include <asm/pgtable.h>
28916 #include <asm/proto.h>
28917
28918 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28919 static int disable_nx __cpuinitdata;
28920
28921 +#ifndef CONFIG_PAX_PAGEEXEC
28922 /*
28923 * noexec = on|off
28924 *
28925 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
28926 return 0;
28927 }
28928 early_param("noexec", noexec_setup);
28929 +#endif
28930 +
28931 +#endif
28932
28933 void __cpuinit x86_configure_nx(void)
28934 {
28935 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28936 if (cpu_has_nx && !disable_nx)
28937 __supported_pte_mask |= _PAGE_NX;
28938 else
28939 +#endif
28940 __supported_pte_mask &= ~_PAGE_NX;
28941 }
28942
28943 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
28944 index 13a6b29..c2fff23 100644
28945 --- a/arch/x86/mm/tlb.c
28946 +++ b/arch/x86/mm/tlb.c
28947 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
28948 BUG();
28949 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
28950 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
28951 +
28952 +#ifndef CONFIG_PAX_PER_CPU_PGD
28953 load_cr3(swapper_pg_dir);
28954 +#endif
28955 +
28956 }
28957 }
28958 EXPORT_SYMBOL_GPL(leave_mm);
28959 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
28960 index 877b9a1..a8ecf42 100644
28961 --- a/arch/x86/net/bpf_jit.S
28962 +++ b/arch/x86/net/bpf_jit.S
28963 @@ -9,6 +9,7 @@
28964 */
28965 #include <linux/linkage.h>
28966 #include <asm/dwarf2.h>
28967 +#include <asm/alternative-asm.h>
28968
28969 /*
28970 * Calling convention :
28971 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
28972 jle bpf_slow_path_word
28973 mov (SKBDATA,%rsi),%eax
28974 bswap %eax /* ntohl() */
28975 + pax_force_retaddr
28976 ret
28977
28978 sk_load_half:
28979 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
28980 jle bpf_slow_path_half
28981 movzwl (SKBDATA,%rsi),%eax
28982 rol $8,%ax # ntohs()
28983 + pax_force_retaddr
28984 ret
28985
28986 sk_load_byte:
28987 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
28988 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
28989 jle bpf_slow_path_byte
28990 movzbl (SKBDATA,%rsi),%eax
28991 + pax_force_retaddr
28992 ret
28993
28994 /**
28995 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
28996 movzbl (SKBDATA,%rsi),%ebx
28997 and $15,%bl
28998 shl $2,%bl
28999 + pax_force_retaddr
29000 ret
29001
29002 /* rsi contains offset and can be scratched */
29003 @@ -109,6 +114,7 @@ bpf_slow_path_word:
29004 js bpf_error
29005 mov -12(%rbp),%eax
29006 bswap %eax
29007 + pax_force_retaddr
29008 ret
29009
29010 bpf_slow_path_half:
29011 @@ -117,12 +123,14 @@ bpf_slow_path_half:
29012 mov -12(%rbp),%ax
29013 rol $8,%ax
29014 movzwl %ax,%eax
29015 + pax_force_retaddr
29016 ret
29017
29018 bpf_slow_path_byte:
29019 bpf_slow_path_common(1)
29020 js bpf_error
29021 movzbl -12(%rbp),%eax
29022 + pax_force_retaddr
29023 ret
29024
29025 bpf_slow_path_byte_msh:
29026 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29027 and $15,%al
29028 shl $2,%al
29029 xchg %eax,%ebx
29030 + pax_force_retaddr
29031 ret
29032
29033 #define sk_negative_common(SIZE) \
29034 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29035 sk_negative_common(4)
29036 mov (%rax), %eax
29037 bswap %eax
29038 + pax_force_retaddr
29039 ret
29040
29041 bpf_slow_path_half_neg:
29042 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29043 mov (%rax),%ax
29044 rol $8,%ax
29045 movzwl %ax,%eax
29046 + pax_force_retaddr
29047 ret
29048
29049 bpf_slow_path_byte_neg:
29050 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29051 .globl sk_load_byte_negative_offset
29052 sk_negative_common(1)
29053 movzbl (%rax), %eax
29054 + pax_force_retaddr
29055 ret
29056
29057 bpf_slow_path_byte_msh_neg:
29058 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29059 and $15,%al
29060 shl $2,%al
29061 xchg %eax,%ebx
29062 + pax_force_retaddr
29063 ret
29064
29065 bpf_error:
29066 @@ -197,4 +210,5 @@ bpf_error:
29067 xor %eax,%eax
29068 mov -8(%rbp),%rbx
29069 leaveq
29070 + pax_force_retaddr
29071 ret
29072 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29073 index d11a470..3f9adff3 100644
29074 --- a/arch/x86/net/bpf_jit_comp.c
29075 +++ b/arch/x86/net/bpf_jit_comp.c
29076 @@ -12,6 +12,7 @@
29077 #include <linux/netdevice.h>
29078 #include <linux/filter.h>
29079 #include <linux/if_vlan.h>
29080 +#include <linux/random.h>
29081
29082 /*
29083 * Conventions :
29084 @@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29085 return ptr + len;
29086 }
29087
29088 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29089 +#define MAX_INSTR_CODE_SIZE 96
29090 +#else
29091 +#define MAX_INSTR_CODE_SIZE 64
29092 +#endif
29093 +
29094 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29095
29096 #define EMIT1(b1) EMIT(b1, 1)
29097 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29098 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29099 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29100 +
29101 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29102 +/* original constant will appear in ecx */
29103 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
29104 +do { \
29105 + /* mov ecx, randkey */ \
29106 + EMIT1(0xb9); \
29107 + EMIT(_key, 4); \
29108 + /* xor ecx, randkey ^ off */ \
29109 + EMIT2(0x81, 0xf1); \
29110 + EMIT((_key) ^ (_off), 4); \
29111 +} while (0)
29112 +
29113 +#define EMIT1_off32(b1, _off) \
29114 +do { \
29115 + switch (b1) { \
29116 + case 0x05: /* add eax, imm32 */ \
29117 + case 0x2d: /* sub eax, imm32 */ \
29118 + case 0x25: /* and eax, imm32 */ \
29119 + case 0x0d: /* or eax, imm32 */ \
29120 + case 0xb8: /* mov eax, imm32 */ \
29121 + case 0x3d: /* cmp eax, imm32 */ \
29122 + case 0xa9: /* test eax, imm32 */ \
29123 + DILUTE_CONST_SEQUENCE(_off, randkey); \
29124 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29125 + break; \
29126 + case 0xbb: /* mov ebx, imm32 */ \
29127 + DILUTE_CONST_SEQUENCE(_off, randkey); \
29128 + /* mov ebx, ecx */ \
29129 + EMIT2(0x89, 0xcb); \
29130 + break; \
29131 + case 0xbe: /* mov esi, imm32 */ \
29132 + DILUTE_CONST_SEQUENCE(_off, randkey); \
29133 + /* mov esi, ecx */ \
29134 + EMIT2(0x89, 0xce); \
29135 + break; \
29136 + case 0xe9: /* jmp rel imm32 */ \
29137 + EMIT1(b1); \
29138 + EMIT(_off, 4); \
29139 + /* prevent fall-through, we're not called if off = 0 */ \
29140 + EMIT(0xcccccccc, 4); \
29141 + EMIT(0xcccccccc, 4); \
29142 + break; \
29143 + default: \
29144 + EMIT1(b1); \
29145 + EMIT(_off, 4); \
29146 + } \
29147 +} while (0)
29148 +
29149 +#define EMIT2_off32(b1, b2, _off) \
29150 +do { \
29151 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29152 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29153 + EMIT(randkey, 4); \
29154 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29155 + EMIT((_off) - randkey, 4); \
29156 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29157 + DILUTE_CONST_SEQUENCE(_off, randkey); \
29158 + /* imul eax, ecx */ \
29159 + EMIT3(0x0f, 0xaf, 0xc1); \
29160 + } else { \
29161 + EMIT2(b1, b2); \
29162 + EMIT(_off, 4); \
29163 + } \
29164 +} while (0)
29165 +#else
29166 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29167 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29168 +#endif
29169
29170 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29171 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29172 @@ -90,6 +165,24 @@ do { \
29173 #define X86_JBE 0x76
29174 #define X86_JA 0x77
29175
29176 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29177 +#define APPEND_FLOW_VERIFY() \
29178 +do { \
29179 + /* mov ecx, randkey */ \
29180 + EMIT1(0xb9); \
29181 + EMIT(randkey, 4); \
29182 + /* cmp ecx, randkey */ \
29183 + EMIT2(0x81, 0xf9); \
29184 + EMIT(randkey, 4); \
29185 + /* jz after 8 int 3s */ \
29186 + EMIT2(0x74, 0x08); \
29187 + EMIT(0xcccccccc, 4); \
29188 + EMIT(0xcccccccc, 4); \
29189 +} while (0)
29190 +#else
29191 +#define APPEND_FLOW_VERIFY() do { } while (0)
29192 +#endif
29193 +
29194 #define EMIT_COND_JMP(op, offset) \
29195 do { \
29196 if (is_near(offset)) \
29197 @@ -97,6 +190,7 @@ do { \
29198 else { \
29199 EMIT2(0x0f, op + 0x10); \
29200 EMIT(offset, 4); /* jxx .+off32 */ \
29201 + APPEND_FLOW_VERIFY(); \
29202 } \
29203 } while (0)
29204
29205 @@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
29206 set_fs(old_fs);
29207 }
29208
29209 +struct bpf_jit_work {
29210 + struct work_struct work;
29211 + void *image;
29212 +};
29213 +
29214 #define CHOOSE_LOAD_FUNC(K, func) \
29215 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29216
29217 void bpf_jit_compile(struct sk_filter *fp)
29218 {
29219 - u8 temp[64];
29220 + u8 temp[MAX_INSTR_CODE_SIZE];
29221 u8 *prog;
29222 unsigned int proglen, oldproglen = 0;
29223 int ilen, i;
29224 @@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29225 unsigned int *addrs;
29226 const struct sock_filter *filter = fp->insns;
29227 int flen = fp->len;
29228 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29229 + unsigned int randkey;
29230 +#endif
29231
29232 if (!bpf_jit_enable)
29233 return;
29234 @@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29235 if (addrs == NULL)
29236 return;
29237
29238 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29239 + if (!fp->work)
29240 + goto out;
29241 +
29242 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29243 + randkey = get_random_int();
29244 +#endif
29245 +
29246 /* Before first pass, make a rough estimation of addrs[]
29247 - * each bpf instruction is translated to less than 64 bytes
29248 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29249 */
29250 for (proglen = 0, i = 0; i < flen; i++) {
29251 - proglen += 64;
29252 + proglen += MAX_INSTR_CODE_SIZE;
29253 addrs[i] = proglen;
29254 }
29255 cleanup_addr = proglen; /* epilogue address */
29256 @@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29257 case BPF_S_ALU_MUL_K: /* A *= K */
29258 if (is_imm8(K))
29259 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29260 - else {
29261 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29262 - EMIT(K, 4);
29263 - }
29264 + else
29265 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29266 break;
29267 case BPF_S_ALU_DIV_X: /* A /= X; */
29268 seen |= SEEN_XREG;
29269 @@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29270 break;
29271 case BPF_S_ALU_MOD_K: /* A %= K; */
29272 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29273 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29274 + DILUTE_CONST_SEQUENCE(K, randkey);
29275 +#else
29276 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29277 +#endif
29278 EMIT2(0xf7, 0xf1); /* div %ecx */
29279 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29280 break;
29281 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29282 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29283 + DILUTE_CONST_SEQUENCE(K, randkey);
29284 + // imul rax, rcx
29285 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29286 +#else
29287 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29288 EMIT(K, 4);
29289 +#endif
29290 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29291 break;
29292 case BPF_S_ALU_AND_X:
29293 @@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29294 if (is_imm8(K)) {
29295 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29296 } else {
29297 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29298 - EMIT(K, 4);
29299 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29300 }
29301 } else {
29302 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29303 @@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29304 break;
29305 default:
29306 /* hmm, too complex filter, give up with jit compiler */
29307 - goto out;
29308 + goto error;
29309 }
29310 ilen = prog - temp;
29311 if (image) {
29312 if (unlikely(proglen + ilen > oldproglen)) {
29313 pr_err("bpb_jit_compile fatal error\n");
29314 - kfree(addrs);
29315 - module_free(NULL, image);
29316 - return;
29317 + module_free_exec(NULL, image);
29318 + goto error;
29319 }
29320 + pax_open_kernel();
29321 memcpy(image + proglen, temp, ilen);
29322 + pax_close_kernel();
29323 }
29324 proglen += ilen;
29325 addrs[i] = proglen;
29326 @@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29327 break;
29328 }
29329 if (proglen == oldproglen) {
29330 - image = module_alloc(max_t(unsigned int,
29331 - proglen,
29332 - sizeof(struct work_struct)));
29333 + image = module_alloc_exec(proglen);
29334 if (!image)
29335 - goto out;
29336 + goto error;
29337 }
29338 oldproglen = proglen;
29339 }
29340 @@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29341 bpf_flush_icache(image, image + proglen);
29342
29343 fp->bpf_func = (void *)image;
29344 - }
29345 + } else
29346 +error:
29347 + kfree(fp->work);
29348 +
29349 out:
29350 kfree(addrs);
29351 return;
29352 @@ -707,18 +826,20 @@ out:
29353
29354 static void jit_free_defer(struct work_struct *arg)
29355 {
29356 - module_free(NULL, arg);
29357 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29358 + kfree(arg);
29359 }
29360
29361 /* run from softirq, we must use a work_struct to call
29362 - * module_free() from process context
29363 + * module_free_exec() from process context
29364 */
29365 void bpf_jit_free(struct sk_filter *fp)
29366 {
29367 if (fp->bpf_func != sk_run_filter) {
29368 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
29369 + struct work_struct *work = &fp->work->work;
29370
29371 INIT_WORK(work, jit_free_defer);
29372 + fp->work->image = fp->bpf_func;
29373 schedule_work(work);
29374 }
29375 }
29376 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29377 index d6aa6e8..266395a 100644
29378 --- a/arch/x86/oprofile/backtrace.c
29379 +++ b/arch/x86/oprofile/backtrace.c
29380 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29381 struct stack_frame_ia32 *fp;
29382 unsigned long bytes;
29383
29384 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29385 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29386 if (bytes != sizeof(bufhead))
29387 return NULL;
29388
29389 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29390 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29391
29392 oprofile_add_trace(bufhead[0].return_address);
29393
29394 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29395 struct stack_frame bufhead[2];
29396 unsigned long bytes;
29397
29398 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29399 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29400 if (bytes != sizeof(bufhead))
29401 return NULL;
29402
29403 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29404 {
29405 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29406
29407 - if (!user_mode_vm(regs)) {
29408 + if (!user_mode(regs)) {
29409 unsigned long stack = kernel_stack_pointer(regs);
29410 if (depth)
29411 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29412 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
29413 index 48768df..ba9143c 100644
29414 --- a/arch/x86/oprofile/nmi_int.c
29415 +++ b/arch/x86/oprofile/nmi_int.c
29416 @@ -23,6 +23,7 @@
29417 #include <asm/nmi.h>
29418 #include <asm/msr.h>
29419 #include <asm/apic.h>
29420 +#include <asm/pgtable.h>
29421
29422 #include "op_counter.h"
29423 #include "op_x86_model.h"
29424 @@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
29425 if (ret)
29426 return ret;
29427
29428 - if (!model->num_virt_counters)
29429 - model->num_virt_counters = model->num_counters;
29430 + if (!model->num_virt_counters) {
29431 + pax_open_kernel();
29432 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
29433 + pax_close_kernel();
29434 + }
29435
29436 mux_init(ops);
29437
29438 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
29439 index b2b9443..be58856 100644
29440 --- a/arch/x86/oprofile/op_model_amd.c
29441 +++ b/arch/x86/oprofile/op_model_amd.c
29442 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
29443 num_counters = AMD64_NUM_COUNTERS;
29444 }
29445
29446 - op_amd_spec.num_counters = num_counters;
29447 - op_amd_spec.num_controls = num_counters;
29448 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29449 + pax_open_kernel();
29450 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
29451 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
29452 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29453 + pax_close_kernel();
29454
29455 return 0;
29456 }
29457 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
29458 index d90528e..0127e2b 100644
29459 --- a/arch/x86/oprofile/op_model_ppro.c
29460 +++ b/arch/x86/oprofile/op_model_ppro.c
29461 @@ -19,6 +19,7 @@
29462 #include <asm/msr.h>
29463 #include <asm/apic.h>
29464 #include <asm/nmi.h>
29465 +#include <asm/pgtable.h>
29466
29467 #include "op_x86_model.h"
29468 #include "op_counter.h"
29469 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
29470
29471 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
29472
29473 - op_arch_perfmon_spec.num_counters = num_counters;
29474 - op_arch_perfmon_spec.num_controls = num_counters;
29475 + pax_open_kernel();
29476 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
29477 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
29478 + pax_close_kernel();
29479 }
29480
29481 static int arch_perfmon_init(struct oprofile_operations *ignore)
29482 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
29483 index 71e8a67..6a313bb 100644
29484 --- a/arch/x86/oprofile/op_x86_model.h
29485 +++ b/arch/x86/oprofile/op_x86_model.h
29486 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
29487 void (*switch_ctrl)(struct op_x86_model_spec const *model,
29488 struct op_msrs const * const msrs);
29489 #endif
29490 -};
29491 +} __do_const;
29492
29493 struct op_counter_config;
29494
29495 diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
29496 index e9e6ed5..e47ae67 100644
29497 --- a/arch/x86/pci/amd_bus.c
29498 +++ b/arch/x86/pci/amd_bus.c
29499 @@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
29500 return NOTIFY_OK;
29501 }
29502
29503 -static struct notifier_block __cpuinitdata amd_cpu_notifier = {
29504 +static struct notifier_block amd_cpu_notifier = {
29505 .notifier_call = amd_cpu_notify,
29506 };
29507
29508 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
29509 index 372e9b8..e775a6c 100644
29510 --- a/arch/x86/pci/irq.c
29511 +++ b/arch/x86/pci/irq.c
29512 @@ -50,7 +50,7 @@ struct irq_router {
29513 struct irq_router_handler {
29514 u16 vendor;
29515 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
29516 -};
29517 +} __do_const;
29518
29519 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
29520 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
29521 @@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
29522 return 0;
29523 }
29524
29525 -static __initdata struct irq_router_handler pirq_routers[] = {
29526 +static __initconst const struct irq_router_handler pirq_routers[] = {
29527 { PCI_VENDOR_ID_INTEL, intel_router_probe },
29528 { PCI_VENDOR_ID_AL, ali_router_probe },
29529 { PCI_VENDOR_ID_ITE, ite_router_probe },
29530 @@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
29531 static void __init pirq_find_router(struct irq_router *r)
29532 {
29533 struct irq_routing_table *rt = pirq_table;
29534 - struct irq_router_handler *h;
29535 + const struct irq_router_handler *h;
29536
29537 #ifdef CONFIG_PCI_BIOS
29538 if (!rt->signature) {
29539 @@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
29540 return 0;
29541 }
29542
29543 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
29544 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
29545 {
29546 .callback = fix_broken_hp_bios_irq9,
29547 .ident = "HP Pavilion N5400 Series Laptop",
29548 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
29549 index 6eb18c4..20d83de 100644
29550 --- a/arch/x86/pci/mrst.c
29551 +++ b/arch/x86/pci/mrst.c
29552 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
29553 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
29554 pci_mmcfg_late_init();
29555 pcibios_enable_irq = mrst_pci_irq_enable;
29556 - pci_root_ops = pci_mrst_ops;
29557 + pax_open_kernel();
29558 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
29559 + pax_close_kernel();
29560 pci_soc_mode = 1;
29561 /* Continue with standard init */
29562 return 1;
29563 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
29564 index c77b24a..c979855 100644
29565 --- a/arch/x86/pci/pcbios.c
29566 +++ b/arch/x86/pci/pcbios.c
29567 @@ -79,7 +79,7 @@ union bios32 {
29568 static struct {
29569 unsigned long address;
29570 unsigned short segment;
29571 -} bios32_indirect = { 0, __KERNEL_CS };
29572 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
29573
29574 /*
29575 * Returns the entry point for the given service, NULL on error
29576 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
29577 unsigned long length; /* %ecx */
29578 unsigned long entry; /* %edx */
29579 unsigned long flags;
29580 + struct desc_struct d, *gdt;
29581
29582 local_irq_save(flags);
29583 - __asm__("lcall *(%%edi); cld"
29584 +
29585 + gdt = get_cpu_gdt_table(smp_processor_id());
29586 +
29587 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
29588 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29589 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
29590 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29591 +
29592 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
29593 : "=a" (return_code),
29594 "=b" (address),
29595 "=c" (length),
29596 "=d" (entry)
29597 : "0" (service),
29598 "1" (0),
29599 - "D" (&bios32_indirect));
29600 + "D" (&bios32_indirect),
29601 + "r"(__PCIBIOS_DS)
29602 + : "memory");
29603 +
29604 + pax_open_kernel();
29605 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
29606 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
29607 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
29608 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
29609 + pax_close_kernel();
29610 +
29611 local_irq_restore(flags);
29612
29613 switch (return_code) {
29614 - case 0:
29615 - return address + entry;
29616 - case 0x80: /* Not present */
29617 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29618 - return 0;
29619 - default: /* Shouldn't happen */
29620 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29621 - service, return_code);
29622 + case 0: {
29623 + int cpu;
29624 + unsigned char flags;
29625 +
29626 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
29627 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
29628 + printk(KERN_WARNING "bios32_service: not valid\n");
29629 return 0;
29630 + }
29631 + address = address + PAGE_OFFSET;
29632 + length += 16UL; /* some BIOSs underreport this... */
29633 + flags = 4;
29634 + if (length >= 64*1024*1024) {
29635 + length >>= PAGE_SHIFT;
29636 + flags |= 8;
29637 + }
29638 +
29639 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
29640 + gdt = get_cpu_gdt_table(cpu);
29641 + pack_descriptor(&d, address, length, 0x9b, flags);
29642 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29643 + pack_descriptor(&d, address, length, 0x93, flags);
29644 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29645 + }
29646 + return entry;
29647 + }
29648 + case 0x80: /* Not present */
29649 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29650 + return 0;
29651 + default: /* Shouldn't happen */
29652 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29653 + service, return_code);
29654 + return 0;
29655 }
29656 }
29657
29658 static struct {
29659 unsigned long address;
29660 unsigned short segment;
29661 -} pci_indirect = { 0, __KERNEL_CS };
29662 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
29663
29664 -static int pci_bios_present;
29665 +static int pci_bios_present __read_only;
29666
29667 static int check_pcibios(void)
29668 {
29669 @@ -131,11 +174,13 @@ static int check_pcibios(void)
29670 unsigned long flags, pcibios_entry;
29671
29672 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
29673 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
29674 + pci_indirect.address = pcibios_entry;
29675
29676 local_irq_save(flags);
29677 - __asm__(
29678 - "lcall *(%%edi); cld\n\t"
29679 + __asm__("movw %w6, %%ds\n\t"
29680 + "lcall *%%ss:(%%edi); cld\n\t"
29681 + "push %%ss\n\t"
29682 + "pop %%ds\n\t"
29683 "jc 1f\n\t"
29684 "xor %%ah, %%ah\n"
29685 "1:"
29686 @@ -144,7 +189,8 @@ static int check_pcibios(void)
29687 "=b" (ebx),
29688 "=c" (ecx)
29689 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
29690 - "D" (&pci_indirect)
29691 + "D" (&pci_indirect),
29692 + "r" (__PCIBIOS_DS)
29693 : "memory");
29694 local_irq_restore(flags);
29695
29696 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29697
29698 switch (len) {
29699 case 1:
29700 - __asm__("lcall *(%%esi); cld\n\t"
29701 + __asm__("movw %w6, %%ds\n\t"
29702 + "lcall *%%ss:(%%esi); cld\n\t"
29703 + "push %%ss\n\t"
29704 + "pop %%ds\n\t"
29705 "jc 1f\n\t"
29706 "xor %%ah, %%ah\n"
29707 "1:"
29708 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29709 : "1" (PCIBIOS_READ_CONFIG_BYTE),
29710 "b" (bx),
29711 "D" ((long)reg),
29712 - "S" (&pci_indirect));
29713 + "S" (&pci_indirect),
29714 + "r" (__PCIBIOS_DS));
29715 /*
29716 * Zero-extend the result beyond 8 bits, do not trust the
29717 * BIOS having done it:
29718 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29719 *value &= 0xff;
29720 break;
29721 case 2:
29722 - __asm__("lcall *(%%esi); cld\n\t"
29723 + __asm__("movw %w6, %%ds\n\t"
29724 + "lcall *%%ss:(%%esi); cld\n\t"
29725 + "push %%ss\n\t"
29726 + "pop %%ds\n\t"
29727 "jc 1f\n\t"
29728 "xor %%ah, %%ah\n"
29729 "1:"
29730 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29731 : "1" (PCIBIOS_READ_CONFIG_WORD),
29732 "b" (bx),
29733 "D" ((long)reg),
29734 - "S" (&pci_indirect));
29735 + "S" (&pci_indirect),
29736 + "r" (__PCIBIOS_DS));
29737 /*
29738 * Zero-extend the result beyond 16 bits, do not trust the
29739 * BIOS having done it:
29740 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29741 *value &= 0xffff;
29742 break;
29743 case 4:
29744 - __asm__("lcall *(%%esi); cld\n\t"
29745 + __asm__("movw %w6, %%ds\n\t"
29746 + "lcall *%%ss:(%%esi); cld\n\t"
29747 + "push %%ss\n\t"
29748 + "pop %%ds\n\t"
29749 "jc 1f\n\t"
29750 "xor %%ah, %%ah\n"
29751 "1:"
29752 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29753 : "1" (PCIBIOS_READ_CONFIG_DWORD),
29754 "b" (bx),
29755 "D" ((long)reg),
29756 - "S" (&pci_indirect));
29757 + "S" (&pci_indirect),
29758 + "r" (__PCIBIOS_DS));
29759 break;
29760 }
29761
29762 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29763
29764 switch (len) {
29765 case 1:
29766 - __asm__("lcall *(%%esi); cld\n\t"
29767 + __asm__("movw %w6, %%ds\n\t"
29768 + "lcall *%%ss:(%%esi); cld\n\t"
29769 + "push %%ss\n\t"
29770 + "pop %%ds\n\t"
29771 "jc 1f\n\t"
29772 "xor %%ah, %%ah\n"
29773 "1:"
29774 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29775 "c" (value),
29776 "b" (bx),
29777 "D" ((long)reg),
29778 - "S" (&pci_indirect));
29779 + "S" (&pci_indirect),
29780 + "r" (__PCIBIOS_DS));
29781 break;
29782 case 2:
29783 - __asm__("lcall *(%%esi); cld\n\t"
29784 + __asm__("movw %w6, %%ds\n\t"
29785 + "lcall *%%ss:(%%esi); cld\n\t"
29786 + "push %%ss\n\t"
29787 + "pop %%ds\n\t"
29788 "jc 1f\n\t"
29789 "xor %%ah, %%ah\n"
29790 "1:"
29791 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29792 "c" (value),
29793 "b" (bx),
29794 "D" ((long)reg),
29795 - "S" (&pci_indirect));
29796 + "S" (&pci_indirect),
29797 + "r" (__PCIBIOS_DS));
29798 break;
29799 case 4:
29800 - __asm__("lcall *(%%esi); cld\n\t"
29801 + __asm__("movw %w6, %%ds\n\t"
29802 + "lcall *%%ss:(%%esi); cld\n\t"
29803 + "push %%ss\n\t"
29804 + "pop %%ds\n\t"
29805 "jc 1f\n\t"
29806 "xor %%ah, %%ah\n"
29807 "1:"
29808 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29809 "c" (value),
29810 "b" (bx),
29811 "D" ((long)reg),
29812 - "S" (&pci_indirect));
29813 + "S" (&pci_indirect),
29814 + "r" (__PCIBIOS_DS));
29815 break;
29816 }
29817
29818 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29819
29820 DBG("PCI: Fetching IRQ routing table... ");
29821 __asm__("push %%es\n\t"
29822 + "movw %w8, %%ds\n\t"
29823 "push %%ds\n\t"
29824 "pop %%es\n\t"
29825 - "lcall *(%%esi); cld\n\t"
29826 + "lcall *%%ss:(%%esi); cld\n\t"
29827 "pop %%es\n\t"
29828 + "push %%ss\n\t"
29829 + "pop %%ds\n"
29830 "jc 1f\n\t"
29831 "xor %%ah, %%ah\n"
29832 "1:"
29833 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29834 "1" (0),
29835 "D" ((long) &opt),
29836 "S" (&pci_indirect),
29837 - "m" (opt)
29838 + "m" (opt),
29839 + "r" (__PCIBIOS_DS)
29840 : "memory");
29841 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
29842 if (ret & 0xff00)
29843 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29844 {
29845 int ret;
29846
29847 - __asm__("lcall *(%%esi); cld\n\t"
29848 + __asm__("movw %w5, %%ds\n\t"
29849 + "lcall *%%ss:(%%esi); cld\n\t"
29850 + "push %%ss\n\t"
29851 + "pop %%ds\n"
29852 "jc 1f\n\t"
29853 "xor %%ah, %%ah\n"
29854 "1:"
29855 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29856 : "0" (PCIBIOS_SET_PCI_HW_INT),
29857 "b" ((dev->bus->number << 8) | dev->devfn),
29858 "c" ((irq << 8) | (pin + 10)),
29859 - "S" (&pci_indirect));
29860 + "S" (&pci_indirect),
29861 + "r" (__PCIBIOS_DS));
29862 return !(ret & 0xff00);
29863 }
29864 EXPORT_SYMBOL(pcibios_set_irq_routing);
29865 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
29866 index 40e4469..1ab536e 100644
29867 --- a/arch/x86/platform/efi/efi_32.c
29868 +++ b/arch/x86/platform/efi/efi_32.c
29869 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
29870 {
29871 struct desc_ptr gdt_descr;
29872
29873 +#ifdef CONFIG_PAX_KERNEXEC
29874 + struct desc_struct d;
29875 +#endif
29876 +
29877 local_irq_save(efi_rt_eflags);
29878
29879 load_cr3(initial_page_table);
29880 __flush_tlb_all();
29881
29882 +#ifdef CONFIG_PAX_KERNEXEC
29883 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
29884 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29885 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
29886 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29887 +#endif
29888 +
29889 gdt_descr.address = __pa(get_cpu_gdt_table(0));
29890 gdt_descr.size = GDT_SIZE - 1;
29891 load_gdt(&gdt_descr);
29892 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
29893 {
29894 struct desc_ptr gdt_descr;
29895
29896 +#ifdef CONFIG_PAX_KERNEXEC
29897 + struct desc_struct d;
29898 +
29899 + memset(&d, 0, sizeof d);
29900 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29901 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29902 +#endif
29903 +
29904 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
29905 gdt_descr.size = GDT_SIZE - 1;
29906 load_gdt(&gdt_descr);
29907 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
29908 index fbe66e6..eae5e38 100644
29909 --- a/arch/x86/platform/efi/efi_stub_32.S
29910 +++ b/arch/x86/platform/efi/efi_stub_32.S
29911 @@ -6,7 +6,9 @@
29912 */
29913
29914 #include <linux/linkage.h>
29915 +#include <linux/init.h>
29916 #include <asm/page_types.h>
29917 +#include <asm/segment.h>
29918
29919 /*
29920 * efi_call_phys(void *, ...) is a function with variable parameters.
29921 @@ -20,7 +22,7 @@
29922 * service functions will comply with gcc calling convention, too.
29923 */
29924
29925 -.text
29926 +__INIT
29927 ENTRY(efi_call_phys)
29928 /*
29929 * 0. The function can only be called in Linux kernel. So CS has been
29930 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
29931 * The mapping of lower virtual memory has been created in prelog and
29932 * epilog.
29933 */
29934 - movl $1f, %edx
29935 - subl $__PAGE_OFFSET, %edx
29936 - jmp *%edx
29937 +#ifdef CONFIG_PAX_KERNEXEC
29938 + movl $(__KERNEXEC_EFI_DS), %edx
29939 + mov %edx, %ds
29940 + mov %edx, %es
29941 + mov %edx, %ss
29942 + addl $2f,(1f)
29943 + ljmp *(1f)
29944 +
29945 +__INITDATA
29946 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
29947 +.previous
29948 +
29949 +2:
29950 + subl $2b,(1b)
29951 +#else
29952 + jmp 1f-__PAGE_OFFSET
29953 1:
29954 +#endif
29955
29956 /*
29957 * 2. Now on the top of stack is the return
29958 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
29959 * parameter 2, ..., param n. To make things easy, we save the return
29960 * address of efi_call_phys in a global variable.
29961 */
29962 - popl %edx
29963 - movl %edx, saved_return_addr
29964 - /* get the function pointer into ECX*/
29965 - popl %ecx
29966 - movl %ecx, efi_rt_function_ptr
29967 - movl $2f, %edx
29968 - subl $__PAGE_OFFSET, %edx
29969 - pushl %edx
29970 + popl (saved_return_addr)
29971 + popl (efi_rt_function_ptr)
29972
29973 /*
29974 * 3. Clear PG bit in %CR0.
29975 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
29976 /*
29977 * 5. Call the physical function.
29978 */
29979 - jmp *%ecx
29980 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
29981
29982 -2:
29983 /*
29984 * 6. After EFI runtime service returns, control will return to
29985 * following instruction. We'd better readjust stack pointer first.
29986 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
29987 movl %cr0, %edx
29988 orl $0x80000000, %edx
29989 movl %edx, %cr0
29990 - jmp 1f
29991 -1:
29992 +
29993 /*
29994 * 8. Now restore the virtual mode from flat mode by
29995 * adding EIP with PAGE_OFFSET.
29996 */
29997 - movl $1f, %edx
29998 - jmp *%edx
29999 +#ifdef CONFIG_PAX_KERNEXEC
30000 + movl $(__KERNEL_DS), %edx
30001 + mov %edx, %ds
30002 + mov %edx, %es
30003 + mov %edx, %ss
30004 + ljmp $(__KERNEL_CS),$1f
30005 +#else
30006 + jmp 1f+__PAGE_OFFSET
30007 +#endif
30008 1:
30009
30010 /*
30011 * 9. Balance the stack. And because EAX contain the return value,
30012 * we'd better not clobber it.
30013 */
30014 - leal efi_rt_function_ptr, %edx
30015 - movl (%edx), %ecx
30016 - pushl %ecx
30017 + pushl (efi_rt_function_ptr)
30018
30019 /*
30020 - * 10. Push the saved return address onto the stack and return.
30021 + * 10. Return to the saved return address.
30022 */
30023 - leal saved_return_addr, %edx
30024 - movl (%edx), %ecx
30025 - pushl %ecx
30026 - ret
30027 + jmpl *(saved_return_addr)
30028 ENDPROC(efi_call_phys)
30029 .previous
30030
30031 -.data
30032 +__INITDATA
30033 saved_return_addr:
30034 .long 0
30035 efi_rt_function_ptr:
30036 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30037 index 4c07cca..2c8427d 100644
30038 --- a/arch/x86/platform/efi/efi_stub_64.S
30039 +++ b/arch/x86/platform/efi/efi_stub_64.S
30040 @@ -7,6 +7,7 @@
30041 */
30042
30043 #include <linux/linkage.h>
30044 +#include <asm/alternative-asm.h>
30045
30046 #define SAVE_XMM \
30047 mov %rsp, %rax; \
30048 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
30049 call *%rdi
30050 addq $32, %rsp
30051 RESTORE_XMM
30052 + pax_force_retaddr 0, 1
30053 ret
30054 ENDPROC(efi_call0)
30055
30056 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
30057 call *%rdi
30058 addq $32, %rsp
30059 RESTORE_XMM
30060 + pax_force_retaddr 0, 1
30061 ret
30062 ENDPROC(efi_call1)
30063
30064 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
30065 call *%rdi
30066 addq $32, %rsp
30067 RESTORE_XMM
30068 + pax_force_retaddr 0, 1
30069 ret
30070 ENDPROC(efi_call2)
30071
30072 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
30073 call *%rdi
30074 addq $32, %rsp
30075 RESTORE_XMM
30076 + pax_force_retaddr 0, 1
30077 ret
30078 ENDPROC(efi_call3)
30079
30080 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
30081 call *%rdi
30082 addq $32, %rsp
30083 RESTORE_XMM
30084 + pax_force_retaddr 0, 1
30085 ret
30086 ENDPROC(efi_call4)
30087
30088 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
30089 call *%rdi
30090 addq $48, %rsp
30091 RESTORE_XMM
30092 + pax_force_retaddr 0, 1
30093 ret
30094 ENDPROC(efi_call5)
30095
30096 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
30097 call *%rdi
30098 addq $48, %rsp
30099 RESTORE_XMM
30100 + pax_force_retaddr 0, 1
30101 ret
30102 ENDPROC(efi_call6)
30103 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30104 index e31bcd8..f12dc46 100644
30105 --- a/arch/x86/platform/mrst/mrst.c
30106 +++ b/arch/x86/platform/mrst/mrst.c
30107 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30108 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30109 int sfi_mrtc_num;
30110
30111 -static void mrst_power_off(void)
30112 +static __noreturn void mrst_power_off(void)
30113 {
30114 + BUG();
30115 }
30116
30117 -static void mrst_reboot(void)
30118 +static __noreturn void mrst_reboot(void)
30119 {
30120 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30121 + BUG();
30122 }
30123
30124 /* parse all the mtimer info to a static mtimer array */
30125 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30126 index d6ee929..3637cb5 100644
30127 --- a/arch/x86/platform/olpc/olpc_dt.c
30128 +++ b/arch/x86/platform/olpc/olpc_dt.c
30129 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30130 return res;
30131 }
30132
30133 -static struct of_pdt_ops prom_olpc_ops __initdata = {
30134 +static struct of_pdt_ops prom_olpc_ops __initconst = {
30135 .nextprop = olpc_dt_nextprop,
30136 .getproplen = olpc_dt_getproplen,
30137 .getproperty = olpc_dt_getproperty,
30138 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30139 index 120cee1..b2db75a 100644
30140 --- a/arch/x86/power/cpu.c
30141 +++ b/arch/x86/power/cpu.c
30142 @@ -133,7 +133,7 @@ static void do_fpu_end(void)
30143 static void fix_processor_context(void)
30144 {
30145 int cpu = smp_processor_id();
30146 - struct tss_struct *t = &per_cpu(init_tss, cpu);
30147 + struct tss_struct *t = init_tss + cpu;
30148
30149 set_tss_desc(cpu, t); /*
30150 * This just modifies memory; should not be
30151 @@ -143,8 +143,6 @@ static void fix_processor_context(void)
30152 */
30153
30154 #ifdef CONFIG_X86_64
30155 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
30156 -
30157 syscall_init(); /* This sets MSR_*STAR and related */
30158 #endif
30159 load_TR_desc(); /* This does ltr */
30160 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30161 index cbca565..bae7133 100644
30162 --- a/arch/x86/realmode/init.c
30163 +++ b/arch/x86/realmode/init.c
30164 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
30165 __va(real_mode_header->trampoline_header);
30166
30167 #ifdef CONFIG_X86_32
30168 - trampoline_header->start = __pa(startup_32_smp);
30169 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
30170 +
30171 +#ifdef CONFIG_PAX_KERNEXEC
30172 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30173 +#endif
30174 +
30175 + trampoline_header->boot_cs = __BOOT_CS;
30176 trampoline_header->gdt_limit = __BOOT_DS + 7;
30177 trampoline_header->gdt_base = __pa(boot_gdt);
30178 #else
30179 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30180 index 8869287..d577672 100644
30181 --- a/arch/x86/realmode/rm/Makefile
30182 +++ b/arch/x86/realmode/rm/Makefile
30183 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30184 $(call cc-option, -fno-unit-at-a-time)) \
30185 $(call cc-option, -fno-stack-protector) \
30186 $(call cc-option, -mpreferred-stack-boundary=2)
30187 +ifdef CONSTIFY_PLUGIN
30188 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30189 +endif
30190 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30191 GCOV_PROFILE := n
30192 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30193 index a28221d..93c40f1 100644
30194 --- a/arch/x86/realmode/rm/header.S
30195 +++ b/arch/x86/realmode/rm/header.S
30196 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30197 #endif
30198 /* APM/BIOS reboot */
30199 .long pa_machine_real_restart_asm
30200 -#ifdef CONFIG_X86_64
30201 +#ifdef CONFIG_X86_32
30202 + .long __KERNEL_CS
30203 +#else
30204 .long __KERNEL32_CS
30205 #endif
30206 END(real_mode_header)
30207 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30208 index c1b2791..f9e31c7 100644
30209 --- a/arch/x86/realmode/rm/trampoline_32.S
30210 +++ b/arch/x86/realmode/rm/trampoline_32.S
30211 @@ -25,6 +25,12 @@
30212 #include <asm/page_types.h>
30213 #include "realmode.h"
30214
30215 +#ifdef CONFIG_PAX_KERNEXEC
30216 +#define ta(X) (X)
30217 +#else
30218 +#define ta(X) (pa_ ## X)
30219 +#endif
30220 +
30221 .text
30222 .code16
30223
30224 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30225
30226 cli # We should be safe anyway
30227
30228 - movl tr_start, %eax # where we need to go
30229 -
30230 movl $0xA5A5A5A5, trampoline_status
30231 # write marker for master knows we're running
30232
30233 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30234 movw $1, %dx # protected mode (PE) bit
30235 lmsw %dx # into protected mode
30236
30237 - ljmpl $__BOOT_CS, $pa_startup_32
30238 + ljmpl *(trampoline_header)
30239
30240 .section ".text32","ax"
30241 .code32
30242 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30243 .balign 8
30244 GLOBAL(trampoline_header)
30245 tr_start: .space 4
30246 - tr_gdt_pad: .space 2
30247 + tr_boot_cs: .space 2
30248 tr_gdt: .space 6
30249 END(trampoline_header)
30250
30251 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30252 index bb360dc..3e5945f 100644
30253 --- a/arch/x86/realmode/rm/trampoline_64.S
30254 +++ b/arch/x86/realmode/rm/trampoline_64.S
30255 @@ -107,7 +107,7 @@ ENTRY(startup_32)
30256 wrmsr
30257
30258 # Enable paging and in turn activate Long Mode
30259 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30260 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
30261 movl %eax, %cr0
30262
30263 /*
30264 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30265 index 79d67bd..c7e1b90 100644
30266 --- a/arch/x86/tools/relocs.c
30267 +++ b/arch/x86/tools/relocs.c
30268 @@ -12,10 +12,13 @@
30269 #include <regex.h>
30270 #include <tools/le_byteshift.h>
30271
30272 +#include "../../../include/generated/autoconf.h"
30273 +
30274 static void die(char *fmt, ...);
30275
30276 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
30277 static Elf32_Ehdr ehdr;
30278 +static Elf32_Phdr *phdr;
30279 static unsigned long reloc_count, reloc_idx;
30280 static unsigned long *relocs;
30281 static unsigned long reloc16_count, reloc16_idx;
30282 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
30283 }
30284 }
30285
30286 +static void read_phdrs(FILE *fp)
30287 +{
30288 + unsigned int i;
30289 +
30290 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
30291 + if (!phdr) {
30292 + die("Unable to allocate %d program headers\n",
30293 + ehdr.e_phnum);
30294 + }
30295 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30296 + die("Seek to %d failed: %s\n",
30297 + ehdr.e_phoff, strerror(errno));
30298 + }
30299 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30300 + die("Cannot read ELF program headers: %s\n",
30301 + strerror(errno));
30302 + }
30303 + for(i = 0; i < ehdr.e_phnum; i++) {
30304 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
30305 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
30306 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
30307 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
30308 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
30309 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
30310 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
30311 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
30312 + }
30313 +
30314 +}
30315 +
30316 static void read_shdrs(FILE *fp)
30317 {
30318 - int i;
30319 + unsigned int i;
30320 Elf32_Shdr shdr;
30321
30322 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30323 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
30324
30325 static void read_strtabs(FILE *fp)
30326 {
30327 - int i;
30328 + unsigned int i;
30329 for (i = 0; i < ehdr.e_shnum; i++) {
30330 struct section *sec = &secs[i];
30331 if (sec->shdr.sh_type != SHT_STRTAB) {
30332 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
30333
30334 static void read_symtabs(FILE *fp)
30335 {
30336 - int i,j;
30337 + unsigned int i,j;
30338 for (i = 0; i < ehdr.e_shnum; i++) {
30339 struct section *sec = &secs[i];
30340 if (sec->shdr.sh_type != SHT_SYMTAB) {
30341 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
30342 }
30343
30344
30345 -static void read_relocs(FILE *fp)
30346 +static void read_relocs(FILE *fp, int use_real_mode)
30347 {
30348 - int i,j;
30349 + unsigned int i,j;
30350 + uint32_t base;
30351 +
30352 for (i = 0; i < ehdr.e_shnum; i++) {
30353 struct section *sec = &secs[i];
30354 if (sec->shdr.sh_type != SHT_REL) {
30355 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
30356 die("Cannot read symbol table: %s\n",
30357 strerror(errno));
30358 }
30359 + base = 0;
30360 +
30361 +#ifdef CONFIG_X86_32
30362 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
30363 + if (phdr[j].p_type != PT_LOAD )
30364 + continue;
30365 + 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)
30366 + continue;
30367 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
30368 + break;
30369 + }
30370 +#endif
30371 +
30372 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
30373 Elf32_Rel *rel = &sec->reltab[j];
30374 - rel->r_offset = elf32_to_cpu(rel->r_offset);
30375 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
30376 rel->r_info = elf32_to_cpu(rel->r_info);
30377 }
30378 }
30379 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
30380
30381 static void print_absolute_symbols(void)
30382 {
30383 - int i;
30384 + unsigned int i;
30385 printf("Absolute symbols\n");
30386 printf(" Num: Value Size Type Bind Visibility Name\n");
30387 for (i = 0; i < ehdr.e_shnum; i++) {
30388 struct section *sec = &secs[i];
30389 char *sym_strtab;
30390 - int j;
30391 + unsigned int j;
30392
30393 if (sec->shdr.sh_type != SHT_SYMTAB) {
30394 continue;
30395 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
30396
30397 static void print_absolute_relocs(void)
30398 {
30399 - int i, printed = 0;
30400 + unsigned int i, printed = 0;
30401
30402 for (i = 0; i < ehdr.e_shnum; i++) {
30403 struct section *sec = &secs[i];
30404 struct section *sec_applies, *sec_symtab;
30405 char *sym_strtab;
30406 Elf32_Sym *sh_symtab;
30407 - int j;
30408 + unsigned int j;
30409 if (sec->shdr.sh_type != SHT_REL) {
30410 continue;
30411 }
30412 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
30413 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30414 int use_real_mode)
30415 {
30416 - int i;
30417 + unsigned int i;
30418 /* Walk through the relocations */
30419 for (i = 0; i < ehdr.e_shnum; i++) {
30420 char *sym_strtab;
30421 Elf32_Sym *sh_symtab;
30422 struct section *sec_applies, *sec_symtab;
30423 - int j;
30424 + unsigned int j;
30425 struct section *sec = &secs[i];
30426
30427 if (sec->shdr.sh_type != SHT_REL) {
30428 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30429 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
30430 r_type = ELF32_R_TYPE(rel->r_info);
30431
30432 + if (!use_real_mode) {
30433 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
30434 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
30435 + continue;
30436 +
30437 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
30438 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
30439 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
30440 + continue;
30441 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
30442 + continue;
30443 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
30444 + continue;
30445 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
30446 + continue;
30447 +#endif
30448 + }
30449 +
30450 shn_abs = sym->st_shndx == SHN_ABS;
30451
30452 switch (r_type) {
30453 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
30454
30455 static void emit_relocs(int as_text, int use_real_mode)
30456 {
30457 - int i;
30458 + unsigned int i;
30459 /* Count how many relocations I have and allocate space for them. */
30460 reloc_count = 0;
30461 walk_relocs(count_reloc, use_real_mode);
30462 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
30463 fname, strerror(errno));
30464 }
30465 read_ehdr(fp);
30466 + read_phdrs(fp);
30467 read_shdrs(fp);
30468 read_strtabs(fp);
30469 read_symtabs(fp);
30470 - read_relocs(fp);
30471 + read_relocs(fp, use_real_mode);
30472 if (show_absolute_syms) {
30473 print_absolute_symbols();
30474 goto out;
30475 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
30476 index fd14be1..e3c79c0 100644
30477 --- a/arch/x86/vdso/Makefile
30478 +++ b/arch/x86/vdso/Makefile
30479 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
30480 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
30481 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
30482
30483 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30484 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30485 GCOV_PROFILE := n
30486
30487 #
30488 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
30489 index 0faad64..39ef157 100644
30490 --- a/arch/x86/vdso/vdso32-setup.c
30491 +++ b/arch/x86/vdso/vdso32-setup.c
30492 @@ -25,6 +25,7 @@
30493 #include <asm/tlbflush.h>
30494 #include <asm/vdso.h>
30495 #include <asm/proto.h>
30496 +#include <asm/mman.h>
30497
30498 enum {
30499 VDSO_DISABLED = 0,
30500 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
30501 void enable_sep_cpu(void)
30502 {
30503 int cpu = get_cpu();
30504 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
30505 + struct tss_struct *tss = init_tss + cpu;
30506
30507 if (!boot_cpu_has(X86_FEATURE_SEP)) {
30508 put_cpu();
30509 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
30510 gate_vma.vm_start = FIXADDR_USER_START;
30511 gate_vma.vm_end = FIXADDR_USER_END;
30512 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
30513 - gate_vma.vm_page_prot = __P101;
30514 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
30515
30516 return 0;
30517 }
30518 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30519 if (compat)
30520 addr = VDSO_HIGH_BASE;
30521 else {
30522 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
30523 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
30524 if (IS_ERR_VALUE(addr)) {
30525 ret = addr;
30526 goto up_fail;
30527 }
30528 }
30529
30530 - current->mm->context.vdso = (void *)addr;
30531 + current->mm->context.vdso = addr;
30532
30533 if (compat_uses_vma || !compat) {
30534 /*
30535 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30536 }
30537
30538 current_thread_info()->sysenter_return =
30539 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30540 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30541
30542 up_fail:
30543 if (ret)
30544 - current->mm->context.vdso = NULL;
30545 + current->mm->context.vdso = 0;
30546
30547 up_write(&mm->mmap_sem);
30548
30549 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
30550
30551 const char *arch_vma_name(struct vm_area_struct *vma)
30552 {
30553 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
30554 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
30555 return "[vdso]";
30556 +
30557 +#ifdef CONFIG_PAX_SEGMEXEC
30558 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
30559 + return "[vdso]";
30560 +#endif
30561 +
30562 return NULL;
30563 }
30564
30565 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
30566 * Check to see if the corresponding task was created in compat vdso
30567 * mode.
30568 */
30569 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
30570 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
30571 return &gate_vma;
30572 return NULL;
30573 }
30574 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
30575 index 431e875..cbb23f3 100644
30576 --- a/arch/x86/vdso/vma.c
30577 +++ b/arch/x86/vdso/vma.c
30578 @@ -16,8 +16,6 @@
30579 #include <asm/vdso.h>
30580 #include <asm/page.h>
30581
30582 -unsigned int __read_mostly vdso_enabled = 1;
30583 -
30584 extern char vdso_start[], vdso_end[];
30585 extern unsigned short vdso_sync_cpuid;
30586
30587 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
30588 * unaligned here as a result of stack start randomization.
30589 */
30590 addr = PAGE_ALIGN(addr);
30591 - addr = align_vdso_addr(addr);
30592
30593 return addr;
30594 }
30595 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
30596 unsigned size)
30597 {
30598 struct mm_struct *mm = current->mm;
30599 - unsigned long addr;
30600 + unsigned long addr = 0;
30601 int ret;
30602
30603 - if (!vdso_enabled)
30604 - return 0;
30605 -
30606 down_write(&mm->mmap_sem);
30607 +
30608 +#ifdef CONFIG_PAX_RANDMMAP
30609 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30610 +#endif
30611 +
30612 addr = vdso_addr(mm->start_stack, size);
30613 + addr = align_vdso_addr(addr);
30614 addr = get_unmapped_area(NULL, addr, size, 0, 0);
30615 if (IS_ERR_VALUE(addr)) {
30616 ret = addr;
30617 goto up_fail;
30618 }
30619
30620 - current->mm->context.vdso = (void *)addr;
30621 + mm->context.vdso = addr;
30622
30623 ret = install_special_mapping(mm, addr, size,
30624 VM_READ|VM_EXEC|
30625 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
30626 pages);
30627 - if (ret) {
30628 - current->mm->context.vdso = NULL;
30629 - goto up_fail;
30630 - }
30631 + if (ret)
30632 + mm->context.vdso = 0;
30633
30634 up_fail:
30635 up_write(&mm->mmap_sem);
30636 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30637 vdsox32_size);
30638 }
30639 #endif
30640 -
30641 -static __init int vdso_setup(char *s)
30642 -{
30643 - vdso_enabled = simple_strtoul(s, NULL, 0);
30644 - return 0;
30645 -}
30646 -__setup("vdso=", vdso_setup);
30647 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
30648 index 2262003..f229ced 100644
30649 --- a/arch/x86/xen/enlighten.c
30650 +++ b/arch/x86/xen/enlighten.c
30651 @@ -100,8 +100,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
30652
30653 struct shared_info xen_dummy_shared_info;
30654
30655 -void *xen_initial_gdt;
30656 -
30657 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
30658 __read_mostly int xen_have_vector_callback;
30659 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
30660 @@ -496,8 +494,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
30661 {
30662 unsigned long va = dtr->address;
30663 unsigned int size = dtr->size + 1;
30664 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30665 - unsigned long frames[pages];
30666 + unsigned long frames[65536 / PAGE_SIZE];
30667 int f;
30668
30669 /*
30670 @@ -545,8 +542,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
30671 {
30672 unsigned long va = dtr->address;
30673 unsigned int size = dtr->size + 1;
30674 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30675 - unsigned long frames[pages];
30676 + unsigned long frames[65536 / PAGE_SIZE];
30677 int f;
30678
30679 /*
30680 @@ -939,7 +935,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
30681 return 0;
30682 }
30683
30684 -static void set_xen_basic_apic_ops(void)
30685 +static void __init set_xen_basic_apic_ops(void)
30686 {
30687 apic->read = xen_apic_read;
30688 apic->write = xen_apic_write;
30689 @@ -1245,30 +1241,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
30690 #endif
30691 };
30692
30693 -static void xen_reboot(int reason)
30694 +static __noreturn void xen_reboot(int reason)
30695 {
30696 struct sched_shutdown r = { .reason = reason };
30697
30698 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
30699 - BUG();
30700 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
30701 + BUG();
30702 }
30703
30704 -static void xen_restart(char *msg)
30705 +static __noreturn void xen_restart(char *msg)
30706 {
30707 xen_reboot(SHUTDOWN_reboot);
30708 }
30709
30710 -static void xen_emergency_restart(void)
30711 +static __noreturn void xen_emergency_restart(void)
30712 {
30713 xen_reboot(SHUTDOWN_reboot);
30714 }
30715
30716 -static void xen_machine_halt(void)
30717 +static __noreturn void xen_machine_halt(void)
30718 {
30719 xen_reboot(SHUTDOWN_poweroff);
30720 }
30721
30722 -static void xen_machine_power_off(void)
30723 +static __noreturn void xen_machine_power_off(void)
30724 {
30725 if (pm_power_off)
30726 pm_power_off();
30727 @@ -1370,7 +1366,17 @@ asmlinkage void __init xen_start_kernel(void)
30728 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
30729
30730 /* Work out if we support NX */
30731 - x86_configure_nx();
30732 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
30733 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
30734 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
30735 + unsigned l, h;
30736 +
30737 + __supported_pte_mask |= _PAGE_NX;
30738 + rdmsr(MSR_EFER, l, h);
30739 + l |= EFER_NX;
30740 + wrmsr(MSR_EFER, l, h);
30741 + }
30742 +#endif
30743
30744 xen_setup_features();
30745
30746 @@ -1399,14 +1405,7 @@ asmlinkage void __init xen_start_kernel(void)
30747 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
30748 }
30749
30750 - machine_ops = xen_machine_ops;
30751 -
30752 - /*
30753 - * The only reliable way to retain the initial address of the
30754 - * percpu gdt_page is to remember it here, so we can go and
30755 - * mark it RW later, when the initial percpu area is freed.
30756 - */
30757 - xen_initial_gdt = &per_cpu(gdt_page, 0);
30758 + memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
30759
30760 xen_smp_init();
30761
30762 @@ -1598,7 +1597,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
30763 return NOTIFY_OK;
30764 }
30765
30766 -static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
30767 +static struct notifier_block xen_hvm_cpu_notifier = {
30768 .notifier_call = xen_hvm_cpu_notify,
30769 };
30770
30771 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
30772 index 01de35c..0bda07b 100644
30773 --- a/arch/x86/xen/mmu.c
30774 +++ b/arch/x86/xen/mmu.c
30775 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30776 /* L3_k[510] -> level2_kernel_pgt
30777 * L3_i[511] -> level2_fixmap_pgt */
30778 convert_pfn_mfn(level3_kernel_pgt);
30779 + convert_pfn_mfn(level3_vmalloc_start_pgt);
30780 + convert_pfn_mfn(level3_vmalloc_end_pgt);
30781 + convert_pfn_mfn(level3_vmemmap_pgt);
30782
30783 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
30784 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
30785 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30786 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
30787 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
30788 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
30789 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
30790 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
30791 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
30792 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
30793 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
30794 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
30795 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
30796 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
30797
30798 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
30799 pv_mmu_ops.set_pud = xen_set_pud;
30800 #if PAGETABLE_LEVELS == 4
30801 pv_mmu_ops.set_pgd = xen_set_pgd;
30802 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
30803 #endif
30804
30805 /* This will work as long as patching hasn't happened yet
30806 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
30807 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
30808 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
30809 .set_pgd = xen_set_pgd_hyper,
30810 + .set_pgd_batched = xen_set_pgd_hyper,
30811
30812 .alloc_pud = xen_alloc_pmd_init,
30813 .release_pud = xen_release_pmd_init,
30814 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
30815 index 34bc4ce..c34aa24 100644
30816 --- a/arch/x86/xen/smp.c
30817 +++ b/arch/x86/xen/smp.c
30818 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
30819 {
30820 BUG_ON(smp_processor_id() != 0);
30821 native_smp_prepare_boot_cpu();
30822 -
30823 - /* We've switched to the "real" per-cpu gdt, so make sure the
30824 - old memory can be recycled */
30825 - make_lowmem_page_readwrite(xen_initial_gdt);
30826 -
30827 xen_filter_cpu_maps();
30828 xen_setup_vcpu_info_placement();
30829 }
30830 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
30831 gdt = get_cpu_gdt_table(cpu);
30832
30833 ctxt->flags = VGCF_IN_KERNEL;
30834 - ctxt->user_regs.ds = __USER_DS;
30835 - ctxt->user_regs.es = __USER_DS;
30836 + ctxt->user_regs.ds = __KERNEL_DS;
30837 + ctxt->user_regs.es = __KERNEL_DS;
30838 ctxt->user_regs.ss = __KERNEL_DS;
30839 #ifdef CONFIG_X86_32
30840 ctxt->user_regs.fs = __KERNEL_PERCPU;
30841 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
30842 + savesegment(gs, ctxt->user_regs.gs);
30843 #else
30844 ctxt->gs_base_kernel = per_cpu_offset(cpu);
30845 #endif
30846 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
30847 int rc;
30848
30849 per_cpu(current_task, cpu) = idle;
30850 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
30851 #ifdef CONFIG_X86_32
30852 irq_ctx_init(cpu);
30853 #else
30854 clear_tsk_thread_flag(idle, TIF_FORK);
30855 - per_cpu(kernel_stack, cpu) =
30856 - (unsigned long)task_stack_page(idle) -
30857 - KERNEL_STACK_OFFSET + THREAD_SIZE;
30858 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
30859 #endif
30860 xen_setup_runstate_info(cpu);
30861 xen_setup_timer(cpu);
30862 @@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
30863
30864 void __init xen_smp_init(void)
30865 {
30866 - smp_ops = xen_smp_ops;
30867 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
30868 xen_fill_possible_map();
30869 xen_init_spinlocks();
30870 }
30871 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
30872 index 33ca6e4..0ded929 100644
30873 --- a/arch/x86/xen/xen-asm_32.S
30874 +++ b/arch/x86/xen/xen-asm_32.S
30875 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
30876 ESP_OFFSET=4 # bytes pushed onto stack
30877
30878 /*
30879 - * Store vcpu_info pointer for easy access. Do it this way to
30880 - * avoid having to reload %fs
30881 + * Store vcpu_info pointer for easy access.
30882 */
30883 #ifdef CONFIG_SMP
30884 - GET_THREAD_INFO(%eax)
30885 - movl %ss:TI_cpu(%eax), %eax
30886 - movl %ss:__per_cpu_offset(,%eax,4), %eax
30887 - mov %ss:xen_vcpu(%eax), %eax
30888 + push %fs
30889 + mov $(__KERNEL_PERCPU), %eax
30890 + mov %eax, %fs
30891 + mov PER_CPU_VAR(xen_vcpu), %eax
30892 + pop %fs
30893 #else
30894 movl %ss:xen_vcpu, %eax
30895 #endif
30896 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
30897 index 7faed58..ba4427c 100644
30898 --- a/arch/x86/xen/xen-head.S
30899 +++ b/arch/x86/xen/xen-head.S
30900 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
30901 #ifdef CONFIG_X86_32
30902 mov %esi,xen_start_info
30903 mov $init_thread_union+THREAD_SIZE,%esp
30904 +#ifdef CONFIG_SMP
30905 + movl $cpu_gdt_table,%edi
30906 + movl $__per_cpu_load,%eax
30907 + movw %ax,__KERNEL_PERCPU + 2(%edi)
30908 + rorl $16,%eax
30909 + movb %al,__KERNEL_PERCPU + 4(%edi)
30910 + movb %ah,__KERNEL_PERCPU + 7(%edi)
30911 + movl $__per_cpu_end - 1,%eax
30912 + subl $__per_cpu_start,%eax
30913 + movw %ax,__KERNEL_PERCPU + 0(%edi)
30914 +#endif
30915 #else
30916 mov %rsi,xen_start_info
30917 mov $init_thread_union+THREAD_SIZE,%rsp
30918 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
30919 index a95b417..b6dbd0b 100644
30920 --- a/arch/x86/xen/xen-ops.h
30921 +++ b/arch/x86/xen/xen-ops.h
30922 @@ -10,8 +10,6 @@
30923 extern const char xen_hypervisor_callback[];
30924 extern const char xen_failsafe_callback[];
30925
30926 -extern void *xen_initial_gdt;
30927 -
30928 struct trap_info;
30929 void xen_copy_trap_info(struct trap_info *traps);
30930
30931 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
30932 index 525bd3d..ef888b1 100644
30933 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
30934 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
30935 @@ -119,9 +119,9 @@
30936 ----------------------------------------------------------------------*/
30937
30938 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
30939 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
30940 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
30941 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
30942 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30943
30944 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
30945 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
30946 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
30947 index 2f33760..835e50a 100644
30948 --- a/arch/xtensa/variants/fsf/include/variant/core.h
30949 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
30950 @@ -11,6 +11,7 @@
30951 #ifndef _XTENSA_CORE_H
30952 #define _XTENSA_CORE_H
30953
30954 +#include <linux/const.h>
30955
30956 /****************************************************************************
30957 Parameters Useful for Any Code, USER or PRIVILEGED
30958 @@ -112,9 +113,9 @@
30959 ----------------------------------------------------------------------*/
30960
30961 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30962 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30963 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30964 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30965 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30966
30967 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
30968 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
30969 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
30970 index af00795..2bb8105 100644
30971 --- a/arch/xtensa/variants/s6000/include/variant/core.h
30972 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
30973 @@ -11,6 +11,7 @@
30974 #ifndef _XTENSA_CORE_CONFIGURATION_H
30975 #define _XTENSA_CORE_CONFIGURATION_H
30976
30977 +#include <linux/const.h>
30978
30979 /****************************************************************************
30980 Parameters Useful for Any Code, USER or PRIVILEGED
30981 @@ -118,9 +119,9 @@
30982 ----------------------------------------------------------------------*/
30983
30984 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30985 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30986 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30987 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30988 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30989
30990 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
30991 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
30992 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
30993 index 58916af..eb9dbcf6 100644
30994 --- a/block/blk-iopoll.c
30995 +++ b/block/blk-iopoll.c
30996 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
30997 }
30998 EXPORT_SYMBOL(blk_iopoll_complete);
30999
31000 -static void blk_iopoll_softirq(struct softirq_action *h)
31001 +static void blk_iopoll_softirq(void)
31002 {
31003 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31004 int rearm = 0, budget = blk_iopoll_budget;
31005 @@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31006 return NOTIFY_OK;
31007 }
31008
31009 -static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31010 +static struct notifier_block blk_iopoll_cpu_notifier = {
31011 .notifier_call = blk_iopoll_cpu_notify,
31012 };
31013
31014 diff --git a/block/blk-map.c b/block/blk-map.c
31015 index 623e1cd..ca1e109 100644
31016 --- a/block/blk-map.c
31017 +++ b/block/blk-map.c
31018 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31019 if (!len || !kbuf)
31020 return -EINVAL;
31021
31022 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31023 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31024 if (do_copy)
31025 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31026 else
31027 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31028 index 467c8de..f3628c5 100644
31029 --- a/block/blk-softirq.c
31030 +++ b/block/blk-softirq.c
31031 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31032 * Softirq action handler - move entries to local list and loop over them
31033 * while passing them to the queue registered handler.
31034 */
31035 -static void blk_done_softirq(struct softirq_action *h)
31036 +static void blk_done_softirq(void)
31037 {
31038 struct list_head *cpu_list, local_list;
31039
31040 @@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31041 return NOTIFY_OK;
31042 }
31043
31044 -static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31045 +static struct notifier_block blk_cpu_notifier = {
31046 .notifier_call = blk_cpu_notify,
31047 };
31048
31049 diff --git a/block/bsg.c b/block/bsg.c
31050 index ff64ae3..593560c 100644
31051 --- a/block/bsg.c
31052 +++ b/block/bsg.c
31053 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31054 struct sg_io_v4 *hdr, struct bsg_device *bd,
31055 fmode_t has_write_perm)
31056 {
31057 + unsigned char tmpcmd[sizeof(rq->__cmd)];
31058 + unsigned char *cmdptr;
31059 +
31060 if (hdr->request_len > BLK_MAX_CDB) {
31061 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31062 if (!rq->cmd)
31063 return -ENOMEM;
31064 - }
31065 + cmdptr = rq->cmd;
31066 + } else
31067 + cmdptr = tmpcmd;
31068
31069 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31070 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31071 hdr->request_len))
31072 return -EFAULT;
31073
31074 + if (cmdptr != rq->cmd)
31075 + memcpy(rq->cmd, cmdptr, hdr->request_len);
31076 +
31077 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31078 if (blk_verify_command(rq->cmd, has_write_perm))
31079 return -EPERM;
31080 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31081 index 7c668c8..db3521c 100644
31082 --- a/block/compat_ioctl.c
31083 +++ b/block/compat_ioctl.c
31084 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31085 err |= __get_user(f->spec1, &uf->spec1);
31086 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31087 err |= __get_user(name, &uf->name);
31088 - f->name = compat_ptr(name);
31089 + f->name = (void __force_kernel *)compat_ptr(name);
31090 if (err) {
31091 err = -EFAULT;
31092 goto out;
31093 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31094 index b62fb88..bdab4c4 100644
31095 --- a/block/partitions/efi.c
31096 +++ b/block/partitions/efi.c
31097 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31098 if (!gpt)
31099 return NULL;
31100
31101 + if (!le32_to_cpu(gpt->num_partition_entries))
31102 + return NULL;
31103 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31104 + if (!pte)
31105 + return NULL;
31106 +
31107 count = le32_to_cpu(gpt->num_partition_entries) *
31108 le32_to_cpu(gpt->sizeof_partition_entry);
31109 - if (!count)
31110 - return NULL;
31111 - pte = kzalloc(count, GFP_KERNEL);
31112 - if (!pte)
31113 - return NULL;
31114 -
31115 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31116 (u8 *) pte,
31117 count) < count) {
31118 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31119 index 9a87daa..fb17486 100644
31120 --- a/block/scsi_ioctl.c
31121 +++ b/block/scsi_ioctl.c
31122 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
31123 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31124 struct sg_io_hdr *hdr, fmode_t mode)
31125 {
31126 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31127 + unsigned char tmpcmd[sizeof(rq->__cmd)];
31128 + unsigned char *cmdptr;
31129 +
31130 + if (rq->cmd != rq->__cmd)
31131 + cmdptr = rq->cmd;
31132 + else
31133 + cmdptr = tmpcmd;
31134 +
31135 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31136 return -EFAULT;
31137 +
31138 + if (cmdptr != rq->cmd)
31139 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31140 +
31141 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31142 return -EPERM;
31143
31144 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31145 int err;
31146 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31147 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31148 + unsigned char tmpcmd[sizeof(rq->__cmd)];
31149 + unsigned char *cmdptr;
31150
31151 if (!sic)
31152 return -EINVAL;
31153 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31154 */
31155 err = -EFAULT;
31156 rq->cmd_len = cmdlen;
31157 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
31158 +
31159 + if (rq->cmd != rq->__cmd)
31160 + cmdptr = rq->cmd;
31161 + else
31162 + cmdptr = tmpcmd;
31163 +
31164 + if (copy_from_user(cmdptr, sic->data, cmdlen))
31165 goto error;
31166
31167 + if (rq->cmd != cmdptr)
31168 + memcpy(rq->cmd, cmdptr, cmdlen);
31169 +
31170 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31171 goto error;
31172
31173 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31174 index 7bdd61b..afec999 100644
31175 --- a/crypto/cryptd.c
31176 +++ b/crypto/cryptd.c
31177 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31178
31179 struct cryptd_blkcipher_request_ctx {
31180 crypto_completion_t complete;
31181 -};
31182 +} __no_const;
31183
31184 struct cryptd_hash_ctx {
31185 struct crypto_shash *child;
31186 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31187
31188 struct cryptd_aead_request_ctx {
31189 crypto_completion_t complete;
31190 -};
31191 +} __no_const;
31192
31193 static void cryptd_queue_worker(struct work_struct *work);
31194
31195 diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
31196 index f6d9baf..dfd511f 100644
31197 --- a/crypto/crypto_user.c
31198 +++ b/crypto/crypto_user.c
31199 @@ -30,6 +30,8 @@
31200
31201 #include "internal.h"
31202
31203 +#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
31204 +
31205 static DEFINE_MUTEX(crypto_cfg_mutex);
31206
31207 /* The crypto netlink socket */
31208 @@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
31209 struct crypto_dump_info info;
31210 int err;
31211
31212 - if (!p->cru_driver_name)
31213 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31214 + return -EINVAL;
31215 +
31216 + if (!p->cru_driver_name[0])
31217 return -EINVAL;
31218
31219 alg = crypto_alg_match(p, 1);
31220 @@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31221 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31222 LIST_HEAD(list);
31223
31224 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31225 + return -EINVAL;
31226 +
31227 if (priority && !strlen(p->cru_driver_name))
31228 return -EINVAL;
31229
31230 @@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31231 struct crypto_alg *alg;
31232 struct crypto_user_alg *p = nlmsg_data(nlh);
31233
31234 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31235 + return -EINVAL;
31236 +
31237 alg = crypto_alg_match(p, 1);
31238 if (!alg)
31239 return -ENOENT;
31240 @@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31241 struct crypto_user_alg *p = nlmsg_data(nlh);
31242 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31243
31244 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31245 + return -EINVAL;
31246 +
31247 if (strlen(p->cru_driver_name))
31248 exact = 1;
31249
31250 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31251 index f220d64..d359ad6 100644
31252 --- a/drivers/acpi/apei/apei-internal.h
31253 +++ b/drivers/acpi/apei/apei-internal.h
31254 @@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31255 struct apei_exec_ins_type {
31256 u32 flags;
31257 apei_exec_ins_func_t run;
31258 -};
31259 +} __do_const;
31260
31261 struct apei_exec_context {
31262 u32 ip;
31263 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31264 index e6defd8..c26a225 100644
31265 --- a/drivers/acpi/apei/cper.c
31266 +++ b/drivers/acpi/apei/cper.c
31267 @@ -38,12 +38,12 @@
31268 */
31269 u64 cper_next_record_id(void)
31270 {
31271 - static atomic64_t seq;
31272 + static atomic64_unchecked_t seq;
31273
31274 - if (!atomic64_read(&seq))
31275 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
31276 + if (!atomic64_read_unchecked(&seq))
31277 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31278
31279 - return atomic64_inc_return(&seq);
31280 + return atomic64_inc_return_unchecked(&seq);
31281 }
31282 EXPORT_SYMBOL_GPL(cper_next_record_id);
31283
31284 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31285 index be60399..778b33e8 100644
31286 --- a/drivers/acpi/bgrt.c
31287 +++ b/drivers/acpi/bgrt.c
31288 @@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31289 return -ENODEV;
31290
31291 sysfs_bin_attr_init(&image_attr);
31292 - image_attr.private = bgrt_image;
31293 - image_attr.size = bgrt_image_size;
31294 + pax_open_kernel();
31295 + *(void **)&image_attr.private = bgrt_image;
31296 + *(size_t *)&image_attr.size = bgrt_image_size;
31297 + pax_close_kernel();
31298
31299 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31300 if (!bgrt_kobj)
31301 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31302 index cb96296..b81293b 100644
31303 --- a/drivers/acpi/blacklist.c
31304 +++ b/drivers/acpi/blacklist.c
31305 @@ -52,7 +52,7 @@ struct acpi_blacklist_item {
31306 u32 is_critical_error;
31307 };
31308
31309 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
31310 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
31311
31312 /*
31313 * POLICY: If *anything* doesn't work, put it on the blacklist.
31314 @@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
31315 return 0;
31316 }
31317
31318 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
31319 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
31320 {
31321 .callback = dmi_disable_osi_vista,
31322 .ident = "Fujitsu Siemens",
31323 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
31324 index 7586544..636a2f0 100644
31325 --- a/drivers/acpi/ec_sys.c
31326 +++ b/drivers/acpi/ec_sys.c
31327 @@ -12,6 +12,7 @@
31328 #include <linux/acpi.h>
31329 #include <linux/debugfs.h>
31330 #include <linux/module.h>
31331 +#include <linux/uaccess.h>
31332 #include "internal.h"
31333
31334 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
31335 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31336 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
31337 */
31338 unsigned int size = EC_SPACE_SIZE;
31339 - u8 *data = (u8 *) buf;
31340 + u8 data;
31341 loff_t init_off = *off;
31342 int err = 0;
31343
31344 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31345 size = count;
31346
31347 while (size) {
31348 - err = ec_read(*off, &data[*off - init_off]);
31349 + err = ec_read(*off, &data);
31350 if (err)
31351 return err;
31352 + if (put_user(data, &buf[*off - init_off]))
31353 + return -EFAULT;
31354 *off += 1;
31355 size--;
31356 }
31357 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31358
31359 unsigned int size = count;
31360 loff_t init_off = *off;
31361 - u8 *data = (u8 *) buf;
31362 int err = 0;
31363
31364 if (*off >= EC_SPACE_SIZE)
31365 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31366 }
31367
31368 while (size) {
31369 - u8 byte_write = data[*off - init_off];
31370 + u8 byte_write;
31371 + if (get_user(byte_write, &buf[*off - init_off]))
31372 + return -EFAULT;
31373 err = ec_write(*off, byte_write);
31374 if (err)
31375 return err;
31376 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
31377 index e83311b..142b5cc 100644
31378 --- a/drivers/acpi/processor_driver.c
31379 +++ b/drivers/acpi/processor_driver.c
31380 @@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
31381 return 0;
31382 #endif
31383
31384 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
31385 + BUG_ON(pr->id >= nr_cpu_ids);
31386
31387 /*
31388 * Buggy BIOS check
31389 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
31390 index ed9a1cc..f4a354c 100644
31391 --- a/drivers/acpi/processor_idle.c
31392 +++ b/drivers/acpi/processor_idle.c
31393 @@ -1005,7 +1005,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
31394 {
31395 int i, count = CPUIDLE_DRIVER_STATE_START;
31396 struct acpi_processor_cx *cx;
31397 - struct cpuidle_state *state;
31398 + cpuidle_state_no_const *state;
31399 struct cpuidle_driver *drv = &acpi_idle_driver;
31400
31401 if (!pr->flags.power_setup_done)
31402 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
31403 index ea61ca9..3fdd70d 100644
31404 --- a/drivers/acpi/sysfs.c
31405 +++ b/drivers/acpi/sysfs.c
31406 @@ -420,11 +420,11 @@ static u32 num_counters;
31407 static struct attribute **all_attrs;
31408 static u32 acpi_gpe_count;
31409
31410 -static struct attribute_group interrupt_stats_attr_group = {
31411 +static attribute_group_no_const interrupt_stats_attr_group = {
31412 .name = "interrupts",
31413 };
31414
31415 -static struct kobj_attribute *counter_attrs;
31416 +static kobj_attribute_no_const *counter_attrs;
31417
31418 static void delete_gpe_attr_array(void)
31419 {
31420 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
31421 index 46cd3f4..0871ad0 100644
31422 --- a/drivers/ata/libata-core.c
31423 +++ b/drivers/ata/libata-core.c
31424 @@ -4780,7 +4780,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
31425 struct ata_port *ap;
31426 unsigned int tag;
31427
31428 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31429 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31430 ap = qc->ap;
31431
31432 qc->flags = 0;
31433 @@ -4796,7 +4796,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
31434 struct ata_port *ap;
31435 struct ata_link *link;
31436
31437 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31438 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31439 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
31440 ap = qc->ap;
31441 link = qc->dev->link;
31442 @@ -5892,6 +5892,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31443 return;
31444
31445 spin_lock(&lock);
31446 + pax_open_kernel();
31447
31448 for (cur = ops->inherits; cur; cur = cur->inherits) {
31449 void **inherit = (void **)cur;
31450 @@ -5905,8 +5906,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31451 if (IS_ERR(*pp))
31452 *pp = NULL;
31453
31454 - ops->inherits = NULL;
31455 + *(struct ata_port_operations **)&ops->inherits = NULL;
31456
31457 + pax_close_kernel();
31458 spin_unlock(&lock);
31459 }
31460
31461 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
31462 index 405022d..fb70e53 100644
31463 --- a/drivers/ata/pata_arasan_cf.c
31464 +++ b/drivers/ata/pata_arasan_cf.c
31465 @@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
31466 /* Handle platform specific quirks */
31467 if (pdata->quirk) {
31468 if (pdata->quirk & CF_BROKEN_PIO) {
31469 - ap->ops->set_piomode = NULL;
31470 + pax_open_kernel();
31471 + *(void **)&ap->ops->set_piomode = NULL;
31472 + pax_close_kernel();
31473 ap->pio_mask = 0;
31474 }
31475 if (pdata->quirk & CF_BROKEN_MWDMA)
31476 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
31477 index f9b983a..887b9d8 100644
31478 --- a/drivers/atm/adummy.c
31479 +++ b/drivers/atm/adummy.c
31480 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
31481 vcc->pop(vcc, skb);
31482 else
31483 dev_kfree_skb_any(skb);
31484 - atomic_inc(&vcc->stats->tx);
31485 + atomic_inc_unchecked(&vcc->stats->tx);
31486
31487 return 0;
31488 }
31489 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
31490 index 77a7480..05cde58 100644
31491 --- a/drivers/atm/ambassador.c
31492 +++ b/drivers/atm/ambassador.c
31493 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
31494 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
31495
31496 // VC layer stats
31497 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31498 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31499
31500 // free the descriptor
31501 kfree (tx_descr);
31502 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31503 dump_skb ("<<<", vc, skb);
31504
31505 // VC layer stats
31506 - atomic_inc(&atm_vcc->stats->rx);
31507 + atomic_inc_unchecked(&atm_vcc->stats->rx);
31508 __net_timestamp(skb);
31509 // end of our responsibility
31510 atm_vcc->push (atm_vcc, skb);
31511 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31512 } else {
31513 PRINTK (KERN_INFO, "dropped over-size frame");
31514 // should we count this?
31515 - atomic_inc(&atm_vcc->stats->rx_drop);
31516 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31517 }
31518
31519 } else {
31520 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
31521 }
31522
31523 if (check_area (skb->data, skb->len)) {
31524 - atomic_inc(&atm_vcc->stats->tx_err);
31525 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
31526 return -ENOMEM; // ?
31527 }
31528
31529 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
31530 index b22d71c..d6e1049 100644
31531 --- a/drivers/atm/atmtcp.c
31532 +++ b/drivers/atm/atmtcp.c
31533 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31534 if (vcc->pop) vcc->pop(vcc,skb);
31535 else dev_kfree_skb(skb);
31536 if (dev_data) return 0;
31537 - atomic_inc(&vcc->stats->tx_err);
31538 + atomic_inc_unchecked(&vcc->stats->tx_err);
31539 return -ENOLINK;
31540 }
31541 size = skb->len+sizeof(struct atmtcp_hdr);
31542 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31543 if (!new_skb) {
31544 if (vcc->pop) vcc->pop(vcc,skb);
31545 else dev_kfree_skb(skb);
31546 - atomic_inc(&vcc->stats->tx_err);
31547 + atomic_inc_unchecked(&vcc->stats->tx_err);
31548 return -ENOBUFS;
31549 }
31550 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
31551 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31552 if (vcc->pop) vcc->pop(vcc,skb);
31553 else dev_kfree_skb(skb);
31554 out_vcc->push(out_vcc,new_skb);
31555 - atomic_inc(&vcc->stats->tx);
31556 - atomic_inc(&out_vcc->stats->rx);
31557 + atomic_inc_unchecked(&vcc->stats->tx);
31558 + atomic_inc_unchecked(&out_vcc->stats->rx);
31559 return 0;
31560 }
31561
31562 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31563 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
31564 read_unlock(&vcc_sklist_lock);
31565 if (!out_vcc) {
31566 - atomic_inc(&vcc->stats->tx_err);
31567 + atomic_inc_unchecked(&vcc->stats->tx_err);
31568 goto done;
31569 }
31570 skb_pull(skb,sizeof(struct atmtcp_hdr));
31571 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31572 __net_timestamp(new_skb);
31573 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
31574 out_vcc->push(out_vcc,new_skb);
31575 - atomic_inc(&vcc->stats->tx);
31576 - atomic_inc(&out_vcc->stats->rx);
31577 + atomic_inc_unchecked(&vcc->stats->tx);
31578 + atomic_inc_unchecked(&out_vcc->stats->rx);
31579 done:
31580 if (vcc->pop) vcc->pop(vcc,skb);
31581 else dev_kfree_skb(skb);
31582 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
31583 index c1eb6fa..4c71be9 100644
31584 --- a/drivers/atm/eni.c
31585 +++ b/drivers/atm/eni.c
31586 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
31587 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
31588 vcc->dev->number);
31589 length = 0;
31590 - atomic_inc(&vcc->stats->rx_err);
31591 + atomic_inc_unchecked(&vcc->stats->rx_err);
31592 }
31593 else {
31594 length = ATM_CELL_SIZE-1; /* no HEC */
31595 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31596 size);
31597 }
31598 eff = length = 0;
31599 - atomic_inc(&vcc->stats->rx_err);
31600 + atomic_inc_unchecked(&vcc->stats->rx_err);
31601 }
31602 else {
31603 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
31604 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31605 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
31606 vcc->dev->number,vcc->vci,length,size << 2,descr);
31607 length = eff = 0;
31608 - atomic_inc(&vcc->stats->rx_err);
31609 + atomic_inc_unchecked(&vcc->stats->rx_err);
31610 }
31611 }
31612 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
31613 @@ -767,7 +767,7 @@ rx_dequeued++;
31614 vcc->push(vcc,skb);
31615 pushed++;
31616 }
31617 - atomic_inc(&vcc->stats->rx);
31618 + atomic_inc_unchecked(&vcc->stats->rx);
31619 }
31620 wake_up(&eni_dev->rx_wait);
31621 }
31622 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
31623 PCI_DMA_TODEVICE);
31624 if (vcc->pop) vcc->pop(vcc,skb);
31625 else dev_kfree_skb_irq(skb);
31626 - atomic_inc(&vcc->stats->tx);
31627 + atomic_inc_unchecked(&vcc->stats->tx);
31628 wake_up(&eni_dev->tx_wait);
31629 dma_complete++;
31630 }
31631 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
31632 index b41c948..a002b17 100644
31633 --- a/drivers/atm/firestream.c
31634 +++ b/drivers/atm/firestream.c
31635 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
31636 }
31637 }
31638
31639 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31640 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31641
31642 fs_dprintk (FS_DEBUG_TXMEM, "i");
31643 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
31644 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31645 #endif
31646 skb_put (skb, qe->p1 & 0xffff);
31647 ATM_SKB(skb)->vcc = atm_vcc;
31648 - atomic_inc(&atm_vcc->stats->rx);
31649 + atomic_inc_unchecked(&atm_vcc->stats->rx);
31650 __net_timestamp(skb);
31651 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
31652 atm_vcc->push (atm_vcc, skb);
31653 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31654 kfree (pe);
31655 }
31656 if (atm_vcc)
31657 - atomic_inc(&atm_vcc->stats->rx_drop);
31658 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31659 break;
31660 case 0x1f: /* Reassembly abort: no buffers. */
31661 /* Silently increment error counter. */
31662 if (atm_vcc)
31663 - atomic_inc(&atm_vcc->stats->rx_drop);
31664 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31665 break;
31666 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
31667 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
31668 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
31669 index 204814e..cede831 100644
31670 --- a/drivers/atm/fore200e.c
31671 +++ b/drivers/atm/fore200e.c
31672 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
31673 #endif
31674 /* check error condition */
31675 if (*entry->status & STATUS_ERROR)
31676 - atomic_inc(&vcc->stats->tx_err);
31677 + atomic_inc_unchecked(&vcc->stats->tx_err);
31678 else
31679 - atomic_inc(&vcc->stats->tx);
31680 + atomic_inc_unchecked(&vcc->stats->tx);
31681 }
31682 }
31683
31684 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31685 if (skb == NULL) {
31686 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
31687
31688 - atomic_inc(&vcc->stats->rx_drop);
31689 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31690 return -ENOMEM;
31691 }
31692
31693 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31694
31695 dev_kfree_skb_any(skb);
31696
31697 - atomic_inc(&vcc->stats->rx_drop);
31698 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31699 return -ENOMEM;
31700 }
31701
31702 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31703
31704 vcc->push(vcc, skb);
31705 - atomic_inc(&vcc->stats->rx);
31706 + atomic_inc_unchecked(&vcc->stats->rx);
31707
31708 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31709
31710 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
31711 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
31712 fore200e->atm_dev->number,
31713 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
31714 - atomic_inc(&vcc->stats->rx_err);
31715 + atomic_inc_unchecked(&vcc->stats->rx_err);
31716 }
31717 }
31718
31719 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
31720 goto retry_here;
31721 }
31722
31723 - atomic_inc(&vcc->stats->tx_err);
31724 + atomic_inc_unchecked(&vcc->stats->tx_err);
31725
31726 fore200e->tx_sat++;
31727 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
31728 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
31729 index 72b6960..cf9167a 100644
31730 --- a/drivers/atm/he.c
31731 +++ b/drivers/atm/he.c
31732 @@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31733
31734 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
31735 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
31736 - atomic_inc(&vcc->stats->rx_drop);
31737 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31738 goto return_host_buffers;
31739 }
31740
31741 @@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31742 RBRQ_LEN_ERR(he_dev->rbrq_head)
31743 ? "LEN_ERR" : "",
31744 vcc->vpi, vcc->vci);
31745 - atomic_inc(&vcc->stats->rx_err);
31746 + atomic_inc_unchecked(&vcc->stats->rx_err);
31747 goto return_host_buffers;
31748 }
31749
31750 @@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31751 vcc->push(vcc, skb);
31752 spin_lock(&he_dev->global_lock);
31753
31754 - atomic_inc(&vcc->stats->rx);
31755 + atomic_inc_unchecked(&vcc->stats->rx);
31756
31757 return_host_buffers:
31758 ++pdus_assembled;
31759 @@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
31760 tpd->vcc->pop(tpd->vcc, tpd->skb);
31761 else
31762 dev_kfree_skb_any(tpd->skb);
31763 - atomic_inc(&tpd->vcc->stats->tx_err);
31764 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
31765 }
31766 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
31767 return;
31768 @@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31769 vcc->pop(vcc, skb);
31770 else
31771 dev_kfree_skb_any(skb);
31772 - atomic_inc(&vcc->stats->tx_err);
31773 + atomic_inc_unchecked(&vcc->stats->tx_err);
31774 return -EINVAL;
31775 }
31776
31777 @@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31778 vcc->pop(vcc, skb);
31779 else
31780 dev_kfree_skb_any(skb);
31781 - atomic_inc(&vcc->stats->tx_err);
31782 + atomic_inc_unchecked(&vcc->stats->tx_err);
31783 return -EINVAL;
31784 }
31785 #endif
31786 @@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31787 vcc->pop(vcc, skb);
31788 else
31789 dev_kfree_skb_any(skb);
31790 - atomic_inc(&vcc->stats->tx_err);
31791 + atomic_inc_unchecked(&vcc->stats->tx_err);
31792 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31793 return -ENOMEM;
31794 }
31795 @@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31796 vcc->pop(vcc, skb);
31797 else
31798 dev_kfree_skb_any(skb);
31799 - atomic_inc(&vcc->stats->tx_err);
31800 + atomic_inc_unchecked(&vcc->stats->tx_err);
31801 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31802 return -ENOMEM;
31803 }
31804 @@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31805 __enqueue_tpd(he_dev, tpd, cid);
31806 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31807
31808 - atomic_inc(&vcc->stats->tx);
31809 + atomic_inc_unchecked(&vcc->stats->tx);
31810
31811 return 0;
31812 }
31813 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
31814 index 1dc0519..1aadaf7 100644
31815 --- a/drivers/atm/horizon.c
31816 +++ b/drivers/atm/horizon.c
31817 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
31818 {
31819 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
31820 // VC layer stats
31821 - atomic_inc(&vcc->stats->rx);
31822 + atomic_inc_unchecked(&vcc->stats->rx);
31823 __net_timestamp(skb);
31824 // end of our responsibility
31825 vcc->push (vcc, skb);
31826 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
31827 dev->tx_iovec = NULL;
31828
31829 // VC layer stats
31830 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31831 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31832
31833 // free the skb
31834 hrz_kfree_skb (skb);
31835 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
31836 index 272f009..a18ba55 100644
31837 --- a/drivers/atm/idt77252.c
31838 +++ b/drivers/atm/idt77252.c
31839 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
31840 else
31841 dev_kfree_skb(skb);
31842
31843 - atomic_inc(&vcc->stats->tx);
31844 + atomic_inc_unchecked(&vcc->stats->tx);
31845 }
31846
31847 atomic_dec(&scq->used);
31848 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31849 if ((sb = dev_alloc_skb(64)) == NULL) {
31850 printk("%s: Can't allocate buffers for aal0.\n",
31851 card->name);
31852 - atomic_add(i, &vcc->stats->rx_drop);
31853 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
31854 break;
31855 }
31856 if (!atm_charge(vcc, sb->truesize)) {
31857 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
31858 card->name);
31859 - atomic_add(i - 1, &vcc->stats->rx_drop);
31860 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
31861 dev_kfree_skb(sb);
31862 break;
31863 }
31864 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *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 cell += ATM_CELL_PAYLOAD;
31872 }
31873 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31874 "(CDC: %08x)\n",
31875 card->name, len, rpp->len, readl(SAR_REG_CDC));
31876 recycle_rx_pool_skb(card, rpp);
31877 - atomic_inc(&vcc->stats->rx_err);
31878 + atomic_inc_unchecked(&vcc->stats->rx_err);
31879 return;
31880 }
31881 if (stat & SAR_RSQE_CRC) {
31882 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
31883 recycle_rx_pool_skb(card, rpp);
31884 - atomic_inc(&vcc->stats->rx_err);
31885 + atomic_inc_unchecked(&vcc->stats->rx_err);
31886 return;
31887 }
31888 if (skb_queue_len(&rpp->queue) > 1) {
31889 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31890 RXPRINTK("%s: Can't alloc RX skb.\n",
31891 card->name);
31892 recycle_rx_pool_skb(card, rpp);
31893 - atomic_inc(&vcc->stats->rx_err);
31894 + atomic_inc_unchecked(&vcc->stats->rx_err);
31895 return;
31896 }
31897 if (!atm_charge(vcc, skb->truesize)) {
31898 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31899 __net_timestamp(skb);
31900
31901 vcc->push(vcc, skb);
31902 - atomic_inc(&vcc->stats->rx);
31903 + atomic_inc_unchecked(&vcc->stats->rx);
31904
31905 return;
31906 }
31907 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31908 __net_timestamp(skb);
31909
31910 vcc->push(vcc, skb);
31911 - atomic_inc(&vcc->stats->rx);
31912 + atomic_inc_unchecked(&vcc->stats->rx);
31913
31914 if (skb->truesize > SAR_FB_SIZE_3)
31915 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
31916 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
31917 if (vcc->qos.aal != ATM_AAL0) {
31918 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
31919 card->name, vpi, vci);
31920 - atomic_inc(&vcc->stats->rx_drop);
31921 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31922 goto drop;
31923 }
31924
31925 if ((sb = dev_alloc_skb(64)) == NULL) {
31926 printk("%s: Can't allocate buffers for AAL0.\n",
31927 card->name);
31928 - atomic_inc(&vcc->stats->rx_err);
31929 + atomic_inc_unchecked(&vcc->stats->rx_err);
31930 goto drop;
31931 }
31932
31933 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
31934 ATM_SKB(sb)->vcc = vcc;
31935 __net_timestamp(sb);
31936 vcc->push(vcc, sb);
31937 - atomic_inc(&vcc->stats->rx);
31938 + atomic_inc_unchecked(&vcc->stats->rx);
31939
31940 drop:
31941 skb_pull(queue, 64);
31942 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31943
31944 if (vc == NULL) {
31945 printk("%s: NULL connection in send().\n", card->name);
31946 - atomic_inc(&vcc->stats->tx_err);
31947 + atomic_inc_unchecked(&vcc->stats->tx_err);
31948 dev_kfree_skb(skb);
31949 return -EINVAL;
31950 }
31951 if (!test_bit(VCF_TX, &vc->flags)) {
31952 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
31953 - atomic_inc(&vcc->stats->tx_err);
31954 + atomic_inc_unchecked(&vcc->stats->tx_err);
31955 dev_kfree_skb(skb);
31956 return -EINVAL;
31957 }
31958 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31959 break;
31960 default:
31961 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
31962 - atomic_inc(&vcc->stats->tx_err);
31963 + atomic_inc_unchecked(&vcc->stats->tx_err);
31964 dev_kfree_skb(skb);
31965 return -EINVAL;
31966 }
31967
31968 if (skb_shinfo(skb)->nr_frags != 0) {
31969 printk("%s: No scatter-gather yet.\n", card->name);
31970 - atomic_inc(&vcc->stats->tx_err);
31971 + atomic_inc_unchecked(&vcc->stats->tx_err);
31972 dev_kfree_skb(skb);
31973 return -EINVAL;
31974 }
31975 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31976
31977 err = queue_skb(card, vc, skb, oam);
31978 if (err) {
31979 - atomic_inc(&vcc->stats->tx_err);
31980 + atomic_inc_unchecked(&vcc->stats->tx_err);
31981 dev_kfree_skb(skb);
31982 return err;
31983 }
31984 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
31985 skb = dev_alloc_skb(64);
31986 if (!skb) {
31987 printk("%s: Out of memory in send_oam().\n", card->name);
31988 - atomic_inc(&vcc->stats->tx_err);
31989 + atomic_inc_unchecked(&vcc->stats->tx_err);
31990 return -ENOMEM;
31991 }
31992 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
31993 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
31994 index 4217f29..88f547a 100644
31995 --- a/drivers/atm/iphase.c
31996 +++ b/drivers/atm/iphase.c
31997 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
31998 status = (u_short) (buf_desc_ptr->desc_mode);
31999 if (status & (RX_CER | RX_PTE | RX_OFL))
32000 {
32001 - atomic_inc(&vcc->stats->rx_err);
32002 + atomic_inc_unchecked(&vcc->stats->rx_err);
32003 IF_ERR(printk("IA: bad packet, dropping it");)
32004 if (status & RX_CER) {
32005 IF_ERR(printk(" cause: packet CRC error\n");)
32006 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32007 len = dma_addr - buf_addr;
32008 if (len > iadev->rx_buf_sz) {
32009 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32010 - atomic_inc(&vcc->stats->rx_err);
32011 + atomic_inc_unchecked(&vcc->stats->rx_err);
32012 goto out_free_desc;
32013 }
32014
32015 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32016 ia_vcc = INPH_IA_VCC(vcc);
32017 if (ia_vcc == NULL)
32018 {
32019 - atomic_inc(&vcc->stats->rx_err);
32020 + atomic_inc_unchecked(&vcc->stats->rx_err);
32021 atm_return(vcc, skb->truesize);
32022 dev_kfree_skb_any(skb);
32023 goto INCR_DLE;
32024 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32025 if ((length > iadev->rx_buf_sz) || (length >
32026 (skb->len - sizeof(struct cpcs_trailer))))
32027 {
32028 - atomic_inc(&vcc->stats->rx_err);
32029 + atomic_inc_unchecked(&vcc->stats->rx_err);
32030 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32031 length, skb->len);)
32032 atm_return(vcc, skb->truesize);
32033 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32034
32035 IF_RX(printk("rx_dle_intr: skb push");)
32036 vcc->push(vcc,skb);
32037 - atomic_inc(&vcc->stats->rx);
32038 + atomic_inc_unchecked(&vcc->stats->rx);
32039 iadev->rx_pkt_cnt++;
32040 }
32041 INCR_DLE:
32042 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32043 {
32044 struct k_sonet_stats *stats;
32045 stats = &PRIV(_ia_dev[board])->sonet_stats;
32046 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32047 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32048 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32049 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32050 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32051 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32052 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32053 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32054 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32055 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32056 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32057 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32058 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32059 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32060 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32061 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32062 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32063 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32064 }
32065 ia_cmds.status = 0;
32066 break;
32067 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32068 if ((desc == 0) || (desc > iadev->num_tx_desc))
32069 {
32070 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32071 - atomic_inc(&vcc->stats->tx);
32072 + atomic_inc_unchecked(&vcc->stats->tx);
32073 if (vcc->pop)
32074 vcc->pop(vcc, skb);
32075 else
32076 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32077 ATM_DESC(skb) = vcc->vci;
32078 skb_queue_tail(&iadev->tx_dma_q, skb);
32079
32080 - atomic_inc(&vcc->stats->tx);
32081 + atomic_inc_unchecked(&vcc->stats->tx);
32082 iadev->tx_pkt_cnt++;
32083 /* Increment transaction counter */
32084 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32085
32086 #if 0
32087 /* add flow control logic */
32088 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32089 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32090 if (iavcc->vc_desc_cnt > 10) {
32091 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32092 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32093 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32094 index fa7d701..1e404c7 100644
32095 --- a/drivers/atm/lanai.c
32096 +++ b/drivers/atm/lanai.c
32097 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32098 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32099 lanai_endtx(lanai, lvcc);
32100 lanai_free_skb(lvcc->tx.atmvcc, skb);
32101 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32102 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32103 }
32104
32105 /* Try to fill the buffer - don't call unless there is backlog */
32106 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32107 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32108 __net_timestamp(skb);
32109 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32110 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32111 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32112 out:
32113 lvcc->rx.buf.ptr = end;
32114 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32115 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32116 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32117 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32118 lanai->stats.service_rxnotaal5++;
32119 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32120 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32121 return 0;
32122 }
32123 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32124 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32125 int bytes;
32126 read_unlock(&vcc_sklist_lock);
32127 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32128 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32129 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32130 lvcc->stats.x.aal5.service_trash++;
32131 bytes = (SERVICE_GET_END(s) * 16) -
32132 (((unsigned long) lvcc->rx.buf.ptr) -
32133 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32134 }
32135 if (s & SERVICE_STREAM) {
32136 read_unlock(&vcc_sklist_lock);
32137 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32138 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32139 lvcc->stats.x.aal5.service_stream++;
32140 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32141 "PDU on VCI %d!\n", lanai->number, vci);
32142 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32143 return 0;
32144 }
32145 DPRINTK("got rx crc error on vci %d\n", vci);
32146 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32147 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32148 lvcc->stats.x.aal5.service_rxcrc++;
32149 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32150 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32151 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32152 index ed1d2b7..8cffc1f 100644
32153 --- a/drivers/atm/nicstar.c
32154 +++ b/drivers/atm/nicstar.c
32155 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32156 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32157 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32158 card->index);
32159 - atomic_inc(&vcc->stats->tx_err);
32160 + atomic_inc_unchecked(&vcc->stats->tx_err);
32161 dev_kfree_skb_any(skb);
32162 return -EINVAL;
32163 }
32164 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32165 if (!vc->tx) {
32166 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
32167 card->index);
32168 - atomic_inc(&vcc->stats->tx_err);
32169 + atomic_inc_unchecked(&vcc->stats->tx_err);
32170 dev_kfree_skb_any(skb);
32171 return -EINVAL;
32172 }
32173 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32174 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32175 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
32176 card->index);
32177 - atomic_inc(&vcc->stats->tx_err);
32178 + atomic_inc_unchecked(&vcc->stats->tx_err);
32179 dev_kfree_skb_any(skb);
32180 return -EINVAL;
32181 }
32182
32183 if (skb_shinfo(skb)->nr_frags != 0) {
32184 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32185 - atomic_inc(&vcc->stats->tx_err);
32186 + atomic_inc_unchecked(&vcc->stats->tx_err);
32187 dev_kfree_skb_any(skb);
32188 return -EINVAL;
32189 }
32190 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32191 }
32192
32193 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32194 - atomic_inc(&vcc->stats->tx_err);
32195 + atomic_inc_unchecked(&vcc->stats->tx_err);
32196 dev_kfree_skb_any(skb);
32197 return -EIO;
32198 }
32199 - atomic_inc(&vcc->stats->tx);
32200 + atomic_inc_unchecked(&vcc->stats->tx);
32201
32202 return 0;
32203 }
32204 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32205 printk
32206 ("nicstar%d: Can't allocate buffers for aal0.\n",
32207 card->index);
32208 - atomic_add(i, &vcc->stats->rx_drop);
32209 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
32210 break;
32211 }
32212 if (!atm_charge(vcc, sb->truesize)) {
32213 RXPRINTK
32214 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32215 card->index);
32216 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32217 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32218 dev_kfree_skb_any(sb);
32219 break;
32220 }
32221 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32222 ATM_SKB(sb)->vcc = vcc;
32223 __net_timestamp(sb);
32224 vcc->push(vcc, sb);
32225 - atomic_inc(&vcc->stats->rx);
32226 + atomic_inc_unchecked(&vcc->stats->rx);
32227 cell += ATM_CELL_PAYLOAD;
32228 }
32229
32230 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32231 if (iovb == NULL) {
32232 printk("nicstar%d: Out of iovec buffers.\n",
32233 card->index);
32234 - atomic_inc(&vcc->stats->rx_drop);
32235 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32236 recycle_rx_buf(card, skb);
32237 return;
32238 }
32239 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32240 small or large buffer itself. */
32241 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32242 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32243 - atomic_inc(&vcc->stats->rx_err);
32244 + atomic_inc_unchecked(&vcc->stats->rx_err);
32245 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32246 NS_MAX_IOVECS);
32247 NS_PRV_IOVCNT(iovb) = 0;
32248 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32249 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32250 card->index);
32251 which_list(card, skb);
32252 - atomic_inc(&vcc->stats->rx_err);
32253 + atomic_inc_unchecked(&vcc->stats->rx_err);
32254 recycle_rx_buf(card, skb);
32255 vc->rx_iov = NULL;
32256 recycle_iov_buf(card, iovb);
32257 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32258 ("nicstar%d: Expected a large buffer, and this is not one.\n",
32259 card->index);
32260 which_list(card, skb);
32261 - atomic_inc(&vcc->stats->rx_err);
32262 + atomic_inc_unchecked(&vcc->stats->rx_err);
32263 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32264 NS_PRV_IOVCNT(iovb));
32265 vc->rx_iov = NULL;
32266 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32267 printk(" - PDU size mismatch.\n");
32268 else
32269 printk(".\n");
32270 - atomic_inc(&vcc->stats->rx_err);
32271 + atomic_inc_unchecked(&vcc->stats->rx_err);
32272 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32273 NS_PRV_IOVCNT(iovb));
32274 vc->rx_iov = NULL;
32275 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32276 /* skb points to a small buffer */
32277 if (!atm_charge(vcc, skb->truesize)) {
32278 push_rxbufs(card, skb);
32279 - atomic_inc(&vcc->stats->rx_drop);
32280 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32281 } else {
32282 skb_put(skb, len);
32283 dequeue_sm_buf(card, skb);
32284 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32285 ATM_SKB(skb)->vcc = vcc;
32286 __net_timestamp(skb);
32287 vcc->push(vcc, skb);
32288 - atomic_inc(&vcc->stats->rx);
32289 + atomic_inc_unchecked(&vcc->stats->rx);
32290 }
32291 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32292 struct sk_buff *sb;
32293 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32294 if (len <= NS_SMBUFSIZE) {
32295 if (!atm_charge(vcc, sb->truesize)) {
32296 push_rxbufs(card, sb);
32297 - atomic_inc(&vcc->stats->rx_drop);
32298 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32299 } else {
32300 skb_put(sb, len);
32301 dequeue_sm_buf(card, sb);
32302 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32303 ATM_SKB(sb)->vcc = vcc;
32304 __net_timestamp(sb);
32305 vcc->push(vcc, sb);
32306 - atomic_inc(&vcc->stats->rx);
32307 + atomic_inc_unchecked(&vcc->stats->rx);
32308 }
32309
32310 push_rxbufs(card, skb);
32311 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32312
32313 if (!atm_charge(vcc, skb->truesize)) {
32314 push_rxbufs(card, skb);
32315 - atomic_inc(&vcc->stats->rx_drop);
32316 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32317 } else {
32318 dequeue_lg_buf(card, skb);
32319 #ifdef NS_USE_DESTRUCTORS
32320 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32321 ATM_SKB(skb)->vcc = vcc;
32322 __net_timestamp(skb);
32323 vcc->push(vcc, skb);
32324 - atomic_inc(&vcc->stats->rx);
32325 + atomic_inc_unchecked(&vcc->stats->rx);
32326 }
32327
32328 push_rxbufs(card, sb);
32329 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32330 printk
32331 ("nicstar%d: Out of huge buffers.\n",
32332 card->index);
32333 - atomic_inc(&vcc->stats->rx_drop);
32334 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32335 recycle_iovec_rx_bufs(card,
32336 (struct iovec *)
32337 iovb->data,
32338 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32339 card->hbpool.count++;
32340 } else
32341 dev_kfree_skb_any(hb);
32342 - atomic_inc(&vcc->stats->rx_drop);
32343 + atomic_inc_unchecked(&vcc->stats->rx_drop);
32344 } else {
32345 /* Copy the small buffer to the huge buffer */
32346 sb = (struct sk_buff *)iov->iov_base;
32347 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32348 #endif /* NS_USE_DESTRUCTORS */
32349 __net_timestamp(hb);
32350 vcc->push(vcc, hb);
32351 - atomic_inc(&vcc->stats->rx);
32352 + atomic_inc_unchecked(&vcc->stats->rx);
32353 }
32354 }
32355
32356 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
32357 index 0474a89..06ea4a1 100644
32358 --- a/drivers/atm/solos-pci.c
32359 +++ b/drivers/atm/solos-pci.c
32360 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
32361 }
32362 atm_charge(vcc, skb->truesize);
32363 vcc->push(vcc, skb);
32364 - atomic_inc(&vcc->stats->rx);
32365 + atomic_inc_unchecked(&vcc->stats->rx);
32366 break;
32367
32368 case PKT_STATUS:
32369 @@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
32370 vcc = SKB_CB(oldskb)->vcc;
32371
32372 if (vcc) {
32373 - atomic_inc(&vcc->stats->tx);
32374 + atomic_inc_unchecked(&vcc->stats->tx);
32375 solos_pop(vcc, oldskb);
32376 } else {
32377 dev_kfree_skb_irq(oldskb);
32378 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
32379 index 0215934..ce9f5b1 100644
32380 --- a/drivers/atm/suni.c
32381 +++ b/drivers/atm/suni.c
32382 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
32383
32384
32385 #define ADD_LIMITED(s,v) \
32386 - atomic_add((v),&stats->s); \
32387 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
32388 + atomic_add_unchecked((v),&stats->s); \
32389 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
32390
32391
32392 static void suni_hz(unsigned long from_timer)
32393 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
32394 index 5120a96..e2572bd 100644
32395 --- a/drivers/atm/uPD98402.c
32396 +++ b/drivers/atm/uPD98402.c
32397 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
32398 struct sonet_stats tmp;
32399 int error = 0;
32400
32401 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32402 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32403 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
32404 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
32405 if (zero && !error) {
32406 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
32407
32408
32409 #define ADD_LIMITED(s,v) \
32410 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
32411 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
32412 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32413 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
32414 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
32415 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32416
32417
32418 static void stat_event(struct atm_dev *dev)
32419 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
32420 if (reason & uPD98402_INT_PFM) stat_event(dev);
32421 if (reason & uPD98402_INT_PCO) {
32422 (void) GET(PCOCR); /* clear interrupt cause */
32423 - atomic_add(GET(HECCT),
32424 + atomic_add_unchecked(GET(HECCT),
32425 &PRIV(dev)->sonet_stats.uncorr_hcs);
32426 }
32427 if ((reason & uPD98402_INT_RFO) &&
32428 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
32429 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
32430 uPD98402_INT_LOS),PIMR); /* enable them */
32431 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
32432 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32433 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
32434 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
32435 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32436 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
32437 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
32438 return 0;
32439 }
32440
32441 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
32442 index 969c3c2..9b72956 100644
32443 --- a/drivers/atm/zatm.c
32444 +++ b/drivers/atm/zatm.c
32445 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32446 }
32447 if (!size) {
32448 dev_kfree_skb_irq(skb);
32449 - if (vcc) atomic_inc(&vcc->stats->rx_err);
32450 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
32451 continue;
32452 }
32453 if (!atm_charge(vcc,skb->truesize)) {
32454 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32455 skb->len = size;
32456 ATM_SKB(skb)->vcc = vcc;
32457 vcc->push(vcc,skb);
32458 - atomic_inc(&vcc->stats->rx);
32459 + atomic_inc_unchecked(&vcc->stats->rx);
32460 }
32461 zout(pos & 0xffff,MTA(mbx));
32462 #if 0 /* probably a stupid idea */
32463 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
32464 skb_queue_head(&zatm_vcc->backlog,skb);
32465 break;
32466 }
32467 - atomic_inc(&vcc->stats->tx);
32468 + atomic_inc_unchecked(&vcc->stats->tx);
32469 wake_up(&zatm_vcc->tx_wait);
32470 }
32471
32472 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
32473 index 6856303..0602d70 100644
32474 --- a/drivers/base/bus.c
32475 +++ b/drivers/base/bus.c
32476 @@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
32477 return -EINVAL;
32478
32479 mutex_lock(&subsys->p->mutex);
32480 - list_add_tail(&sif->node, &subsys->p->interfaces);
32481 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
32482 if (sif->add_dev) {
32483 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32484 while ((dev = subsys_dev_iter_next(&iter)))
32485 @@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
32486 subsys = sif->subsys;
32487
32488 mutex_lock(&subsys->p->mutex);
32489 - list_del_init(&sif->node);
32490 + pax_list_del_init((struct list_head *)&sif->node);
32491 if (sif->remove_dev) {
32492 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32493 while ((dev = subsys_dev_iter_next(&iter)))
32494 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
32495 index 17cf7ca..7e553e1 100644
32496 --- a/drivers/base/devtmpfs.c
32497 +++ b/drivers/base/devtmpfs.c
32498 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
32499 if (!thread)
32500 return 0;
32501
32502 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
32503 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
32504 if (err)
32505 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
32506 else
32507 diff --git a/drivers/base/node.c b/drivers/base/node.c
32508 index fac124a..66bd4ab 100644
32509 --- a/drivers/base/node.c
32510 +++ b/drivers/base/node.c
32511 @@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
32512 struct node_attr {
32513 struct device_attribute attr;
32514 enum node_states state;
32515 -};
32516 +} __do_const;
32517
32518 static ssize_t show_node_state(struct device *dev,
32519 struct device_attribute *attr, char *buf)
32520 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
32521 index acc3a8d..981c236 100644
32522 --- a/drivers/base/power/domain.c
32523 +++ b/drivers/base/power/domain.c
32524 @@ -1851,7 +1851,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
32525 {
32526 struct cpuidle_driver *cpuidle_drv;
32527 struct gpd_cpu_data *cpu_data;
32528 - struct cpuidle_state *idle_state;
32529 + cpuidle_state_no_const *idle_state;
32530 int ret = 0;
32531
32532 if (IS_ERR_OR_NULL(genpd) || state < 0)
32533 @@ -1919,7 +1919,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
32534 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
32535 {
32536 struct gpd_cpu_data *cpu_data;
32537 - struct cpuidle_state *idle_state;
32538 + cpuidle_state_no_const *idle_state;
32539 int ret = 0;
32540
32541 if (IS_ERR_OR_NULL(genpd))
32542 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
32543 index e6ee5e8..98ad7fc 100644
32544 --- a/drivers/base/power/wakeup.c
32545 +++ b/drivers/base/power/wakeup.c
32546 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
32547 * They need to be modified together atomically, so it's better to use one
32548 * atomic variable to hold them both.
32549 */
32550 -static atomic_t combined_event_count = ATOMIC_INIT(0);
32551 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
32552
32553 #define IN_PROGRESS_BITS (sizeof(int) * 4)
32554 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
32555
32556 static void split_counters(unsigned int *cnt, unsigned int *inpr)
32557 {
32558 - unsigned int comb = atomic_read(&combined_event_count);
32559 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
32560
32561 *cnt = (comb >> IN_PROGRESS_BITS);
32562 *inpr = comb & MAX_IN_PROGRESS;
32563 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
32564 ws->start_prevent_time = ws->last_time;
32565
32566 /* Increment the counter of events in progress. */
32567 - cec = atomic_inc_return(&combined_event_count);
32568 + cec = atomic_inc_return_unchecked(&combined_event_count);
32569
32570 trace_wakeup_source_activate(ws->name, cec);
32571 }
32572 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
32573 * Increment the counter of registered wakeup events and decrement the
32574 * couter of wakeup events in progress simultaneously.
32575 */
32576 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
32577 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
32578 trace_wakeup_source_deactivate(ws->name, cec);
32579
32580 split_counters(&cnt, &inpr);
32581 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
32582 index e8d11b6..7b1b36f 100644
32583 --- a/drivers/base/syscore.c
32584 +++ b/drivers/base/syscore.c
32585 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
32586 void register_syscore_ops(struct syscore_ops *ops)
32587 {
32588 mutex_lock(&syscore_ops_lock);
32589 - list_add_tail(&ops->node, &syscore_ops_list);
32590 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
32591 mutex_unlock(&syscore_ops_lock);
32592 }
32593 EXPORT_SYMBOL_GPL(register_syscore_ops);
32594 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
32595 void unregister_syscore_ops(struct syscore_ops *ops)
32596 {
32597 mutex_lock(&syscore_ops_lock);
32598 - list_del(&ops->node);
32599 + pax_list_del((struct list_head *)&ops->node);
32600 mutex_unlock(&syscore_ops_lock);
32601 }
32602 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
32603 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
32604 index ade58bc..867143d 100644
32605 --- a/drivers/block/cciss.c
32606 +++ b/drivers/block/cciss.c
32607 @@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
32608 int err;
32609 u32 cp;
32610
32611 + memset(&arg64, 0, sizeof(arg64));
32612 +
32613 err = 0;
32614 err |=
32615 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
32616 @@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
32617 while (!list_empty(&h->reqQ)) {
32618 c = list_entry(h->reqQ.next, CommandList_struct, list);
32619 /* can't do anything if fifo is full */
32620 - if ((h->access.fifo_full(h))) {
32621 + if ((h->access->fifo_full(h))) {
32622 dev_warn(&h->pdev->dev, "fifo full\n");
32623 break;
32624 }
32625 @@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
32626 h->Qdepth--;
32627
32628 /* Tell the controller execute command */
32629 - h->access.submit_command(h, c);
32630 + h->access->submit_command(h, c);
32631
32632 /* Put job onto the completed Q */
32633 addQ(&h->cmpQ, c);
32634 @@ -3441,17 +3443,17 @@ startio:
32635
32636 static inline unsigned long get_next_completion(ctlr_info_t *h)
32637 {
32638 - return h->access.command_completed(h);
32639 + return h->access->command_completed(h);
32640 }
32641
32642 static inline int interrupt_pending(ctlr_info_t *h)
32643 {
32644 - return h->access.intr_pending(h);
32645 + return h->access->intr_pending(h);
32646 }
32647
32648 static inline long interrupt_not_for_us(ctlr_info_t *h)
32649 {
32650 - return ((h->access.intr_pending(h) == 0) ||
32651 + return ((h->access->intr_pending(h) == 0) ||
32652 (h->interrupts_enabled == 0));
32653 }
32654
32655 @@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
32656 u32 a;
32657
32658 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
32659 - return h->access.command_completed(h);
32660 + return h->access->command_completed(h);
32661
32662 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
32663 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
32664 @@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
32665 trans_support & CFGTBL_Trans_use_short_tags);
32666
32667 /* Change the access methods to the performant access methods */
32668 - h->access = SA5_performant_access;
32669 + h->access = &SA5_performant_access;
32670 h->transMethod = CFGTBL_Trans_Performant;
32671
32672 return;
32673 @@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
32674 if (prod_index < 0)
32675 return -ENODEV;
32676 h->product_name = products[prod_index].product_name;
32677 - h->access = *(products[prod_index].access);
32678 + h->access = products[prod_index].access;
32679
32680 if (cciss_board_disabled(h)) {
32681 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
32682 @@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
32683 }
32684
32685 /* make sure the board interrupts are off */
32686 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32687 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32688 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
32689 if (rc)
32690 goto clean2;
32691 @@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
32692 * fake ones to scoop up any residual completions.
32693 */
32694 spin_lock_irqsave(&h->lock, flags);
32695 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32696 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32697 spin_unlock_irqrestore(&h->lock, flags);
32698 free_irq(h->intr[h->intr_mode], h);
32699 rc = cciss_request_irq(h, cciss_msix_discard_completions,
32700 @@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
32701 dev_info(&h->pdev->dev, "Board READY.\n");
32702 dev_info(&h->pdev->dev,
32703 "Waiting for stale completions to drain.\n");
32704 - h->access.set_intr_mask(h, CCISS_INTR_ON);
32705 + h->access->set_intr_mask(h, CCISS_INTR_ON);
32706 msleep(10000);
32707 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32708 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32709
32710 rc = controller_reset_failed(h->cfgtable);
32711 if (rc)
32712 @@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
32713 cciss_scsi_setup(h);
32714
32715 /* Turn the interrupts on so we can service requests */
32716 - h->access.set_intr_mask(h, CCISS_INTR_ON);
32717 + h->access->set_intr_mask(h, CCISS_INTR_ON);
32718
32719 /* Get the firmware version */
32720 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
32721 @@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
32722 kfree(flush_buf);
32723 if (return_code != IO_OK)
32724 dev_warn(&h->pdev->dev, "Error flushing cache\n");
32725 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32726 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32727 free_irq(h->intr[h->intr_mode], h);
32728 }
32729
32730 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
32731 index 7fda30e..eb5dfe0 100644
32732 --- a/drivers/block/cciss.h
32733 +++ b/drivers/block/cciss.h
32734 @@ -101,7 +101,7 @@ struct ctlr_info
32735 /* information about each logical volume */
32736 drive_info_struct *drv[CISS_MAX_LUN];
32737
32738 - struct access_method access;
32739 + struct access_method *access;
32740
32741 /* queue and queue Info */
32742 struct list_head reqQ;
32743 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
32744 index 3f08713..56a586a 100644
32745 --- a/drivers/block/cpqarray.c
32746 +++ b/drivers/block/cpqarray.c
32747 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32748 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
32749 goto Enomem4;
32750 }
32751 - hba[i]->access.set_intr_mask(hba[i], 0);
32752 + hba[i]->access->set_intr_mask(hba[i], 0);
32753 if (request_irq(hba[i]->intr, do_ida_intr,
32754 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
32755 {
32756 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32757 add_timer(&hba[i]->timer);
32758
32759 /* Enable IRQ now that spinlock and rate limit timer are set up */
32760 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32761 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32762
32763 for(j=0; j<NWD; j++) {
32764 struct gendisk *disk = ida_gendisk[i][j];
32765 @@ -694,7 +694,7 @@ DBGINFO(
32766 for(i=0; i<NR_PRODUCTS; i++) {
32767 if (board_id == products[i].board_id) {
32768 c->product_name = products[i].product_name;
32769 - c->access = *(products[i].access);
32770 + c->access = products[i].access;
32771 break;
32772 }
32773 }
32774 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
32775 hba[ctlr]->intr = intr;
32776 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
32777 hba[ctlr]->product_name = products[j].product_name;
32778 - hba[ctlr]->access = *(products[j].access);
32779 + hba[ctlr]->access = products[j].access;
32780 hba[ctlr]->ctlr = ctlr;
32781 hba[ctlr]->board_id = board_id;
32782 hba[ctlr]->pci_dev = NULL; /* not PCI */
32783 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
32784
32785 while((c = h->reqQ) != NULL) {
32786 /* Can't do anything if we're busy */
32787 - if (h->access.fifo_full(h) == 0)
32788 + if (h->access->fifo_full(h) == 0)
32789 return;
32790
32791 /* Get the first entry from the request Q */
32792 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
32793 h->Qdepth--;
32794
32795 /* Tell the controller to do our bidding */
32796 - h->access.submit_command(h, c);
32797 + h->access->submit_command(h, c);
32798
32799 /* Get onto the completion Q */
32800 addQ(&h->cmpQ, c);
32801 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32802 unsigned long flags;
32803 __u32 a,a1;
32804
32805 - istat = h->access.intr_pending(h);
32806 + istat = h->access->intr_pending(h);
32807 /* Is this interrupt for us? */
32808 if (istat == 0)
32809 return IRQ_NONE;
32810 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32811 */
32812 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
32813 if (istat & FIFO_NOT_EMPTY) {
32814 - while((a = h->access.command_completed(h))) {
32815 + while((a = h->access->command_completed(h))) {
32816 a1 = a; a &= ~3;
32817 if ((c = h->cmpQ) == NULL)
32818 {
32819 @@ -1449,11 +1449,11 @@ static int sendcmd(
32820 /*
32821 * Disable interrupt
32822 */
32823 - info_p->access.set_intr_mask(info_p, 0);
32824 + info_p->access->set_intr_mask(info_p, 0);
32825 /* Make sure there is room in the command FIFO */
32826 /* Actually it should be completely empty at this time. */
32827 for (i = 200000; i > 0; i--) {
32828 - temp = info_p->access.fifo_full(info_p);
32829 + temp = info_p->access->fifo_full(info_p);
32830 if (temp != 0) {
32831 break;
32832 }
32833 @@ -1466,7 +1466,7 @@ DBG(
32834 /*
32835 * Send the cmd
32836 */
32837 - info_p->access.submit_command(info_p, c);
32838 + info_p->access->submit_command(info_p, c);
32839 complete = pollcomplete(ctlr);
32840
32841 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
32842 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
32843 * we check the new geometry. Then turn interrupts back on when
32844 * we're done.
32845 */
32846 - host->access.set_intr_mask(host, 0);
32847 + host->access->set_intr_mask(host, 0);
32848 getgeometry(ctlr);
32849 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
32850 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
32851
32852 for(i=0; i<NWD; i++) {
32853 struct gendisk *disk = ida_gendisk[ctlr][i];
32854 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
32855 /* Wait (up to 2 seconds) for a command to complete */
32856
32857 for (i = 200000; i > 0; i--) {
32858 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
32859 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
32860 if (done == 0) {
32861 udelay(10); /* a short fixed delay */
32862 } else
32863 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
32864 index be73e9d..7fbf140 100644
32865 --- a/drivers/block/cpqarray.h
32866 +++ b/drivers/block/cpqarray.h
32867 @@ -99,7 +99,7 @@ struct ctlr_info {
32868 drv_info_t drv[NWD];
32869 struct proc_dir_entry *proc;
32870
32871 - struct access_method access;
32872 + struct access_method *access;
32873
32874 cmdlist_t *reqQ;
32875 cmdlist_t *cmpQ;
32876 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
32877 index 6b51afa..17e1191 100644
32878 --- a/drivers/block/drbd/drbd_int.h
32879 +++ b/drivers/block/drbd/drbd_int.h
32880 @@ -582,7 +582,7 @@ struct drbd_epoch {
32881 struct drbd_tconn *tconn;
32882 struct list_head list;
32883 unsigned int barrier_nr;
32884 - atomic_t epoch_size; /* increased on every request added. */
32885 + atomic_unchecked_t epoch_size; /* increased on every request added. */
32886 atomic_t active; /* increased on every req. added, and dec on every finished. */
32887 unsigned long flags;
32888 };
32889 @@ -1011,7 +1011,7 @@ struct drbd_conf {
32890 int al_tr_cycle;
32891 int al_tr_pos; /* position of the next transaction in the journal */
32892 wait_queue_head_t seq_wait;
32893 - atomic_t packet_seq;
32894 + atomic_unchecked_t packet_seq;
32895 unsigned int peer_seq;
32896 spinlock_t peer_seq_lock;
32897 unsigned int minor;
32898 @@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
32899 char __user *uoptval;
32900 int err;
32901
32902 - uoptval = (char __user __force *)optval;
32903 + uoptval = (char __force_user *)optval;
32904
32905 set_fs(KERNEL_DS);
32906 if (level == SOL_SOCKET)
32907 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
32908 index 8c13eeb..217adee 100644
32909 --- a/drivers/block/drbd/drbd_main.c
32910 +++ b/drivers/block/drbd/drbd_main.c
32911 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
32912 p->sector = sector;
32913 p->block_id = block_id;
32914 p->blksize = blksize;
32915 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
32916 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
32917 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
32918 }
32919
32920 @@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
32921 return -EIO;
32922 p->sector = cpu_to_be64(req->i.sector);
32923 p->block_id = (unsigned long)req;
32924 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
32925 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
32926 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
32927 if (mdev->state.conn >= C_SYNC_SOURCE &&
32928 mdev->state.conn <= C_PAUSED_SYNC_T)
32929 @@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
32930 {
32931 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
32932
32933 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
32934 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
32935 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
32936 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
32937 kfree(tconn->current_epoch);
32938
32939 idr_destroy(&tconn->volumes);
32940 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
32941 index a9eccfc..f5efe87 100644
32942 --- a/drivers/block/drbd/drbd_receiver.c
32943 +++ b/drivers/block/drbd/drbd_receiver.c
32944 @@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
32945 {
32946 int err;
32947
32948 - atomic_set(&mdev->packet_seq, 0);
32949 + atomic_set_unchecked(&mdev->packet_seq, 0);
32950 mdev->peer_seq = 0;
32951
32952 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
32953 @@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
32954 do {
32955 next_epoch = NULL;
32956
32957 - epoch_size = atomic_read(&epoch->epoch_size);
32958 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
32959
32960 switch (ev & ~EV_CLEANUP) {
32961 case EV_PUT:
32962 @@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
32963 rv = FE_DESTROYED;
32964 } else {
32965 epoch->flags = 0;
32966 - atomic_set(&epoch->epoch_size, 0);
32967 + atomic_set_unchecked(&epoch->epoch_size, 0);
32968 /* atomic_set(&epoch->active, 0); is already zero */
32969 if (rv == FE_STILL_LIVE)
32970 rv = FE_RECYCLED;
32971 @@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
32972 conn_wait_active_ee_empty(tconn);
32973 drbd_flush(tconn);
32974
32975 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
32976 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
32977 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
32978 if (epoch)
32979 break;
32980 @@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
32981 }
32982
32983 epoch->flags = 0;
32984 - atomic_set(&epoch->epoch_size, 0);
32985 + atomic_set_unchecked(&epoch->epoch_size, 0);
32986 atomic_set(&epoch->active, 0);
32987
32988 spin_lock(&tconn->epoch_lock);
32989 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
32990 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
32991 list_add(&epoch->list, &tconn->current_epoch->list);
32992 tconn->current_epoch = epoch;
32993 tconn->epochs++;
32994 @@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
32995
32996 err = wait_for_and_update_peer_seq(mdev, peer_seq);
32997 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
32998 - atomic_inc(&tconn->current_epoch->epoch_size);
32999 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33000 err2 = drbd_drain_block(mdev, pi->size);
33001 if (!err)
33002 err = err2;
33003 @@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33004
33005 spin_lock(&tconn->epoch_lock);
33006 peer_req->epoch = tconn->current_epoch;
33007 - atomic_inc(&peer_req->epoch->epoch_size);
33008 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33009 atomic_inc(&peer_req->epoch->active);
33010 spin_unlock(&tconn->epoch_lock);
33011
33012 @@ -4346,7 +4346,7 @@ struct data_cmd {
33013 int expect_payload;
33014 size_t pkt_size;
33015 int (*fn)(struct drbd_tconn *, struct packet_info *);
33016 -};
33017 +} __do_const;
33018
33019 static struct data_cmd drbd_cmd_handler[] = {
33020 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33021 @@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33022 if (!list_empty(&tconn->current_epoch->list))
33023 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33024 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33025 - atomic_set(&tconn->current_epoch->epoch_size, 0);
33026 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33027 tconn->send.seen_any_write_yet = false;
33028
33029 conn_info(tconn, "Connection closed\n");
33030 @@ -5222,7 +5222,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33031 struct asender_cmd {
33032 size_t pkt_size;
33033 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33034 -};
33035 +} __do_const;
33036
33037 static struct asender_cmd asender_tbl[] = {
33038 [P_PING] = { 0, got_Ping },
33039 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33040 index ae12512..37fa397 100644
33041 --- a/drivers/block/loop.c
33042 +++ b/drivers/block/loop.c
33043 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
33044 mm_segment_t old_fs = get_fs();
33045
33046 set_fs(get_ds());
33047 - bw = file->f_op->write(file, buf, len, &pos);
33048 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33049 set_fs(old_fs);
33050 if (likely(bw == len))
33051 return 0;
33052 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33053 index d620b44..587561e 100644
33054 --- a/drivers/cdrom/cdrom.c
33055 +++ b/drivers/cdrom/cdrom.c
33056 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33057 ENSURE(reset, CDC_RESET);
33058 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33059 cdi->mc_flags = 0;
33060 - cdo->n_minors = 0;
33061 cdi->options = CDO_USE_FFLAGS;
33062
33063 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33064 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33065 else
33066 cdi->cdda_method = CDDA_OLD;
33067
33068 - if (!cdo->generic_packet)
33069 - cdo->generic_packet = cdrom_dummy_generic_packet;
33070 + if (!cdo->generic_packet) {
33071 + pax_open_kernel();
33072 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33073 + pax_close_kernel();
33074 + }
33075
33076 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33077 mutex_lock(&cdrom_mutex);
33078 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33079 if (cdi->exit)
33080 cdi->exit(cdi);
33081
33082 - cdi->ops->n_minors--;
33083 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33084 }
33085
33086 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33087 index d59cdcb..11afddf 100644
33088 --- a/drivers/cdrom/gdrom.c
33089 +++ b/drivers/cdrom/gdrom.c
33090 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33091 .audio_ioctl = gdrom_audio_ioctl,
33092 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33093 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33094 - .n_minors = 1,
33095 };
33096
33097 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33098 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33099 index 72bedad..8181ce1 100644
33100 --- a/drivers/char/Kconfig
33101 +++ b/drivers/char/Kconfig
33102 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33103
33104 config DEVKMEM
33105 bool "/dev/kmem virtual device support"
33106 - default y
33107 + default n
33108 + depends on !GRKERNSEC_KMEM
33109 help
33110 Say Y here if you want to support the /dev/kmem device. The
33111 /dev/kmem device is rarely used, but can be used for certain
33112 @@ -581,6 +582,7 @@ config DEVPORT
33113 bool
33114 depends on !M68K
33115 depends on ISA || PCI
33116 + depends on !GRKERNSEC_KMEM
33117 default y
33118
33119 source "drivers/s390/char/Kconfig"
33120 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33121 index 2e04433..22afc64 100644
33122 --- a/drivers/char/agp/frontend.c
33123 +++ b/drivers/char/agp/frontend.c
33124 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33125 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33126 return -EFAULT;
33127
33128 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33129 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33130 return -EFAULT;
33131
33132 client = agp_find_client_by_pid(reserve.pid);
33133 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33134 index 21cb980..f15107c 100644
33135 --- a/drivers/char/genrtc.c
33136 +++ b/drivers/char/genrtc.c
33137 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
33138 switch (cmd) {
33139
33140 case RTC_PLL_GET:
33141 + memset(&pll, 0, sizeof(pll));
33142 if (get_rtc_pll(&pll))
33143 return -EINVAL;
33144 else
33145 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33146 index fe6d4be..89f32100 100644
33147 --- a/drivers/char/hpet.c
33148 +++ b/drivers/char/hpet.c
33149 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33150 }
33151
33152 static int
33153 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33154 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33155 struct hpet_info *info)
33156 {
33157 struct hpet_timer __iomem *timer;
33158 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33159 index 053201b0..8335cce 100644
33160 --- a/drivers/char/ipmi/ipmi_msghandler.c
33161 +++ b/drivers/char/ipmi/ipmi_msghandler.c
33162 @@ -420,7 +420,7 @@ struct ipmi_smi {
33163 struct proc_dir_entry *proc_dir;
33164 char proc_dir_name[10];
33165
33166 - atomic_t stats[IPMI_NUM_STATS];
33167 + atomic_unchecked_t stats[IPMI_NUM_STATS];
33168
33169 /*
33170 * run_to_completion duplicate of smb_info, smi_info
33171 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33172
33173
33174 #define ipmi_inc_stat(intf, stat) \
33175 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
33176 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
33177 #define ipmi_get_stat(intf, stat) \
33178 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
33179 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
33180
33181 static int is_lan_addr(struct ipmi_addr *addr)
33182 {
33183 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
33184 INIT_LIST_HEAD(&intf->cmd_rcvrs);
33185 init_waitqueue_head(&intf->waitq);
33186 for (i = 0; i < IPMI_NUM_STATS; i++)
33187 - atomic_set(&intf->stats[i], 0);
33188 + atomic_set_unchecked(&intf->stats[i], 0);
33189
33190 intf->proc_dir = NULL;
33191
33192 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
33193 index 1c7fdcd..4899100 100644
33194 --- a/drivers/char/ipmi/ipmi_si_intf.c
33195 +++ b/drivers/char/ipmi/ipmi_si_intf.c
33196 @@ -275,7 +275,7 @@ struct smi_info {
33197 unsigned char slave_addr;
33198
33199 /* Counters and things for the proc filesystem. */
33200 - atomic_t stats[SI_NUM_STATS];
33201 + atomic_unchecked_t stats[SI_NUM_STATS];
33202
33203 struct task_struct *thread;
33204
33205 @@ -284,9 +284,9 @@ struct smi_info {
33206 };
33207
33208 #define smi_inc_stat(smi, stat) \
33209 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
33210 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
33211 #define smi_get_stat(smi, stat) \
33212 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
33213 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
33214
33215 #define SI_MAX_PARMS 4
33216
33217 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
33218 atomic_set(&new_smi->req_events, 0);
33219 new_smi->run_to_completion = 0;
33220 for (i = 0; i < SI_NUM_STATS; i++)
33221 - atomic_set(&new_smi->stats[i], 0);
33222 + atomic_set_unchecked(&new_smi->stats[i], 0);
33223
33224 new_smi->interrupt_disabled = 1;
33225 atomic_set(&new_smi->stop_operation, 0);
33226 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
33227 index c6fa3bc..4ca3e42 100644
33228 --- a/drivers/char/mem.c
33229 +++ b/drivers/char/mem.c
33230 @@ -18,6 +18,7 @@
33231 #include <linux/raw.h>
33232 #include <linux/tty.h>
33233 #include <linux/capability.h>
33234 +#include <linux/security.h>
33235 #include <linux/ptrace.h>
33236 #include <linux/device.h>
33237 #include <linux/highmem.h>
33238 @@ -37,6 +38,10 @@
33239
33240 #define DEVPORT_MINOR 4
33241
33242 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33243 +extern const struct file_operations grsec_fops;
33244 +#endif
33245 +
33246 static inline unsigned long size_inside_page(unsigned long start,
33247 unsigned long size)
33248 {
33249 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33250
33251 while (cursor < to) {
33252 if (!devmem_is_allowed(pfn)) {
33253 +#ifdef CONFIG_GRKERNSEC_KMEM
33254 + gr_handle_mem_readwrite(from, to);
33255 +#else
33256 printk(KERN_INFO
33257 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
33258 current->comm, from, to);
33259 +#endif
33260 return 0;
33261 }
33262 cursor += PAGE_SIZE;
33263 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33264 }
33265 return 1;
33266 }
33267 +#elif defined(CONFIG_GRKERNSEC_KMEM)
33268 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33269 +{
33270 + return 0;
33271 +}
33272 #else
33273 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33274 {
33275 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33276
33277 while (count > 0) {
33278 unsigned long remaining;
33279 + char *temp;
33280
33281 sz = size_inside_page(p, count);
33282
33283 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33284 if (!ptr)
33285 return -EFAULT;
33286
33287 - remaining = copy_to_user(buf, ptr, sz);
33288 +#ifdef CONFIG_PAX_USERCOPY
33289 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33290 + if (!temp) {
33291 + unxlate_dev_mem_ptr(p, ptr);
33292 + return -ENOMEM;
33293 + }
33294 + memcpy(temp, ptr, sz);
33295 +#else
33296 + temp = ptr;
33297 +#endif
33298 +
33299 + remaining = copy_to_user(buf, temp, sz);
33300 +
33301 +#ifdef CONFIG_PAX_USERCOPY
33302 + kfree(temp);
33303 +#endif
33304 +
33305 unxlate_dev_mem_ptr(p, ptr);
33306 if (remaining)
33307 return -EFAULT;
33308 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33309 size_t count, loff_t *ppos)
33310 {
33311 unsigned long p = *ppos;
33312 - ssize_t low_count, read, sz;
33313 + ssize_t low_count, read, sz, err = 0;
33314 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
33315 - int err = 0;
33316
33317 read = 0;
33318 if (p < (unsigned long) high_memory) {
33319 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33320 }
33321 #endif
33322 while (low_count > 0) {
33323 + char *temp;
33324 +
33325 sz = size_inside_page(p, low_count);
33326
33327 /*
33328 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33329 */
33330 kbuf = xlate_dev_kmem_ptr((char *)p);
33331
33332 - if (copy_to_user(buf, kbuf, sz))
33333 +#ifdef CONFIG_PAX_USERCOPY
33334 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33335 + if (!temp)
33336 + return -ENOMEM;
33337 + memcpy(temp, kbuf, sz);
33338 +#else
33339 + temp = kbuf;
33340 +#endif
33341 +
33342 + err = copy_to_user(buf, temp, sz);
33343 +
33344 +#ifdef CONFIG_PAX_USERCOPY
33345 + kfree(temp);
33346 +#endif
33347 +
33348 + if (err)
33349 return -EFAULT;
33350 buf += sz;
33351 p += sz;
33352 @@ -833,6 +880,9 @@ static const struct memdev {
33353 #ifdef CONFIG_CRASH_DUMP
33354 [12] = { "oldmem", 0, &oldmem_fops, NULL },
33355 #endif
33356 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33357 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
33358 +#endif
33359 };
33360
33361 static int memory_open(struct inode *inode, struct file *filp)
33362 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
33363 index 9df78e2..01ba9ae 100644
33364 --- a/drivers/char/nvram.c
33365 +++ b/drivers/char/nvram.c
33366 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
33367
33368 spin_unlock_irq(&rtc_lock);
33369
33370 - if (copy_to_user(buf, contents, tmp - contents))
33371 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
33372 return -EFAULT;
33373
33374 *ppos = i;
33375 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
33376 index b66eaa0..2619d1b 100644
33377 --- a/drivers/char/pcmcia/synclink_cs.c
33378 +++ b/drivers/char/pcmcia/synclink_cs.c
33379 @@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33380
33381 if (debug_level >= DEBUG_LEVEL_INFO)
33382 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
33383 - __FILE__,__LINE__, info->device_name, port->count);
33384 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
33385
33386 - WARN_ON(!port->count);
33387 + WARN_ON(!atomic_read(&port->count));
33388
33389 if (tty_port_close_start(port, tty, filp) == 0)
33390 goto cleanup;
33391 @@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33392 cleanup:
33393 if (debug_level >= DEBUG_LEVEL_INFO)
33394 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
33395 - tty->driver->name, port->count);
33396 + tty->driver->name, atomic_read(&port->count));
33397 }
33398
33399 /* Wait until the transmitter is empty.
33400 @@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33401
33402 if (debug_level >= DEBUG_LEVEL_INFO)
33403 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
33404 - __FILE__,__LINE__,tty->driver->name, port->count);
33405 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
33406
33407 /* If port is closing, signal caller to try again */
33408 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
33409 @@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33410 goto cleanup;
33411 }
33412 spin_lock(&port->lock);
33413 - port->count++;
33414 + atomic_inc(&port->count);
33415 spin_unlock(&port->lock);
33416 spin_unlock_irqrestore(&info->netlock, flags);
33417
33418 - if (port->count == 1) {
33419 + if (atomic_read(&port->count) == 1) {
33420 /* 1st open on this device, init hardware */
33421 retval = startup(info, tty);
33422 if (retval < 0)
33423 @@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
33424 unsigned short new_crctype;
33425
33426 /* return error if TTY interface open */
33427 - if (info->port.count)
33428 + if (atomic_read(&info->port.count))
33429 return -EBUSY;
33430
33431 switch (encoding)
33432 @@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
33433
33434 /* arbitrate between network and tty opens */
33435 spin_lock_irqsave(&info->netlock, flags);
33436 - if (info->port.count != 0 || info->netcount != 0) {
33437 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
33438 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
33439 spin_unlock_irqrestore(&info->netlock, flags);
33440 return -EBUSY;
33441 @@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
33442 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
33443
33444 /* return error if TTY interface open */
33445 - if (info->port.count)
33446 + if (atomic_read(&info->port.count))
33447 return -EBUSY;
33448
33449 if (cmd != SIOCWANDEV)
33450 diff --git a/drivers/char/random.c b/drivers/char/random.c
33451 index 57d4b15..253207b 100644
33452 --- a/drivers/char/random.c
33453 +++ b/drivers/char/random.c
33454 @@ -272,8 +272,13 @@
33455 /*
33456 * Configuration information
33457 */
33458 +#ifdef CONFIG_GRKERNSEC_RANDNET
33459 +#define INPUT_POOL_WORDS 512
33460 +#define OUTPUT_POOL_WORDS 128
33461 +#else
33462 #define INPUT_POOL_WORDS 128
33463 #define OUTPUT_POOL_WORDS 32
33464 +#endif
33465 #define SEC_XFER_SIZE 512
33466 #define EXTRACT_SIZE 10
33467
33468 @@ -313,10 +318,17 @@ static struct poolinfo {
33469 int poolwords;
33470 int tap1, tap2, tap3, tap4, tap5;
33471 } poolinfo_table[] = {
33472 +#ifdef CONFIG_GRKERNSEC_RANDNET
33473 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
33474 + { 512, 411, 308, 208, 104, 1 },
33475 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
33476 + { 128, 103, 76, 51, 25, 1 },
33477 +#else
33478 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
33479 { 128, 103, 76, 51, 25, 1 },
33480 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
33481 { 32, 26, 20, 14, 7, 1 },
33482 +#endif
33483 #if 0
33484 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
33485 { 2048, 1638, 1231, 819, 411, 1 },
33486 @@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
33487 input_rotate += i ? 7 : 14;
33488 }
33489
33490 - ACCESS_ONCE(r->input_rotate) = input_rotate;
33491 - ACCESS_ONCE(r->add_ptr) = i;
33492 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
33493 + ACCESS_ONCE_RW(r->add_ptr) = i;
33494 smp_wmb();
33495
33496 if (out)
33497 @@ -1024,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
33498
33499 extract_buf(r, tmp);
33500 i = min_t(int, nbytes, EXTRACT_SIZE);
33501 - if (copy_to_user(buf, tmp, i)) {
33502 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
33503 ret = -EFAULT;
33504 break;
33505 }
33506 @@ -1360,7 +1372,7 @@ EXPORT_SYMBOL(generate_random_uuid);
33507 #include <linux/sysctl.h>
33508
33509 static int min_read_thresh = 8, min_write_thresh;
33510 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
33511 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
33512 static int max_write_thresh = INPUT_POOL_WORDS * 32;
33513 static char sysctl_bootid[16];
33514
33515 @@ -1376,7 +1388,7 @@ static char sysctl_bootid[16];
33516 static int proc_do_uuid(ctl_table *table, int write,
33517 void __user *buffer, size_t *lenp, loff_t *ppos)
33518 {
33519 - ctl_table fake_table;
33520 + ctl_table_no_const fake_table;
33521 unsigned char buf[64], tmp_uuid[16], *uuid;
33522
33523 uuid = table->data;
33524 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
33525 index d780295..b29f3a8 100644
33526 --- a/drivers/char/sonypi.c
33527 +++ b/drivers/char/sonypi.c
33528 @@ -54,6 +54,7 @@
33529
33530 #include <asm/uaccess.h>
33531 #include <asm/io.h>
33532 +#include <asm/local.h>
33533
33534 #include <linux/sonypi.h>
33535
33536 @@ -490,7 +491,7 @@ static struct sonypi_device {
33537 spinlock_t fifo_lock;
33538 wait_queue_head_t fifo_proc_list;
33539 struct fasync_struct *fifo_async;
33540 - int open_count;
33541 + local_t open_count;
33542 int model;
33543 struct input_dev *input_jog_dev;
33544 struct input_dev *input_key_dev;
33545 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
33546 static int sonypi_misc_release(struct inode *inode, struct file *file)
33547 {
33548 mutex_lock(&sonypi_device.lock);
33549 - sonypi_device.open_count--;
33550 + local_dec(&sonypi_device.open_count);
33551 mutex_unlock(&sonypi_device.lock);
33552 return 0;
33553 }
33554 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
33555 {
33556 mutex_lock(&sonypi_device.lock);
33557 /* Flush input queue on first open */
33558 - if (!sonypi_device.open_count)
33559 + if (!local_read(&sonypi_device.open_count))
33560 kfifo_reset(&sonypi_device.fifo);
33561 - sonypi_device.open_count++;
33562 + local_inc(&sonypi_device.open_count);
33563 mutex_unlock(&sonypi_device.lock);
33564
33565 return 0;
33566 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
33567 index 93211df..c7805f7 100644
33568 --- a/drivers/char/tpm/tpm.c
33569 +++ b/drivers/char/tpm/tpm.c
33570 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
33571 chip->vendor.req_complete_val)
33572 goto out_recv;
33573
33574 - if ((status == chip->vendor.req_canceled)) {
33575 + if (status == chip->vendor.req_canceled) {
33576 dev_err(chip->dev, "Operation Canceled\n");
33577 rc = -ECANCELED;
33578 goto out;
33579 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
33580 index 56051d0..11cf3b7 100644
33581 --- a/drivers/char/tpm/tpm_acpi.c
33582 +++ b/drivers/char/tpm/tpm_acpi.c
33583 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
33584 virt = acpi_os_map_memory(start, len);
33585 if (!virt) {
33586 kfree(log->bios_event_log);
33587 + log->bios_event_log = NULL;
33588 printk("%s: ERROR - Unable to map memory\n", __func__);
33589 return -EIO;
33590 }
33591
33592 - memcpy_fromio(log->bios_event_log, virt, len);
33593 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
33594
33595 acpi_os_unmap_memory(virt, len);
33596 return 0;
33597 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
33598 index 84ddc55..1d32f1e 100644
33599 --- a/drivers/char/tpm/tpm_eventlog.c
33600 +++ b/drivers/char/tpm/tpm_eventlog.c
33601 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
33602 event = addr;
33603
33604 if ((event->event_type == 0 && event->event_size == 0) ||
33605 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
33606 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
33607 return NULL;
33608
33609 return addr;
33610 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
33611 return NULL;
33612
33613 if ((event->event_type == 0 && event->event_size == 0) ||
33614 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
33615 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
33616 return NULL;
33617
33618 (*pos)++;
33619 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
33620 int i;
33621
33622 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
33623 - seq_putc(m, data[i]);
33624 + if (!seq_putc(m, data[i]))
33625 + return -EFAULT;
33626
33627 return 0;
33628 }
33629 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
33630 index ee4dbea..69c817b 100644
33631 --- a/drivers/char/virtio_console.c
33632 +++ b/drivers/char/virtio_console.c
33633 @@ -681,7 +681,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
33634 if (to_user) {
33635 ssize_t ret;
33636
33637 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
33638 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
33639 if (ret)
33640 return -EFAULT;
33641 } else {
33642 @@ -780,7 +780,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
33643 if (!port_has_data(port) && !port->host_connected)
33644 return 0;
33645
33646 - return fill_readbuf(port, ubuf, count, true);
33647 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
33648 }
33649
33650 static int wait_port_writable(struct port *port, bool nonblock)
33651 diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
33652 index 8ae1a61..9c00613 100644
33653 --- a/drivers/clocksource/arm_generic.c
33654 +++ b/drivers/clocksource/arm_generic.c
33655 @@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
33656 return NOTIFY_OK;
33657 }
33658
33659 -static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
33660 +static struct notifier_block arch_timer_cpu_nb = {
33661 .notifier_call = arch_timer_cpu_notify,
33662 };
33663
33664 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
33665 index 7b0d49d..134fac9 100644
33666 --- a/drivers/cpufreq/acpi-cpufreq.c
33667 +++ b/drivers/cpufreq/acpi-cpufreq.c
33668 @@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
33669 return sprintf(buf, "%u\n", boost_enabled);
33670 }
33671
33672 -static struct global_attr global_boost = __ATTR(boost, 0644,
33673 +static global_attr_no_const global_boost = __ATTR(boost, 0644,
33674 show_global_boost,
33675 store_global_boost);
33676
33677 @@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33678 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
33679 per_cpu(acfreq_data, cpu) = data;
33680
33681 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
33682 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
33683 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
33684 + pax_open_kernel();
33685 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
33686 + pax_close_kernel();
33687 + }
33688
33689 result = acpi_processor_register_performance(data->acpi_data, cpu);
33690 if (result)
33691 @@ -835,7 +838,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33692 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
33693 break;
33694 case ACPI_ADR_SPACE_FIXED_HARDWARE:
33695 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
33696 + pax_open_kernel();
33697 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
33698 + pax_close_kernel();
33699 policy->cur = get_cur_freq_on_cpu(cpu);
33700 break;
33701 default:
33702 @@ -846,8 +851,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33703 acpi_processor_notify_smm(THIS_MODULE);
33704
33705 /* Check for APERF/MPERF support in hardware */
33706 - if (boot_cpu_has(X86_FEATURE_APERFMPERF))
33707 - acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
33708 + if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
33709 + pax_open_kernel();
33710 + *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
33711 + pax_close_kernel();
33712 + }
33713
33714 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
33715 for (i = 0; i < perf->state_count; i++)
33716 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
33717 index 1f93dbd..305cef1 100644
33718 --- a/drivers/cpufreq/cpufreq.c
33719 +++ b/drivers/cpufreq/cpufreq.c
33720 @@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
33721 return NOTIFY_OK;
33722 }
33723
33724 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
33725 +static struct notifier_block cpufreq_cpu_notifier = {
33726 .notifier_call = cpufreq_cpu_callback,
33727 };
33728
33729 @@ -1875,8 +1875,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
33730
33731 pr_debug("trying to register driver %s\n", driver_data->name);
33732
33733 - if (driver_data->setpolicy)
33734 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
33735 + if (driver_data->setpolicy) {
33736 + pax_open_kernel();
33737 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
33738 + pax_close_kernel();
33739 + }
33740
33741 spin_lock_irqsave(&cpufreq_driver_lock, flags);
33742 if (cpufreq_driver) {
33743 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
33744 index 6c5f1d3..c7e2f35e 100644
33745 --- a/drivers/cpufreq/cpufreq_governor.c
33746 +++ b/drivers/cpufreq/cpufreq_governor.c
33747 @@ -243,7 +243,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
33748 * governor, thus we are bound to jiffes/HZ
33749 */
33750 if (dbs_data->governor == GOV_CONSERVATIVE) {
33751 - struct cs_ops *ops = dbs_data->gov_ops;
33752 + const struct cs_ops *ops = dbs_data->gov_ops;
33753
33754 cpufreq_register_notifier(ops->notifier_block,
33755 CPUFREQ_TRANSITION_NOTIFIER);
33756 @@ -251,7 +251,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
33757 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
33758 jiffies_to_usecs(10);
33759 } else {
33760 - struct od_ops *ops = dbs_data->gov_ops;
33761 + const struct od_ops *ops = dbs_data->gov_ops;
33762
33763 od_tuners->io_is_busy = ops->io_busy();
33764 }
33765 @@ -268,7 +268,7 @@ second_time:
33766 cs_dbs_info->enable = 1;
33767 cs_dbs_info->requested_freq = policy->cur;
33768 } else {
33769 - struct od_ops *ops = dbs_data->gov_ops;
33770 + const struct od_ops *ops = dbs_data->gov_ops;
33771 od_dbs_info->rate_mult = 1;
33772 od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
33773 ops->powersave_bias_init_cpu(cpu);
33774 @@ -289,7 +289,7 @@ second_time:
33775 mutex_destroy(&cpu_cdbs->timer_mutex);
33776 dbs_data->enable--;
33777 if (!dbs_data->enable) {
33778 - struct cs_ops *ops = dbs_data->gov_ops;
33779 + const struct cs_ops *ops = dbs_data->gov_ops;
33780
33781 sysfs_remove_group(cpufreq_global_kobject,
33782 dbs_data->attr_group);
33783 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
33784 index f661654..6c8e638 100644
33785 --- a/drivers/cpufreq/cpufreq_governor.h
33786 +++ b/drivers/cpufreq/cpufreq_governor.h
33787 @@ -142,7 +142,7 @@ struct dbs_data {
33788 void (*gov_check_cpu)(int cpu, unsigned int load);
33789
33790 /* Governor specific ops, see below */
33791 - void *gov_ops;
33792 + const void *gov_ops;
33793 };
33794
33795 /* Governor specific ops, will be passed to dbs_data->gov_ops */
33796 diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
33797 index 9d7732b..0b1a793 100644
33798 --- a/drivers/cpufreq/cpufreq_stats.c
33799 +++ b/drivers/cpufreq/cpufreq_stats.c
33800 @@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
33801 }
33802
33803 /* priority=1 so this will get called before cpufreq_remove_dev */
33804 -static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
33805 +static struct notifier_block cpufreq_stat_cpu_notifier = {
33806 .notifier_call = cpufreq_stat_cpu_callback,
33807 .priority = 1,
33808 };
33809 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
33810 index 827629c9..0bc6a03 100644
33811 --- a/drivers/cpufreq/p4-clockmod.c
33812 +++ b/drivers/cpufreq/p4-clockmod.c
33813 @@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
33814 case 0x0F: /* Core Duo */
33815 case 0x16: /* Celeron Core */
33816 case 0x1C: /* Atom */
33817 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33818 + pax_open_kernel();
33819 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33820 + pax_close_kernel();
33821 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
33822 case 0x0D: /* Pentium M (Dothan) */
33823 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33824 + pax_open_kernel();
33825 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33826 + pax_close_kernel();
33827 /* fall through */
33828 case 0x09: /* Pentium M (Banias) */
33829 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
33830 @@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
33831
33832 /* on P-4s, the TSC runs with constant frequency independent whether
33833 * throttling is active or not. */
33834 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33835 + pax_open_kernel();
33836 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33837 + pax_close_kernel();
33838
33839 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
33840 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
33841 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
33842 index 3a953d5..f5993f6 100644
33843 --- a/drivers/cpufreq/speedstep-centrino.c
33844 +++ b/drivers/cpufreq/speedstep-centrino.c
33845 @@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
33846 !cpu_has(cpu, X86_FEATURE_EST))
33847 return -ENODEV;
33848
33849 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
33850 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
33851 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
33852 + pax_open_kernel();
33853 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
33854 + pax_close_kernel();
33855 + }
33856
33857 if (policy->cpu != 0)
33858 return -ENODEV;
33859 diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
33860 index e1f6860..f8de20b 100644
33861 --- a/drivers/cpuidle/cpuidle.c
33862 +++ b/drivers/cpuidle/cpuidle.c
33863 @@ -279,7 +279,7 @@ static int poll_idle(struct cpuidle_device *dev,
33864
33865 static void poll_idle_init(struct cpuidle_driver *drv)
33866 {
33867 - struct cpuidle_state *state = &drv->states[0];
33868 + cpuidle_state_no_const *state = &drv->states[0];
33869
33870 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
33871 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
33872 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
33873 index ea2f8e7..70ac501 100644
33874 --- a/drivers/cpuidle/governor.c
33875 +++ b/drivers/cpuidle/governor.c
33876 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
33877 mutex_lock(&cpuidle_lock);
33878 if (__cpuidle_find_governor(gov->name) == NULL) {
33879 ret = 0;
33880 - list_add_tail(&gov->governor_list, &cpuidle_governors);
33881 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
33882 if (!cpuidle_curr_governor ||
33883 cpuidle_curr_governor->rating < gov->rating)
33884 cpuidle_switch_governor(gov);
33885 @@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
33886 new_gov = cpuidle_replace_governor(gov->rating);
33887 cpuidle_switch_governor(new_gov);
33888 }
33889 - list_del(&gov->governor_list);
33890 + pax_list_del((struct list_head *)&gov->governor_list);
33891 mutex_unlock(&cpuidle_lock);
33892 }
33893
33894 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
33895 index 428754a..8bdf9cc 100644
33896 --- a/drivers/cpuidle/sysfs.c
33897 +++ b/drivers/cpuidle/sysfs.c
33898 @@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
33899 NULL
33900 };
33901
33902 -static struct attribute_group cpuidle_attr_group = {
33903 +static attribute_group_no_const cpuidle_attr_group = {
33904 .attrs = cpuidle_default_attrs,
33905 .name = "cpuidle",
33906 };
33907 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
33908 index 3b36797..289c16a 100644
33909 --- a/drivers/devfreq/devfreq.c
33910 +++ b/drivers/devfreq/devfreq.c
33911 @@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
33912 goto err_out;
33913 }
33914
33915 - list_add(&governor->node, &devfreq_governor_list);
33916 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
33917
33918 list_for_each_entry(devfreq, &devfreq_list, node) {
33919 int ret = 0;
33920 @@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
33921 }
33922 }
33923
33924 - list_del(&governor->node);
33925 + pax_list_del((struct list_head *)&governor->node);
33926 err_out:
33927 mutex_unlock(&devfreq_list_lock);
33928
33929 diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
33930 index b70709b..1d8d02a 100644
33931 --- a/drivers/dma/sh/shdma.c
33932 +++ b/drivers/dma/sh/shdma.c
33933 @@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
33934 return ret;
33935 }
33936
33937 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
33938 +static struct notifier_block sh_dmae_nmi_notifier = {
33939 .notifier_call = sh_dmae_nmi_handler,
33940
33941 /* Run before NMI debug handler and KGDB */
33942 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
33943 index 0ca1ca7..6e6f454 100644
33944 --- a/drivers/edac/edac_mc_sysfs.c
33945 +++ b/drivers/edac/edac_mc_sysfs.c
33946 @@ -148,7 +148,7 @@ static const char *edac_caps[] = {
33947 struct dev_ch_attribute {
33948 struct device_attribute attr;
33949 int channel;
33950 -};
33951 +} __do_const;
33952
33953 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
33954 struct dev_ch_attribute dev_attr_legacy_##_name = \
33955 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
33956 index 0056c4d..23b54d9 100644
33957 --- a/drivers/edac/edac_pci_sysfs.c
33958 +++ b/drivers/edac/edac_pci_sysfs.c
33959 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
33960 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
33961 static int edac_pci_poll_msec = 1000; /* one second workq period */
33962
33963 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
33964 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
33965 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
33966 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
33967
33968 static struct kobject *edac_pci_top_main_kobj;
33969 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
33970 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
33971 void *value;
33972 ssize_t(*show) (void *, char *);
33973 ssize_t(*store) (void *, const char *, size_t);
33974 -};
33975 +} __do_const;
33976
33977 /* Set of show/store abstract level functions for PCI Parity object */
33978 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
33979 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33980 edac_printk(KERN_CRIT, EDAC_PCI,
33981 "Signaled System Error on %s\n",
33982 pci_name(dev));
33983 - atomic_inc(&pci_nonparity_count);
33984 + atomic_inc_unchecked(&pci_nonparity_count);
33985 }
33986
33987 if (status & (PCI_STATUS_PARITY)) {
33988 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33989 "Master Data Parity Error on %s\n",
33990 pci_name(dev));
33991
33992 - atomic_inc(&pci_parity_count);
33993 + atomic_inc_unchecked(&pci_parity_count);
33994 }
33995
33996 if (status & (PCI_STATUS_DETECTED_PARITY)) {
33997 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33998 "Detected Parity Error on %s\n",
33999 pci_name(dev));
34000
34001 - atomic_inc(&pci_parity_count);
34002 + atomic_inc_unchecked(&pci_parity_count);
34003 }
34004 }
34005
34006 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34007 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34008 "Signaled System Error on %s\n",
34009 pci_name(dev));
34010 - atomic_inc(&pci_nonparity_count);
34011 + atomic_inc_unchecked(&pci_nonparity_count);
34012 }
34013
34014 if (status & (PCI_STATUS_PARITY)) {
34015 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34016 "Master Data Parity Error on "
34017 "%s\n", pci_name(dev));
34018
34019 - atomic_inc(&pci_parity_count);
34020 + atomic_inc_unchecked(&pci_parity_count);
34021 }
34022
34023 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34024 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34025 "Detected Parity Error on %s\n",
34026 pci_name(dev));
34027
34028 - atomic_inc(&pci_parity_count);
34029 + atomic_inc_unchecked(&pci_parity_count);
34030 }
34031 }
34032 }
34033 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34034 if (!check_pci_errors)
34035 return;
34036
34037 - before_count = atomic_read(&pci_parity_count);
34038 + before_count = atomic_read_unchecked(&pci_parity_count);
34039
34040 /* scan all PCI devices looking for a Parity Error on devices and
34041 * bridges.
34042 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34043 /* Only if operator has selected panic on PCI Error */
34044 if (edac_pci_get_panic_on_pe()) {
34045 /* If the count is different 'after' from 'before' */
34046 - if (before_count != atomic_read(&pci_parity_count))
34047 + if (before_count != atomic_read_unchecked(&pci_parity_count))
34048 panic("EDAC: PCI Parity Error");
34049 }
34050 }
34051 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34052 index 6796799..99e8377 100644
34053 --- a/drivers/edac/mce_amd.h
34054 +++ b/drivers/edac/mce_amd.h
34055 @@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
34056 struct amd_decoder_ops {
34057 bool (*mc0_mce)(u16, u8);
34058 bool (*mc1_mce)(u16, u8);
34059 -};
34060 +} __no_const;
34061
34062 void amd_report_gart_errors(bool);
34063 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34064 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34065 index 57ea7f4..789e3c3 100644
34066 --- a/drivers/firewire/core-card.c
34067 +++ b/drivers/firewire/core-card.c
34068 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34069
34070 void fw_core_remove_card(struct fw_card *card)
34071 {
34072 - struct fw_card_driver dummy_driver = dummy_driver_template;
34073 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
34074
34075 card->driver->update_phy_reg(card, 4,
34076 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34077 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34078 index f8d2287..5aaf4db 100644
34079 --- a/drivers/firewire/core-cdev.c
34080 +++ b/drivers/firewire/core-cdev.c
34081 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
34082 int ret;
34083
34084 if ((request->channels == 0 && request->bandwidth == 0) ||
34085 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34086 - request->bandwidth < 0)
34087 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34088 return -EINVAL;
34089
34090 r = kmalloc(sizeof(*r), GFP_KERNEL);
34091 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
34092 index af3e8aa..eb2f227 100644
34093 --- a/drivers/firewire/core-device.c
34094 +++ b/drivers/firewire/core-device.c
34095 @@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
34096 struct config_rom_attribute {
34097 struct device_attribute attr;
34098 u32 key;
34099 -};
34100 +} __do_const;
34101
34102 static ssize_t show_immediate(struct device *dev,
34103 struct device_attribute *dattr, char *buf)
34104 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
34105 index 28a94c7..58da63a 100644
34106 --- a/drivers/firewire/core-transaction.c
34107 +++ b/drivers/firewire/core-transaction.c
34108 @@ -38,6 +38,7 @@
34109 #include <linux/timer.h>
34110 #include <linux/types.h>
34111 #include <linux/workqueue.h>
34112 +#include <linux/sched.h>
34113
34114 #include <asm/byteorder.h>
34115
34116 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
34117 index 515a42c..5ecf3ba 100644
34118 --- a/drivers/firewire/core.h
34119 +++ b/drivers/firewire/core.h
34120 @@ -111,6 +111,7 @@ struct fw_card_driver {
34121
34122 int (*stop_iso)(struct fw_iso_context *ctx);
34123 };
34124 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
34125
34126 void fw_card_initialize(struct fw_card *card,
34127 const struct fw_card_driver *driver, struct device *device);
34128 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
34129 index 94a58a0..f5eba42 100644
34130 --- a/drivers/firmware/dmi-id.c
34131 +++ b/drivers/firmware/dmi-id.c
34132 @@ -16,7 +16,7 @@
34133 struct dmi_device_attribute{
34134 struct device_attribute dev_attr;
34135 int field;
34136 -};
34137 +} __do_const;
34138 #define to_dmi_dev_attr(_dev_attr) \
34139 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
34140
34141 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
34142 index 4cd392d..4b629e1 100644
34143 --- a/drivers/firmware/dmi_scan.c
34144 +++ b/drivers/firmware/dmi_scan.c
34145 @@ -490,11 +490,6 @@ void __init dmi_scan_machine(void)
34146 }
34147 }
34148 else {
34149 - /*
34150 - * no iounmap() for that ioremap(); it would be a no-op, but
34151 - * it's so early in setup that sucker gets confused into doing
34152 - * what it shouldn't if we actually call it.
34153 - */
34154 p = dmi_ioremap(0xF0000, 0x10000);
34155 if (p == NULL)
34156 goto error;
34157 @@ -769,7 +764,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
34158 if (buf == NULL)
34159 return -1;
34160
34161 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
34162 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
34163
34164 iounmap(buf);
34165 return 0;
34166 diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
34167 index 2a2e145..73745e79 100644
34168 --- a/drivers/firmware/efivars.c
34169 +++ b/drivers/firmware/efivars.c
34170 @@ -133,7 +133,7 @@ struct efivar_attribute {
34171 };
34172
34173 static struct efivars __efivars;
34174 -static struct efivar_operations ops;
34175 +static efivar_operations_no_const ops __read_only;
34176
34177 #define PSTORE_EFI_ATTRIBUTES \
34178 (EFI_VARIABLE_NON_VOLATILE | \
34179 @@ -1798,7 +1798,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
34180 static int
34181 create_efivars_bin_attributes(struct efivars *efivars)
34182 {
34183 - struct bin_attribute *attr;
34184 + bin_attribute_no_const *attr;
34185 int error;
34186
34187 /* new_var */
34188 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
34189 index 2a90ba6..07f3733 100644
34190 --- a/drivers/firmware/google/memconsole.c
34191 +++ b/drivers/firmware/google/memconsole.c
34192 @@ -147,7 +147,9 @@ static int __init memconsole_init(void)
34193 if (!found_memconsole())
34194 return -ENODEV;
34195
34196 - memconsole_bin_attr.size = memconsole_length;
34197 + pax_open_kernel();
34198 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
34199 + pax_close_kernel();
34200
34201 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
34202
34203 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
34204 index 6f2306d..af9476a 100644
34205 --- a/drivers/gpio/gpio-ich.c
34206 +++ b/drivers/gpio/gpio-ich.c
34207 @@ -69,7 +69,7 @@ struct ichx_desc {
34208 /* Some chipsets have quirks, let these use their own request/get */
34209 int (*request)(struct gpio_chip *chip, unsigned offset);
34210 int (*get)(struct gpio_chip *chip, unsigned offset);
34211 -};
34212 +} __do_const;
34213
34214 static struct {
34215 spinlock_t lock;
34216 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
34217 index 9902732..64b62dd 100644
34218 --- a/drivers/gpio/gpio-vr41xx.c
34219 +++ b/drivers/gpio/gpio-vr41xx.c
34220 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
34221 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
34222 maskl, pendl, maskh, pendh);
34223
34224 - atomic_inc(&irq_err_count);
34225 + atomic_inc_unchecked(&irq_err_count);
34226
34227 return -EINVAL;
34228 }
34229 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
34230 index 7b2d378..cc947ea 100644
34231 --- a/drivers/gpu/drm/drm_crtc_helper.c
34232 +++ b/drivers/gpu/drm/drm_crtc_helper.c
34233 @@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
34234 struct drm_crtc *tmp;
34235 int crtc_mask = 1;
34236
34237 - WARN(!crtc, "checking null crtc?\n");
34238 + BUG_ON(!crtc);
34239
34240 dev = crtc->dev;
34241
34242 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
34243 index be174ca..7f38143 100644
34244 --- a/drivers/gpu/drm/drm_drv.c
34245 +++ b/drivers/gpu/drm/drm_drv.c
34246 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
34247 /**
34248 * Copy and IOCTL return string to user space
34249 */
34250 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
34251 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
34252 {
34253 int len;
34254
34255 @@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
34256 struct drm_file *file_priv = filp->private_data;
34257 struct drm_device *dev;
34258 struct drm_ioctl_desc *ioctl;
34259 - drm_ioctl_t *func;
34260 + drm_ioctl_no_const_t func;
34261 unsigned int nr = DRM_IOCTL_NR(cmd);
34262 int retcode = -EINVAL;
34263 char stack_kdata[128];
34264 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
34265 return -ENODEV;
34266
34267 atomic_inc(&dev->ioctl_count);
34268 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
34269 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
34270 ++file_priv->ioctl_count;
34271
34272 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
34273 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
34274 index 133b413..fd68225 100644
34275 --- a/drivers/gpu/drm/drm_fops.c
34276 +++ b/drivers/gpu/drm/drm_fops.c
34277 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
34278 }
34279
34280 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
34281 - atomic_set(&dev->counts[i], 0);
34282 + atomic_set_unchecked(&dev->counts[i], 0);
34283
34284 dev->sigdata.lock = NULL;
34285
34286 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
34287 if (drm_device_is_unplugged(dev))
34288 return -ENODEV;
34289
34290 - if (!dev->open_count++)
34291 + if (local_inc_return(&dev->open_count) == 1)
34292 need_setup = 1;
34293 mutex_lock(&dev->struct_mutex);
34294 old_mapping = dev->dev_mapping;
34295 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
34296 retcode = drm_open_helper(inode, filp, dev);
34297 if (retcode)
34298 goto err_undo;
34299 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
34300 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
34301 if (need_setup) {
34302 retcode = drm_setup(dev);
34303 if (retcode)
34304 @@ -164,7 +164,7 @@ err_undo:
34305 iput(container_of(dev->dev_mapping, struct inode, i_data));
34306 dev->dev_mapping = old_mapping;
34307 mutex_unlock(&dev->struct_mutex);
34308 - dev->open_count--;
34309 + local_dec(&dev->open_count);
34310 return retcode;
34311 }
34312 EXPORT_SYMBOL(drm_open);
34313 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
34314
34315 mutex_lock(&drm_global_mutex);
34316
34317 - DRM_DEBUG("open_count = %d\n", dev->open_count);
34318 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
34319
34320 if (dev->driver->preclose)
34321 dev->driver->preclose(dev, file_priv);
34322 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
34323 * Begin inline drm_release
34324 */
34325
34326 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
34327 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
34328 task_pid_nr(current),
34329 (long)old_encode_dev(file_priv->minor->device),
34330 - dev->open_count);
34331 + local_read(&dev->open_count));
34332
34333 /* Release any auth tokens that might point to this file_priv,
34334 (do that under the drm_global_mutex) */
34335 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
34336 * End inline drm_release
34337 */
34338
34339 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
34340 - if (!--dev->open_count) {
34341 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
34342 + if (local_dec_and_test(&dev->open_count)) {
34343 if (atomic_read(&dev->ioctl_count)) {
34344 DRM_ERROR("Device busy: %d\n",
34345 atomic_read(&dev->ioctl_count));
34346 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
34347 index f731116..629842c 100644
34348 --- a/drivers/gpu/drm/drm_global.c
34349 +++ b/drivers/gpu/drm/drm_global.c
34350 @@ -36,7 +36,7 @@
34351 struct drm_global_item {
34352 struct mutex mutex;
34353 void *object;
34354 - int refcount;
34355 + atomic_t refcount;
34356 };
34357
34358 static struct drm_global_item glob[DRM_GLOBAL_NUM];
34359 @@ -49,7 +49,7 @@ void drm_global_init(void)
34360 struct drm_global_item *item = &glob[i];
34361 mutex_init(&item->mutex);
34362 item->object = NULL;
34363 - item->refcount = 0;
34364 + atomic_set(&item->refcount, 0);
34365 }
34366 }
34367
34368 @@ -59,7 +59,7 @@ void drm_global_release(void)
34369 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
34370 struct drm_global_item *item = &glob[i];
34371 BUG_ON(item->object != NULL);
34372 - BUG_ON(item->refcount != 0);
34373 + BUG_ON(atomic_read(&item->refcount) != 0);
34374 }
34375 }
34376
34377 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34378 void *object;
34379
34380 mutex_lock(&item->mutex);
34381 - if (item->refcount == 0) {
34382 + if (atomic_read(&item->refcount) == 0) {
34383 item->object = kzalloc(ref->size, GFP_KERNEL);
34384 if (unlikely(item->object == NULL)) {
34385 ret = -ENOMEM;
34386 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34387 goto out_err;
34388
34389 }
34390 - ++item->refcount;
34391 + atomic_inc(&item->refcount);
34392 ref->object = item->object;
34393 object = item->object;
34394 mutex_unlock(&item->mutex);
34395 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
34396 struct drm_global_item *item = &glob[ref->global_type];
34397
34398 mutex_lock(&item->mutex);
34399 - BUG_ON(item->refcount == 0);
34400 + BUG_ON(atomic_read(&item->refcount) == 0);
34401 BUG_ON(ref->object != item->object);
34402 - if (--item->refcount == 0) {
34403 + if (atomic_dec_and_test(&item->refcount)) {
34404 ref->release(ref);
34405 item->object = NULL;
34406 }
34407 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
34408 index d4b20ce..77a8d41 100644
34409 --- a/drivers/gpu/drm/drm_info.c
34410 +++ b/drivers/gpu/drm/drm_info.c
34411 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
34412 struct drm_local_map *map;
34413 struct drm_map_list *r_list;
34414
34415 - /* Hardcoded from _DRM_FRAME_BUFFER,
34416 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
34417 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
34418 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
34419 + static const char * const types[] = {
34420 + [_DRM_FRAME_BUFFER] = "FB",
34421 + [_DRM_REGISTERS] = "REG",
34422 + [_DRM_SHM] = "SHM",
34423 + [_DRM_AGP] = "AGP",
34424 + [_DRM_SCATTER_GATHER] = "SG",
34425 + [_DRM_CONSISTENT] = "PCI",
34426 + [_DRM_GEM] = "GEM" };
34427 const char *type;
34428 int i;
34429
34430 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
34431 map = r_list->map;
34432 if (!map)
34433 continue;
34434 - if (map->type < 0 || map->type > 5)
34435 + if (map->type >= ARRAY_SIZE(types))
34436 type = "??";
34437 else
34438 type = types[map->type];
34439 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
34440 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
34441 vma->vm_flags & VM_LOCKED ? 'l' : '-',
34442 vma->vm_flags & VM_IO ? 'i' : '-',
34443 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34444 + 0);
34445 +#else
34446 vma->vm_pgoff);
34447 +#endif
34448
34449 #if defined(__i386__)
34450 pgprot = pgprot_val(vma->vm_page_prot);
34451 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
34452 index 2f4c434..dd12cd2 100644
34453 --- a/drivers/gpu/drm/drm_ioc32.c
34454 +++ b/drivers/gpu/drm/drm_ioc32.c
34455 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
34456 request = compat_alloc_user_space(nbytes);
34457 if (!access_ok(VERIFY_WRITE, request, nbytes))
34458 return -EFAULT;
34459 - list = (struct drm_buf_desc *) (request + 1);
34460 + list = (struct drm_buf_desc __user *) (request + 1);
34461
34462 if (__put_user(count, &request->count)
34463 || __put_user(list, &request->list))
34464 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
34465 request = compat_alloc_user_space(nbytes);
34466 if (!access_ok(VERIFY_WRITE, request, nbytes))
34467 return -EFAULT;
34468 - list = (struct drm_buf_pub *) (request + 1);
34469 + list = (struct drm_buf_pub __user *) (request + 1);
34470
34471 if (__put_user(count, &request->count)
34472 || __put_user(list, &request->list))
34473 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
34474 return 0;
34475 }
34476
34477 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
34478 +drm_ioctl_compat_t drm_compat_ioctls[] = {
34479 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
34480 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
34481 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
34482 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
34483 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34484 {
34485 unsigned int nr = DRM_IOCTL_NR(cmd);
34486 - drm_ioctl_compat_t *fn;
34487 int ret;
34488
34489 /* Assume that ioctls without an explicit compat routine will just
34490 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34491 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
34492 return drm_ioctl(filp, cmd, arg);
34493
34494 - fn = drm_compat_ioctls[nr];
34495 -
34496 - if (fn != NULL)
34497 - ret = (*fn) (filp, cmd, arg);
34498 + if (drm_compat_ioctls[nr] != NULL)
34499 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
34500 else
34501 ret = drm_ioctl(filp, cmd, arg);
34502
34503 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
34504 index e77bd8b..1571b85 100644
34505 --- a/drivers/gpu/drm/drm_ioctl.c
34506 +++ b/drivers/gpu/drm/drm_ioctl.c
34507 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
34508 stats->data[i].value =
34509 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
34510 else
34511 - stats->data[i].value = atomic_read(&dev->counts[i]);
34512 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
34513 stats->data[i].type = dev->types[i];
34514 }
34515
34516 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
34517 index d752c96..fe08455 100644
34518 --- a/drivers/gpu/drm/drm_lock.c
34519 +++ b/drivers/gpu/drm/drm_lock.c
34520 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34521 if (drm_lock_take(&master->lock, lock->context)) {
34522 master->lock.file_priv = file_priv;
34523 master->lock.lock_time = jiffies;
34524 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
34525 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
34526 break; /* Got lock */
34527 }
34528
34529 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34530 return -EINVAL;
34531 }
34532
34533 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
34534 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
34535
34536 if (drm_lock_free(&master->lock, lock->context)) {
34537 /* FIXME: Should really bail out here. */
34538 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
34539 index 200e104..59facda 100644
34540 --- a/drivers/gpu/drm/drm_stub.c
34541 +++ b/drivers/gpu/drm/drm_stub.c
34542 @@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
34543
34544 drm_device_set_unplugged(dev);
34545
34546 - if (dev->open_count == 0) {
34547 + if (local_read(&dev->open_count) == 0) {
34548 drm_put_dev(dev);
34549 }
34550 mutex_unlock(&drm_global_mutex);
34551 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
34552 index 004ecdf..db1f6e0 100644
34553 --- a/drivers/gpu/drm/i810/i810_dma.c
34554 +++ b/drivers/gpu/drm/i810/i810_dma.c
34555 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
34556 dma->buflist[vertex->idx],
34557 vertex->discard, vertex->used);
34558
34559 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34560 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34561 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34562 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34563 sarea_priv->last_enqueue = dev_priv->counter - 1;
34564 sarea_priv->last_dispatch = (int)hw_status[5];
34565
34566 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
34567 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
34568 mc->last_render);
34569
34570 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
34571 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34572 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
34573 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34574 sarea_priv->last_enqueue = dev_priv->counter - 1;
34575 sarea_priv->last_dispatch = (int)hw_status[5];
34576
34577 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
34578 index 6e0acad..93c8289 100644
34579 --- a/drivers/gpu/drm/i810/i810_drv.h
34580 +++ b/drivers/gpu/drm/i810/i810_drv.h
34581 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
34582 int page_flipping;
34583
34584 wait_queue_head_t irq_queue;
34585 - atomic_t irq_received;
34586 - atomic_t irq_emitted;
34587 + atomic_unchecked_t irq_received;
34588 + atomic_unchecked_t irq_emitted;
34589
34590 int front_offset;
34591 } drm_i810_private_t;
34592 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
34593 index 8a7c48b..72effc2 100644
34594 --- a/drivers/gpu/drm/i915/i915_debugfs.c
34595 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
34596 @@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
34597 I915_READ(GTIMR));
34598 }
34599 seq_printf(m, "Interrupts received: %d\n",
34600 - atomic_read(&dev_priv->irq_received));
34601 + atomic_read_unchecked(&dev_priv->irq_received));
34602 for_each_ring(ring, dev_priv, i) {
34603 if (IS_GEN6(dev) || IS_GEN7(dev)) {
34604 seq_printf(m,
34605 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
34606 index 5206f24..7af0a0a 100644
34607 --- a/drivers/gpu/drm/i915/i915_dma.c
34608 +++ b/drivers/gpu/drm/i915/i915_dma.c
34609 @@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
34610 bool can_switch;
34611
34612 spin_lock(&dev->count_lock);
34613 - can_switch = (dev->open_count == 0);
34614 + can_switch = (local_read(&dev->open_count) == 0);
34615 spin_unlock(&dev->count_lock);
34616 return can_switch;
34617 }
34618 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
34619 index 66ad64f..a865871 100644
34620 --- a/drivers/gpu/drm/i915/i915_drv.h
34621 +++ b/drivers/gpu/drm/i915/i915_drv.h
34622 @@ -656,7 +656,7 @@ typedef struct drm_i915_private {
34623 drm_dma_handle_t *status_page_dmah;
34624 struct resource mch_res;
34625
34626 - atomic_t irq_received;
34627 + atomic_unchecked_t irq_received;
34628
34629 /* protects the irq masks */
34630 spinlock_t irq_lock;
34631 @@ -1103,7 +1103,7 @@ struct drm_i915_gem_object {
34632 * will be page flipped away on the next vblank. When it
34633 * reaches 0, dev_priv->pending_flip_queue will be woken up.
34634 */
34635 - atomic_t pending_flip;
34636 + atomic_unchecked_t pending_flip;
34637 };
34638 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
34639
34640 @@ -1634,7 +1634,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
34641 struct drm_i915_private *dev_priv, unsigned port);
34642 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
34643 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
34644 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
34645 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
34646 {
34647 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
34648 }
34649 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34650 index 26d08bb..fccb984 100644
34651 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34652 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34653 @@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
34654 i915_gem_clflush_object(obj);
34655
34656 if (obj->base.pending_write_domain)
34657 - flips |= atomic_read(&obj->pending_flip);
34658 + flips |= atomic_read_unchecked(&obj->pending_flip);
34659
34660 flush_domains |= obj->base.write_domain;
34661 }
34662 @@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
34663
34664 static int
34665 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
34666 - int count)
34667 + unsigned int count)
34668 {
34669 - int i;
34670 + unsigned int i;
34671
34672 for (i = 0; i < count; i++) {
34673 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
34674 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
34675 index 3c59584..500f2e9 100644
34676 --- a/drivers/gpu/drm/i915/i915_ioc32.c
34677 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
34678 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
34679 (unsigned long)request);
34680 }
34681
34682 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
34683 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
34684 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
34685 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
34686 [DRM_I915_GETPARAM] = compat_i915_getparam,
34687 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
34688 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34689 {
34690 unsigned int nr = DRM_IOCTL_NR(cmd);
34691 - drm_ioctl_compat_t *fn = NULL;
34692 int ret;
34693
34694 if (nr < DRM_COMMAND_BASE)
34695 return drm_compat_ioctl(filp, cmd, arg);
34696
34697 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
34698 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
34699 -
34700 - if (fn != NULL)
34701 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
34702 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
34703 ret = (*fn) (filp, cmd, arg);
34704 - else
34705 + } else
34706 ret = drm_ioctl(filp, cmd, arg);
34707
34708 return ret;
34709 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
34710 index 3c00403..5a5c6c9 100644
34711 --- a/drivers/gpu/drm/i915/i915_irq.c
34712 +++ b/drivers/gpu/drm/i915/i915_irq.c
34713 @@ -539,7 +539,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
34714 u32 pipe_stats[I915_MAX_PIPES];
34715 bool blc_event;
34716
34717 - atomic_inc(&dev_priv->irq_received);
34718 + atomic_inc_unchecked(&dev_priv->irq_received);
34719
34720 while (true) {
34721 iir = I915_READ(VLV_IIR);
34722 @@ -692,7 +692,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
34723 irqreturn_t ret = IRQ_NONE;
34724 int i;
34725
34726 - atomic_inc(&dev_priv->irq_received);
34727 + atomic_inc_unchecked(&dev_priv->irq_received);
34728
34729 /* disable master interrupt before clearing iir */
34730 de_ier = I915_READ(DEIER);
34731 @@ -764,7 +764,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
34732 int ret = IRQ_NONE;
34733 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
34734
34735 - atomic_inc(&dev_priv->irq_received);
34736 + atomic_inc_unchecked(&dev_priv->irq_received);
34737
34738 /* disable master interrupt before clearing iir */
34739 de_ier = I915_READ(DEIER);
34740 @@ -1791,7 +1791,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
34741 {
34742 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34743
34744 - atomic_set(&dev_priv->irq_received, 0);
34745 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34746
34747 I915_WRITE(HWSTAM, 0xeffe);
34748
34749 @@ -1817,7 +1817,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
34750 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34751 int pipe;
34752
34753 - atomic_set(&dev_priv->irq_received, 0);
34754 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34755
34756 /* VLV magic */
34757 I915_WRITE(VLV_IMR, 0);
34758 @@ -2112,7 +2112,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
34759 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34760 int pipe;
34761
34762 - atomic_set(&dev_priv->irq_received, 0);
34763 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34764
34765 for_each_pipe(pipe)
34766 I915_WRITE(PIPESTAT(pipe), 0);
34767 @@ -2163,7 +2163,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
34768 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
34769 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
34770
34771 - atomic_inc(&dev_priv->irq_received);
34772 + atomic_inc_unchecked(&dev_priv->irq_received);
34773
34774 iir = I915_READ16(IIR);
34775 if (iir == 0)
34776 @@ -2248,7 +2248,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
34777 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34778 int pipe;
34779
34780 - atomic_set(&dev_priv->irq_received, 0);
34781 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34782
34783 if (I915_HAS_HOTPLUG(dev)) {
34784 I915_WRITE(PORT_HOTPLUG_EN, 0);
34785 @@ -2343,7 +2343,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
34786 };
34787 int pipe, ret = IRQ_NONE;
34788
34789 - atomic_inc(&dev_priv->irq_received);
34790 + atomic_inc_unchecked(&dev_priv->irq_received);
34791
34792 iir = I915_READ(IIR);
34793 do {
34794 @@ -2469,7 +2469,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
34795 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34796 int pipe;
34797
34798 - atomic_set(&dev_priv->irq_received, 0);
34799 + atomic_set_unchecked(&dev_priv->irq_received, 0);
34800
34801 I915_WRITE(PORT_HOTPLUG_EN, 0);
34802 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
34803 @@ -2576,7 +2576,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
34804 int irq_received;
34805 int ret = IRQ_NONE, pipe;
34806
34807 - atomic_inc(&dev_priv->irq_received);
34808 + atomic_inc_unchecked(&dev_priv->irq_received);
34809
34810 iir = I915_READ(IIR);
34811
34812 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
34813 index 80aa1fc..85cfce3 100644
34814 --- a/drivers/gpu/drm/i915/intel_display.c
34815 +++ b/drivers/gpu/drm/i915/intel_display.c
34816 @@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
34817
34818 wait_event(dev_priv->pending_flip_queue,
34819 atomic_read(&dev_priv->mm.wedged) ||
34820 - atomic_read(&obj->pending_flip) == 0);
34821 + atomic_read_unchecked(&obj->pending_flip) == 0);
34822
34823 /* Big Hammer, we also need to ensure that any pending
34824 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
34825 @@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
34826
34827 obj = work->old_fb_obj;
34828
34829 - atomic_clear_mask(1 << intel_crtc->plane,
34830 - &obj->pending_flip.counter);
34831 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
34832 wake_up(&dev_priv->pending_flip_queue);
34833
34834 queue_work(dev_priv->wq, &work->work);
34835 @@ -7490,7 +7489,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
34836 /* Block clients from rendering to the new back buffer until
34837 * the flip occurs and the object is no longer visible.
34838 */
34839 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34840 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34841 atomic_inc(&intel_crtc->unpin_work_count);
34842
34843 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
34844 @@ -7507,7 +7506,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
34845
34846 cleanup_pending:
34847 atomic_dec(&intel_crtc->unpin_work_count);
34848 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34849 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34850 drm_gem_object_unreference(&work->old_fb_obj->base);
34851 drm_gem_object_unreference(&obj->base);
34852 mutex_unlock(&dev->struct_mutex);
34853 @@ -8849,13 +8848,13 @@ struct intel_quirk {
34854 int subsystem_vendor;
34855 int subsystem_device;
34856 void (*hook)(struct drm_device *dev);
34857 -};
34858 +} __do_const;
34859
34860 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
34861 struct intel_dmi_quirk {
34862 void (*hook)(struct drm_device *dev);
34863 const struct dmi_system_id (*dmi_id_list)[];
34864 -};
34865 +} __do_const;
34866
34867 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
34868 {
34869 @@ -8863,18 +8862,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
34870 return 1;
34871 }
34872
34873 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
34874 + {
34875 + .callback = intel_dmi_reverse_brightness,
34876 + .ident = "NCR Corporation",
34877 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
34878 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
34879 + },
34880 + },
34881 + { } /* terminating entry */
34882 +};
34883 +
34884 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
34885 {
34886 - .dmi_id_list = &(const struct dmi_system_id[]) {
34887 - {
34888 - .callback = intel_dmi_reverse_brightness,
34889 - .ident = "NCR Corporation",
34890 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
34891 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
34892 - },
34893 - },
34894 - { } /* terminating entry */
34895 - },
34896 + .dmi_id_list = &intel_dmi_quirks_table,
34897 .hook = quirk_invert_brightness,
34898 },
34899 };
34900 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
34901 index 54558a0..2d97005 100644
34902 --- a/drivers/gpu/drm/mga/mga_drv.h
34903 +++ b/drivers/gpu/drm/mga/mga_drv.h
34904 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
34905 u32 clear_cmd;
34906 u32 maccess;
34907
34908 - atomic_t vbl_received; /**< Number of vblanks received. */
34909 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
34910 wait_queue_head_t fence_queue;
34911 - atomic_t last_fence_retired;
34912 + atomic_unchecked_t last_fence_retired;
34913 u32 next_fence_to_post;
34914
34915 unsigned int fb_cpp;
34916 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
34917 index 709e90d..89a1c0d 100644
34918 --- a/drivers/gpu/drm/mga/mga_ioc32.c
34919 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
34920 @@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
34921 return 0;
34922 }
34923
34924 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
34925 +drm_ioctl_compat_t mga_compat_ioctls[] = {
34926 [DRM_MGA_INIT] = compat_mga_init,
34927 [DRM_MGA_GETPARAM] = compat_mga_getparam,
34928 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
34929 @@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
34930 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34931 {
34932 unsigned int nr = DRM_IOCTL_NR(cmd);
34933 - drm_ioctl_compat_t *fn = NULL;
34934 int ret;
34935
34936 if (nr < DRM_COMMAND_BASE)
34937 return drm_compat_ioctl(filp, cmd, arg);
34938
34939 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
34940 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
34941 -
34942 - if (fn != NULL)
34943 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
34944 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
34945 ret = (*fn) (filp, cmd, arg);
34946 - else
34947 + } else
34948 ret = drm_ioctl(filp, cmd, arg);
34949
34950 return ret;
34951 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
34952 index 598c281..60d590e 100644
34953 --- a/drivers/gpu/drm/mga/mga_irq.c
34954 +++ b/drivers/gpu/drm/mga/mga_irq.c
34955 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
34956 if (crtc != 0)
34957 return 0;
34958
34959 - return atomic_read(&dev_priv->vbl_received);
34960 + return atomic_read_unchecked(&dev_priv->vbl_received);
34961 }
34962
34963
34964 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
34965 /* VBLANK interrupt */
34966 if (status & MGA_VLINEPEN) {
34967 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
34968 - atomic_inc(&dev_priv->vbl_received);
34969 + atomic_inc_unchecked(&dev_priv->vbl_received);
34970 drm_handle_vblank(dev, 0);
34971 handled = 1;
34972 }
34973 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
34974 if ((prim_start & ~0x03) != (prim_end & ~0x03))
34975 MGA_WRITE(MGA_PRIMEND, prim_end);
34976
34977 - atomic_inc(&dev_priv->last_fence_retired);
34978 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
34979 DRM_WAKEUP(&dev_priv->fence_queue);
34980 handled = 1;
34981 }
34982 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
34983 * using fences.
34984 */
34985 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
34986 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
34987 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
34988 - *sequence) <= (1 << 23)));
34989
34990 *sequence = cur_fence;
34991 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
34992 index 865eddf..62c4cc3 100644
34993 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
34994 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
34995 @@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
34996 struct bit_table {
34997 const char id;
34998 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
34999 -};
35000 +} __no_const;
35001
35002 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35003
35004 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35005 index aa89eb9..d45d38b 100644
35006 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35007 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35008 @@ -80,7 +80,7 @@ struct nouveau_drm {
35009 struct drm_global_reference mem_global_ref;
35010 struct ttm_bo_global_ref bo_global_ref;
35011 struct ttm_bo_device bdev;
35012 - atomic_t validate_sequence;
35013 + atomic_unchecked_t validate_sequence;
35014 int (*move)(struct nouveau_channel *,
35015 struct ttm_buffer_object *,
35016 struct ttm_mem_reg *, struct ttm_mem_reg *);
35017 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
35018 index cdb83ac..27f0a16 100644
35019 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
35020 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
35021 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
35022 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
35023 struct nouveau_channel *);
35024 u32 (*read)(struct nouveau_channel *);
35025 -};
35026 +} __no_const;
35027
35028 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
35029
35030 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35031 index 8bf695c..9fbc90a 100644
35032 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35033 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35034 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35035 int trycnt = 0;
35036 int ret, i;
35037
35038 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35039 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35040 retry:
35041 if (++trycnt > 100000) {
35042 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
35043 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35044 index 08214bc..9208577 100644
35045 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35046 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35047 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35048 unsigned long arg)
35049 {
35050 unsigned int nr = DRM_IOCTL_NR(cmd);
35051 - drm_ioctl_compat_t *fn = NULL;
35052 + drm_ioctl_compat_t fn = NULL;
35053 int ret;
35054
35055 if (nr < DRM_COMMAND_BASE)
35056 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35057 index 25d3495..d81aaf6 100644
35058 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35059 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35060 @@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35061 bool can_switch;
35062
35063 spin_lock(&dev->count_lock);
35064 - can_switch = (dev->open_count == 0);
35065 + can_switch = (local_read(&dev->open_count) == 0);
35066 spin_unlock(&dev->count_lock);
35067 return can_switch;
35068 }
35069 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35070 index d4660cf..70dbe65 100644
35071 --- a/drivers/gpu/drm/r128/r128_cce.c
35072 +++ b/drivers/gpu/drm/r128/r128_cce.c
35073 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35074
35075 /* GH: Simple idle check.
35076 */
35077 - atomic_set(&dev_priv->idle_count, 0);
35078 + atomic_set_unchecked(&dev_priv->idle_count, 0);
35079
35080 /* We don't support anything other than bus-mastering ring mode,
35081 * but the ring can be in either AGP or PCI space for the ring
35082 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35083 index 930c71b..499aded 100644
35084 --- a/drivers/gpu/drm/r128/r128_drv.h
35085 +++ b/drivers/gpu/drm/r128/r128_drv.h
35086 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
35087 int is_pci;
35088 unsigned long cce_buffers_offset;
35089
35090 - atomic_t idle_count;
35091 + atomic_unchecked_t idle_count;
35092
35093 int page_flipping;
35094 int current_page;
35095 u32 crtc_offset;
35096 u32 crtc_offset_cntl;
35097
35098 - atomic_t vbl_received;
35099 + atomic_unchecked_t vbl_received;
35100
35101 u32 color_fmt;
35102 unsigned int front_offset;
35103 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
35104 index a954c54..9cc595c 100644
35105 --- a/drivers/gpu/drm/r128/r128_ioc32.c
35106 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
35107 @@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
35108 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
35109 }
35110
35111 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
35112 +drm_ioctl_compat_t r128_compat_ioctls[] = {
35113 [DRM_R128_INIT] = compat_r128_init,
35114 [DRM_R128_DEPTH] = compat_r128_depth,
35115 [DRM_R128_STIPPLE] = compat_r128_stipple,
35116 @@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
35117 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35118 {
35119 unsigned int nr = DRM_IOCTL_NR(cmd);
35120 - drm_ioctl_compat_t *fn = NULL;
35121 int ret;
35122
35123 if (nr < DRM_COMMAND_BASE)
35124 return drm_compat_ioctl(filp, cmd, arg);
35125
35126 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
35127 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35128 -
35129 - if (fn != NULL)
35130 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
35131 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35132 ret = (*fn) (filp, cmd, arg);
35133 - else
35134 + } else
35135 ret = drm_ioctl(filp, cmd, arg);
35136
35137 return ret;
35138 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
35139 index 2ea4f09..d391371 100644
35140 --- a/drivers/gpu/drm/r128/r128_irq.c
35141 +++ b/drivers/gpu/drm/r128/r128_irq.c
35142 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
35143 if (crtc != 0)
35144 return 0;
35145
35146 - return atomic_read(&dev_priv->vbl_received);
35147 + return atomic_read_unchecked(&dev_priv->vbl_received);
35148 }
35149
35150 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35151 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35152 /* VBLANK interrupt */
35153 if (status & R128_CRTC_VBLANK_INT) {
35154 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
35155 - atomic_inc(&dev_priv->vbl_received);
35156 + atomic_inc_unchecked(&dev_priv->vbl_received);
35157 drm_handle_vblank(dev, 0);
35158 return IRQ_HANDLED;
35159 }
35160 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
35161 index 19bb7e6..de7e2a2 100644
35162 --- a/drivers/gpu/drm/r128/r128_state.c
35163 +++ b/drivers/gpu/drm/r128/r128_state.c
35164 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
35165
35166 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
35167 {
35168 - if (atomic_read(&dev_priv->idle_count) == 0)
35169 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
35170 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
35171 else
35172 - atomic_set(&dev_priv->idle_count, 0);
35173 + atomic_set_unchecked(&dev_priv->idle_count, 0);
35174 }
35175
35176 #endif
35177 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
35178 index 5a82b6b..9e69c73 100644
35179 --- a/drivers/gpu/drm/radeon/mkregtable.c
35180 +++ b/drivers/gpu/drm/radeon/mkregtable.c
35181 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
35182 regex_t mask_rex;
35183 regmatch_t match[4];
35184 char buf[1024];
35185 - size_t end;
35186 + long end;
35187 int len;
35188 int done = 0;
35189 int r;
35190 unsigned o;
35191 struct offset *offset;
35192 char last_reg_s[10];
35193 - int last_reg;
35194 + unsigned long last_reg;
35195
35196 if (regcomp
35197 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
35198 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
35199 index 0d6562b..a154330 100644
35200 --- a/drivers/gpu/drm/radeon/radeon_device.c
35201 +++ b/drivers/gpu/drm/radeon/radeon_device.c
35202 @@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
35203 bool can_switch;
35204
35205 spin_lock(&dev->count_lock);
35206 - can_switch = (dev->open_count == 0);
35207 + can_switch = (local_read(&dev->open_count) == 0);
35208 spin_unlock(&dev->count_lock);
35209 return can_switch;
35210 }
35211 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
35212 index e7fdf16..f4f6490 100644
35213 --- a/drivers/gpu/drm/radeon/radeon_drv.h
35214 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
35215 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
35216
35217 /* SW interrupt */
35218 wait_queue_head_t swi_queue;
35219 - atomic_t swi_emitted;
35220 + atomic_unchecked_t swi_emitted;
35221 int vblank_crtc;
35222 uint32_t irq_enable_reg;
35223 uint32_t r500_disp_irq_reg;
35224 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
35225 index c180df8..5fd8186 100644
35226 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
35227 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
35228 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35229 request = compat_alloc_user_space(sizeof(*request));
35230 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
35231 || __put_user(req32.param, &request->param)
35232 - || __put_user((void __user *)(unsigned long)req32.value,
35233 + || __put_user((unsigned long)req32.value,
35234 &request->value))
35235 return -EFAULT;
35236
35237 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35238 #define compat_radeon_cp_setparam NULL
35239 #endif /* X86_64 || IA64 */
35240
35241 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35242 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
35243 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
35244 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
35245 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
35246 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35247 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35248 {
35249 unsigned int nr = DRM_IOCTL_NR(cmd);
35250 - drm_ioctl_compat_t *fn = NULL;
35251 int ret;
35252
35253 if (nr < DRM_COMMAND_BASE)
35254 return drm_compat_ioctl(filp, cmd, arg);
35255
35256 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
35257 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35258 -
35259 - if (fn != NULL)
35260 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
35261 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35262 ret = (*fn) (filp, cmd, arg);
35263 - else
35264 + } else
35265 ret = drm_ioctl(filp, cmd, arg);
35266
35267 return ret;
35268 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
35269 index e771033..a0bc6b3 100644
35270 --- a/drivers/gpu/drm/radeon/radeon_irq.c
35271 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
35272 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
35273 unsigned int ret;
35274 RING_LOCALS;
35275
35276 - atomic_inc(&dev_priv->swi_emitted);
35277 - ret = atomic_read(&dev_priv->swi_emitted);
35278 + atomic_inc_unchecked(&dev_priv->swi_emitted);
35279 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
35280
35281 BEGIN_RING(4);
35282 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
35283 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
35284 drm_radeon_private_t *dev_priv =
35285 (drm_radeon_private_t *) dev->dev_private;
35286
35287 - atomic_set(&dev_priv->swi_emitted, 0);
35288 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
35289 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
35290
35291 dev->max_vblank_count = 0x001fffff;
35292 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
35293 index 8e9057b..af6dacb 100644
35294 --- a/drivers/gpu/drm/radeon/radeon_state.c
35295 +++ b/drivers/gpu/drm/radeon/radeon_state.c
35296 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
35297 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
35298 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
35299
35300 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35301 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35302 sarea_priv->nbox * sizeof(depth_boxes[0])))
35303 return -EFAULT;
35304
35305 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
35306 {
35307 drm_radeon_private_t *dev_priv = dev->dev_private;
35308 drm_radeon_getparam_t *param = data;
35309 - int value;
35310 + int value = 0;
35311
35312 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
35313
35314 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
35315 index 93f760e..8088227 100644
35316 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
35317 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
35318 @@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
35319 man->size = size >> PAGE_SHIFT;
35320 }
35321
35322 -static struct vm_operations_struct radeon_ttm_vm_ops;
35323 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
35324 static const struct vm_operations_struct *ttm_vm_ops = NULL;
35325
35326 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
35327 @@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
35328 }
35329 if (unlikely(ttm_vm_ops == NULL)) {
35330 ttm_vm_ops = vma->vm_ops;
35331 + pax_open_kernel();
35332 radeon_ttm_vm_ops = *ttm_vm_ops;
35333 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
35334 + pax_close_kernel();
35335 }
35336 vma->vm_ops = &radeon_ttm_vm_ops;
35337 return 0;
35338 @@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
35339 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
35340 else
35341 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
35342 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35343 - radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35344 - radeon_mem_types_list[i].driver_features = 0;
35345 + pax_open_kernel();
35346 + *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35347 + *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35348 + *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35349 if (i == 0)
35350 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35351 + *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35352 else
35353 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35354 -
35355 + *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35356 + pax_close_kernel();
35357 }
35358 /* Add ttm page pool to debugfs */
35359 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
35360 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35361 - radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35362 - radeon_mem_types_list[i].driver_features = 0;
35363 - radeon_mem_types_list[i++].data = NULL;
35364 + pax_open_kernel();
35365 + *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35366 + *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35367 + *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35368 + *(void **)&radeon_mem_types_list[i++].data = NULL;
35369 + pax_close_kernel();
35370 #ifdef CONFIG_SWIOTLB
35371 if (swiotlb_nr_tbl()) {
35372 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
35373 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35374 - radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35375 - radeon_mem_types_list[i].driver_features = 0;
35376 - radeon_mem_types_list[i++].data = NULL;
35377 + pax_open_kernel();
35378 + *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35379 + *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35380 + *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35381 + *(void **)&radeon_mem_types_list[i++].data = NULL;
35382 + pax_close_kernel();
35383 }
35384 #endif
35385 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
35386 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
35387 index 5706d2a..17aedaa 100644
35388 --- a/drivers/gpu/drm/radeon/rs690.c
35389 +++ b/drivers/gpu/drm/radeon/rs690.c
35390 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
35391 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
35392 rdev->pm.sideport_bandwidth.full)
35393 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
35394 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
35395 + read_delay_latency.full = dfixed_const(800 * 1000);
35396 read_delay_latency.full = dfixed_div(read_delay_latency,
35397 rdev->pm.igp_sideport_mclk);
35398 + a.full = dfixed_const(370);
35399 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
35400 } else {
35401 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
35402 rdev->pm.k8_bandwidth.full)
35403 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35404 index bd2a3b4..122d9ad 100644
35405 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
35406 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35407 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
35408 static int ttm_pool_mm_shrink(struct shrinker *shrink,
35409 struct shrink_control *sc)
35410 {
35411 - static atomic_t start_pool = ATOMIC_INIT(0);
35412 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
35413 unsigned i;
35414 - unsigned pool_offset = atomic_add_return(1, &start_pool);
35415 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
35416 struct ttm_page_pool *pool;
35417 int shrink_pages = sc->nr_to_scan;
35418
35419 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
35420 index 1eb060c..188b1fc 100644
35421 --- a/drivers/gpu/drm/udl/udl_fb.c
35422 +++ b/drivers/gpu/drm/udl/udl_fb.c
35423 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
35424 fb_deferred_io_cleanup(info);
35425 kfree(info->fbdefio);
35426 info->fbdefio = NULL;
35427 - info->fbops->fb_mmap = udl_fb_mmap;
35428 }
35429
35430 pr_warn("released /dev/fb%d user=%d count=%d\n",
35431 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
35432 index 893a650..6190d3b 100644
35433 --- a/drivers/gpu/drm/via/via_drv.h
35434 +++ b/drivers/gpu/drm/via/via_drv.h
35435 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
35436 typedef uint32_t maskarray_t[5];
35437
35438 typedef struct drm_via_irq {
35439 - atomic_t irq_received;
35440 + atomic_unchecked_t irq_received;
35441 uint32_t pending_mask;
35442 uint32_t enable_mask;
35443 wait_queue_head_t irq_queue;
35444 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
35445 struct timeval last_vblank;
35446 int last_vblank_valid;
35447 unsigned usec_per_vblank;
35448 - atomic_t vbl_received;
35449 + atomic_unchecked_t vbl_received;
35450 drm_via_state_t hc_state;
35451 char pci_buf[VIA_PCI_BUF_SIZE];
35452 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
35453 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
35454 index ac98964..5dbf512 100644
35455 --- a/drivers/gpu/drm/via/via_irq.c
35456 +++ b/drivers/gpu/drm/via/via_irq.c
35457 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
35458 if (crtc != 0)
35459 return 0;
35460
35461 - return atomic_read(&dev_priv->vbl_received);
35462 + return atomic_read_unchecked(&dev_priv->vbl_received);
35463 }
35464
35465 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35466 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35467
35468 status = VIA_READ(VIA_REG_INTERRUPT);
35469 if (status & VIA_IRQ_VBLANK_PENDING) {
35470 - atomic_inc(&dev_priv->vbl_received);
35471 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
35472 + atomic_inc_unchecked(&dev_priv->vbl_received);
35473 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
35474 do_gettimeofday(&cur_vblank);
35475 if (dev_priv->last_vblank_valid) {
35476 dev_priv->usec_per_vblank =
35477 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35478 dev_priv->last_vblank = cur_vblank;
35479 dev_priv->last_vblank_valid = 1;
35480 }
35481 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
35482 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
35483 DRM_DEBUG("US per vblank is: %u\n",
35484 dev_priv->usec_per_vblank);
35485 }
35486 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35487
35488 for (i = 0; i < dev_priv->num_irqs; ++i) {
35489 if (status & cur_irq->pending_mask) {
35490 - atomic_inc(&cur_irq->irq_received);
35491 + atomic_inc_unchecked(&cur_irq->irq_received);
35492 DRM_WAKEUP(&cur_irq->irq_queue);
35493 handled = 1;
35494 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
35495 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
35496 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35497 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
35498 masks[irq][4]));
35499 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
35500 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
35501 } else {
35502 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35503 (((cur_irq_sequence =
35504 - atomic_read(&cur_irq->irq_received)) -
35505 + atomic_read_unchecked(&cur_irq->irq_received)) -
35506 *sequence) <= (1 << 23)));
35507 }
35508 *sequence = cur_irq_sequence;
35509 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
35510 }
35511
35512 for (i = 0; i < dev_priv->num_irqs; ++i) {
35513 - atomic_set(&cur_irq->irq_received, 0);
35514 + atomic_set_unchecked(&cur_irq->irq_received, 0);
35515 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
35516 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
35517 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
35518 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
35519 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
35520 case VIA_IRQ_RELATIVE:
35521 irqwait->request.sequence +=
35522 - atomic_read(&cur_irq->irq_received);
35523 + atomic_read_unchecked(&cur_irq->irq_received);
35524 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
35525 case VIA_IRQ_ABSOLUTE:
35526 break;
35527 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35528 index 13aeda7..4a952d1 100644
35529 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35530 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35531 @@ -290,7 +290,7 @@ struct vmw_private {
35532 * Fencing and IRQs.
35533 */
35534
35535 - atomic_t marker_seq;
35536 + atomic_unchecked_t marker_seq;
35537 wait_queue_head_t fence_queue;
35538 wait_queue_head_t fifo_queue;
35539 int fence_queue_waiters; /* Protected by hw_mutex */
35540 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35541 index 3eb1486..0a47ee9 100644
35542 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35543 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35544 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
35545 (unsigned int) min,
35546 (unsigned int) fifo->capabilities);
35547
35548 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35549 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35550 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
35551 vmw_marker_queue_init(&fifo->marker_queue);
35552 return vmw_fifo_send_fence(dev_priv, &dummy);
35553 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
35554 if (reserveable)
35555 iowrite32(bytes, fifo_mem +
35556 SVGA_FIFO_RESERVED);
35557 - return fifo_mem + (next_cmd >> 2);
35558 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
35559 } else {
35560 need_bounce = true;
35561 }
35562 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
35563
35564 fm = vmw_fifo_reserve(dev_priv, bytes);
35565 if (unlikely(fm == NULL)) {
35566 - *seqno = atomic_read(&dev_priv->marker_seq);
35567 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
35568 ret = -ENOMEM;
35569 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
35570 false, 3*HZ);
35571 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
35572 }
35573
35574 do {
35575 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
35576 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
35577 } while (*seqno == 0);
35578
35579 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
35580 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35581 index 4640adb..e1384ed 100644
35582 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35583 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35584 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
35585 * emitted. Then the fence is stale and signaled.
35586 */
35587
35588 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
35589 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
35590 > VMW_FENCE_WRAP);
35591
35592 return ret;
35593 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
35594
35595 if (fifo_idle)
35596 down_read(&fifo_state->rwsem);
35597 - signal_seq = atomic_read(&dev_priv->marker_seq);
35598 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
35599 ret = 0;
35600
35601 for (;;) {
35602 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35603 index 8a8725c..afed796 100644
35604 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35605 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35606 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
35607 while (!vmw_lag_lt(queue, us)) {
35608 spin_lock(&queue->lock);
35609 if (list_empty(&queue->head))
35610 - seqno = atomic_read(&dev_priv->marker_seq);
35611 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
35612 else {
35613 marker = list_first_entry(&queue->head,
35614 struct vmw_marker, head);
35615 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
35616 index ceb3040..6160c5c 100644
35617 --- a/drivers/hid/hid-core.c
35618 +++ b/drivers/hid/hid-core.c
35619 @@ -2242,7 +2242,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
35620
35621 int hid_add_device(struct hid_device *hdev)
35622 {
35623 - static atomic_t id = ATOMIC_INIT(0);
35624 + static atomic_unchecked_t id = ATOMIC_INIT(0);
35625 int ret;
35626
35627 if (WARN_ON(hdev->status & HID_STAT_ADDED))
35628 @@ -2276,7 +2276,7 @@ int hid_add_device(struct hid_device *hdev)
35629 /* XXX hack, any other cleaner solution after the driver core
35630 * is converted to allow more than 20 bytes as the device name? */
35631 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
35632 - hdev->vendor, hdev->product, atomic_inc_return(&id));
35633 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
35634
35635 hid_debug_register(hdev, dev_name(&hdev->dev));
35636 ret = device_add(&hdev->dev);
35637 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
35638 index eec3291..8ed706b 100644
35639 --- a/drivers/hid/hid-wiimote-debug.c
35640 +++ b/drivers/hid/hid-wiimote-debug.c
35641 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
35642 else if (size == 0)
35643 return -EIO;
35644
35645 - if (copy_to_user(u, buf, size))
35646 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
35647 return -EFAULT;
35648
35649 *off += size;
35650 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
35651 index 773a2f2..7ce08bc 100644
35652 --- a/drivers/hv/channel.c
35653 +++ b/drivers/hv/channel.c
35654 @@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
35655 int ret = 0;
35656 int t;
35657
35658 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
35659 - atomic_inc(&vmbus_connection.next_gpadl_handle);
35660 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
35661 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
35662
35663 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
35664 if (ret)
35665 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
35666 index 3648f8f..30ef30d 100644
35667 --- a/drivers/hv/hv.c
35668 +++ b/drivers/hv/hv.c
35669 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
35670 u64 output_address = (output) ? virt_to_phys(output) : 0;
35671 u32 output_address_hi = output_address >> 32;
35672 u32 output_address_lo = output_address & 0xFFFFFFFF;
35673 - void *hypercall_page = hv_context.hypercall_page;
35674 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
35675
35676 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
35677 "=a"(hv_status_lo) : "d" (control_hi),
35678 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
35679 index d8d1fad..b91caf7 100644
35680 --- a/drivers/hv/hyperv_vmbus.h
35681 +++ b/drivers/hv/hyperv_vmbus.h
35682 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
35683 struct vmbus_connection {
35684 enum vmbus_connect_state conn_state;
35685
35686 - atomic_t next_gpadl_handle;
35687 + atomic_unchecked_t next_gpadl_handle;
35688
35689 /*
35690 * Represents channel interrupts. Each bit position represents a
35691 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
35692 index 8e1a9ec..4687821 100644
35693 --- a/drivers/hv/vmbus_drv.c
35694 +++ b/drivers/hv/vmbus_drv.c
35695 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
35696 {
35697 int ret = 0;
35698
35699 - static atomic_t device_num = ATOMIC_INIT(0);
35700 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
35701
35702 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
35703 - atomic_inc_return(&device_num));
35704 + atomic_inc_return_unchecked(&device_num));
35705
35706 child_device_obj->device.bus = &hv_bus;
35707 child_device_obj->device.parent = &hv_acpi_dev->dev;
35708 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
35709 index 1672e2a..4a6297c 100644
35710 --- a/drivers/hwmon/acpi_power_meter.c
35711 +++ b/drivers/hwmon/acpi_power_meter.c
35712 @@ -117,7 +117,7 @@ struct sensor_template {
35713 struct device_attribute *devattr,
35714 const char *buf, size_t count);
35715 int index;
35716 -};
35717 +} __do_const;
35718
35719 /* Averaging interval */
35720 static int update_avg_interval(struct acpi_power_meter_resource *resource)
35721 @@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
35722 struct sensor_template *attrs)
35723 {
35724 struct device *dev = &resource->acpi_dev->dev;
35725 - struct sensor_device_attribute *sensors =
35726 + sensor_device_attribute_no_const *sensors =
35727 &resource->sensors[resource->num_sensors];
35728 int res = 0;
35729
35730 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
35731 index b41baff..4953e4d 100644
35732 --- a/drivers/hwmon/applesmc.c
35733 +++ b/drivers/hwmon/applesmc.c
35734 @@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
35735 {
35736 struct applesmc_node_group *grp;
35737 struct applesmc_dev_attr *node;
35738 - struct attribute *attr;
35739 + attribute_no_const *attr;
35740 int ret, i;
35741
35742 for (grp = groups; grp->format; grp++) {
35743 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
35744 index 56dbcfb..9874bf1 100644
35745 --- a/drivers/hwmon/asus_atk0110.c
35746 +++ b/drivers/hwmon/asus_atk0110.c
35747 @@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
35748 struct atk_sensor_data {
35749 struct list_head list;
35750 struct atk_data *data;
35751 - struct device_attribute label_attr;
35752 - struct device_attribute input_attr;
35753 - struct device_attribute limit1_attr;
35754 - struct device_attribute limit2_attr;
35755 + device_attribute_no_const label_attr;
35756 + device_attribute_no_const input_attr;
35757 + device_attribute_no_const limit1_attr;
35758 + device_attribute_no_const limit2_attr;
35759 char label_attr_name[ATTR_NAME_SIZE];
35760 char input_attr_name[ATTR_NAME_SIZE];
35761 char limit1_attr_name[ATTR_NAME_SIZE];
35762 @@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
35763 static struct device_attribute atk_name_attr =
35764 __ATTR(name, 0444, atk_name_show, NULL);
35765
35766 -static void atk_init_attribute(struct device_attribute *attr, char *name,
35767 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
35768 sysfs_show_func show)
35769 {
35770 sysfs_attr_init(&attr->attr);
35771 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
35772 index d64923d..72591e8 100644
35773 --- a/drivers/hwmon/coretemp.c
35774 +++ b/drivers/hwmon/coretemp.c
35775 @@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
35776 return NOTIFY_OK;
35777 }
35778
35779 -static struct notifier_block coretemp_cpu_notifier __refdata = {
35780 +static struct notifier_block coretemp_cpu_notifier = {
35781 .notifier_call = coretemp_cpu_callback,
35782 };
35783
35784 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
35785 index a14f634..2916ee2 100644
35786 --- a/drivers/hwmon/ibmaem.c
35787 +++ b/drivers/hwmon/ibmaem.c
35788 @@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
35789 struct aem_rw_sensor_template *rw)
35790 {
35791 struct device *dev = &data->pdev->dev;
35792 - struct sensor_device_attribute *sensors = data->sensors;
35793 + sensor_device_attribute_no_const *sensors = data->sensors;
35794 int err;
35795
35796 /* Set up read-only sensors */
35797 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
35798 index 7d19b1b..8fdaaac 100644
35799 --- a/drivers/hwmon/pmbus/pmbus_core.c
35800 +++ b/drivers/hwmon/pmbus/pmbus_core.c
35801 @@ -811,7 +811,7 @@ static ssize_t pmbus_show_label(struct device *dev,
35802
35803 #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \
35804 do { \
35805 - struct sensor_device_attribute *a \
35806 + sensor_device_attribute_no_const *a \
35807 = &data->_type##s[data->num_##_type##s].attribute; \
35808 BUG_ON(data->num_attributes >= data->max_attributes); \
35809 sysfs_attr_init(&a->dev_attr.attr); \
35810 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
35811 index 8047fed..1e956f0 100644
35812 --- a/drivers/hwmon/sht15.c
35813 +++ b/drivers/hwmon/sht15.c
35814 @@ -169,7 +169,7 @@ struct sht15_data {
35815 int supply_uV;
35816 bool supply_uV_valid;
35817 struct work_struct update_supply_work;
35818 - atomic_t interrupt_handled;
35819 + atomic_unchecked_t interrupt_handled;
35820 };
35821
35822 /**
35823 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
35824 return ret;
35825
35826 gpio_direction_input(data->pdata->gpio_data);
35827 - atomic_set(&data->interrupt_handled, 0);
35828 + atomic_set_unchecked(&data->interrupt_handled, 0);
35829
35830 enable_irq(gpio_to_irq(data->pdata->gpio_data));
35831 if (gpio_get_value(data->pdata->gpio_data) == 0) {
35832 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
35833 /* Only relevant if the interrupt hasn't occurred. */
35834 - if (!atomic_read(&data->interrupt_handled))
35835 + if (!atomic_read_unchecked(&data->interrupt_handled))
35836 schedule_work(&data->read_work);
35837 }
35838 ret = wait_event_timeout(data->wait_queue,
35839 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
35840
35841 /* First disable the interrupt */
35842 disable_irq_nosync(irq);
35843 - atomic_inc(&data->interrupt_handled);
35844 + atomic_inc_unchecked(&data->interrupt_handled);
35845 /* Then schedule a reading work struct */
35846 if (data->state != SHT15_READING_NOTHING)
35847 schedule_work(&data->read_work);
35848 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
35849 * If not, then start the interrupt again - care here as could
35850 * have gone low in meantime so verify it hasn't!
35851 */
35852 - atomic_set(&data->interrupt_handled, 0);
35853 + atomic_set_unchecked(&data->interrupt_handled, 0);
35854 enable_irq(gpio_to_irq(data->pdata->gpio_data));
35855 /* If still not occurred or another handler was scheduled */
35856 if (gpio_get_value(data->pdata->gpio_data)
35857 - || atomic_read(&data->interrupt_handled))
35858 + || atomic_read_unchecked(&data->interrupt_handled))
35859 return;
35860 }
35861
35862 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
35863 index 76f157b..9c0db1b 100644
35864 --- a/drivers/hwmon/via-cputemp.c
35865 +++ b/drivers/hwmon/via-cputemp.c
35866 @@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
35867 return NOTIFY_OK;
35868 }
35869
35870 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
35871 +static struct notifier_block via_cputemp_cpu_notifier = {
35872 .notifier_call = via_cputemp_cpu_callback,
35873 };
35874
35875 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
35876 index 378fcb5..5e91fa8 100644
35877 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
35878 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
35879 @@ -43,7 +43,7 @@
35880 extern struct i2c_adapter amd756_smbus;
35881
35882 static struct i2c_adapter *s4882_adapter;
35883 -static struct i2c_algorithm *s4882_algo;
35884 +static i2c_algorithm_no_const *s4882_algo;
35885
35886 /* Wrapper access functions for multiplexed SMBus */
35887 static DEFINE_MUTEX(amd756_lock);
35888 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
35889 index 29015eb..af2d8e9 100644
35890 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
35891 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
35892 @@ -41,7 +41,7 @@
35893 extern struct i2c_adapter *nforce2_smbus;
35894
35895 static struct i2c_adapter *s4985_adapter;
35896 -static struct i2c_algorithm *s4985_algo;
35897 +static i2c_algorithm_no_const *s4985_algo;
35898
35899 /* Wrapper access functions for multiplexed SMBus */
35900 static DEFINE_MUTEX(nforce2_lock);
35901 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
35902 index 8126824..55a2798 100644
35903 --- a/drivers/ide/ide-cd.c
35904 +++ b/drivers/ide/ide-cd.c
35905 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
35906 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
35907 if ((unsigned long)buf & alignment
35908 || blk_rq_bytes(rq) & q->dma_pad_mask
35909 - || object_is_on_stack(buf))
35910 + || object_starts_on_stack(buf))
35911 drive->dma = 0;
35912 }
35913 }
35914 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
35915 index 8848f16..f8e6dd8 100644
35916 --- a/drivers/iio/industrialio-core.c
35917 +++ b/drivers/iio/industrialio-core.c
35918 @@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
35919 }
35920
35921 static
35922 -int __iio_device_attr_init(struct device_attribute *dev_attr,
35923 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
35924 const char *postfix,
35925 struct iio_chan_spec const *chan,
35926 ssize_t (*readfunc)(struct device *dev,
35927 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
35928 index 394fea2..c833880 100644
35929 --- a/drivers/infiniband/core/cm.c
35930 +++ b/drivers/infiniband/core/cm.c
35931 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
35932
35933 struct cm_counter_group {
35934 struct kobject obj;
35935 - atomic_long_t counter[CM_ATTR_COUNT];
35936 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
35937 };
35938
35939 struct cm_counter_attribute {
35940 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
35941 struct ib_mad_send_buf *msg = NULL;
35942 int ret;
35943
35944 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
35945 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
35946 counter[CM_REQ_COUNTER]);
35947
35948 /* Quick state check to discard duplicate REQs. */
35949 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
35950 if (!cm_id_priv)
35951 return;
35952
35953 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
35954 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
35955 counter[CM_REP_COUNTER]);
35956 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
35957 if (ret)
35958 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
35959 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
35960 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
35961 spin_unlock_irq(&cm_id_priv->lock);
35962 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
35963 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
35964 counter[CM_RTU_COUNTER]);
35965 goto out;
35966 }
35967 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
35968 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
35969 dreq_msg->local_comm_id);
35970 if (!cm_id_priv) {
35971 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
35972 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
35973 counter[CM_DREQ_COUNTER]);
35974 cm_issue_drep(work->port, work->mad_recv_wc);
35975 return -EINVAL;
35976 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
35977 case IB_CM_MRA_REP_RCVD:
35978 break;
35979 case IB_CM_TIMEWAIT:
35980 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
35981 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
35982 counter[CM_DREQ_COUNTER]);
35983 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
35984 goto unlock;
35985 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
35986 cm_free_msg(msg);
35987 goto deref;
35988 case IB_CM_DREQ_RCVD:
35989 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
35990 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
35991 counter[CM_DREQ_COUNTER]);
35992 goto unlock;
35993 default:
35994 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
35995 ib_modify_mad(cm_id_priv->av.port->mad_agent,
35996 cm_id_priv->msg, timeout)) {
35997 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
35998 - atomic_long_inc(&work->port->
35999 + atomic_long_inc_unchecked(&work->port->
36000 counter_group[CM_RECV_DUPLICATES].
36001 counter[CM_MRA_COUNTER]);
36002 goto out;
36003 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
36004 break;
36005 case IB_CM_MRA_REQ_RCVD:
36006 case IB_CM_MRA_REP_RCVD:
36007 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36008 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36009 counter[CM_MRA_COUNTER]);
36010 /* fall through */
36011 default:
36012 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
36013 case IB_CM_LAP_IDLE:
36014 break;
36015 case IB_CM_MRA_LAP_SENT:
36016 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36017 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36018 counter[CM_LAP_COUNTER]);
36019 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36020 goto unlock;
36021 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
36022 cm_free_msg(msg);
36023 goto deref;
36024 case IB_CM_LAP_RCVD:
36025 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36026 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36027 counter[CM_LAP_COUNTER]);
36028 goto unlock;
36029 default:
36030 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36031 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36032 if (cur_cm_id_priv) {
36033 spin_unlock_irq(&cm.lock);
36034 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36035 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36036 counter[CM_SIDR_REQ_COUNTER]);
36037 goto out; /* Duplicate message. */
36038 }
36039 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36040 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36041 msg->retries = 1;
36042
36043 - atomic_long_add(1 + msg->retries,
36044 + atomic_long_add_unchecked(1 + msg->retries,
36045 &port->counter_group[CM_XMIT].counter[attr_index]);
36046 if (msg->retries)
36047 - atomic_long_add(msg->retries,
36048 + atomic_long_add_unchecked(msg->retries,
36049 &port->counter_group[CM_XMIT_RETRIES].
36050 counter[attr_index]);
36051
36052 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36053 }
36054
36055 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36056 - atomic_long_inc(&port->counter_group[CM_RECV].
36057 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36058 counter[attr_id - CM_ATTR_ID_OFFSET]);
36059
36060 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36061 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36062 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36063
36064 return sprintf(buf, "%ld\n",
36065 - atomic_long_read(&group->counter[cm_attr->index]));
36066 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36067 }
36068
36069 static const struct sysfs_ops cm_counter_ops = {
36070 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36071 index 176c8f9..2627b62 100644
36072 --- a/drivers/infiniband/core/fmr_pool.c
36073 +++ b/drivers/infiniband/core/fmr_pool.c
36074 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
36075
36076 struct task_struct *thread;
36077
36078 - atomic_t req_ser;
36079 - atomic_t flush_ser;
36080 + atomic_unchecked_t req_ser;
36081 + atomic_unchecked_t flush_ser;
36082
36083 wait_queue_head_t force_wait;
36084 };
36085 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36086 struct ib_fmr_pool *pool = pool_ptr;
36087
36088 do {
36089 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
36090 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
36091 ib_fmr_batch_release(pool);
36092
36093 - atomic_inc(&pool->flush_ser);
36094 + atomic_inc_unchecked(&pool->flush_ser);
36095 wake_up_interruptible(&pool->force_wait);
36096
36097 if (pool->flush_function)
36098 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36099 }
36100
36101 set_current_state(TASK_INTERRUPTIBLE);
36102 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
36103 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
36104 !kthread_should_stop())
36105 schedule();
36106 __set_current_state(TASK_RUNNING);
36107 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
36108 pool->dirty_watermark = params->dirty_watermark;
36109 pool->dirty_len = 0;
36110 spin_lock_init(&pool->pool_lock);
36111 - atomic_set(&pool->req_ser, 0);
36112 - atomic_set(&pool->flush_ser, 0);
36113 + atomic_set_unchecked(&pool->req_ser, 0);
36114 + atomic_set_unchecked(&pool->flush_ser, 0);
36115 init_waitqueue_head(&pool->force_wait);
36116
36117 pool->thread = kthread_run(ib_fmr_cleanup_thread,
36118 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
36119 }
36120 spin_unlock_irq(&pool->pool_lock);
36121
36122 - serial = atomic_inc_return(&pool->req_ser);
36123 + serial = atomic_inc_return_unchecked(&pool->req_ser);
36124 wake_up_process(pool->thread);
36125
36126 if (wait_event_interruptible(pool->force_wait,
36127 - atomic_read(&pool->flush_ser) - serial >= 0))
36128 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
36129 return -EINTR;
36130
36131 return 0;
36132 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
36133 } else {
36134 list_add_tail(&fmr->list, &pool->dirty_list);
36135 if (++pool->dirty_len >= pool->dirty_watermark) {
36136 - atomic_inc(&pool->req_ser);
36137 + atomic_inc_unchecked(&pool->req_ser);
36138 wake_up_process(pool->thread);
36139 }
36140 }
36141 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
36142 index afd8179..598063f 100644
36143 --- a/drivers/infiniband/hw/cxgb4/mem.c
36144 +++ b/drivers/infiniband/hw/cxgb4/mem.c
36145 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36146 int err;
36147 struct fw_ri_tpte tpt;
36148 u32 stag_idx;
36149 - static atomic_t key;
36150 + static atomic_unchecked_t key;
36151
36152 if (c4iw_fatal_error(rdev))
36153 return -EIO;
36154 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36155 if (rdev->stats.stag.cur > rdev->stats.stag.max)
36156 rdev->stats.stag.max = rdev->stats.stag.cur;
36157 mutex_unlock(&rdev->stats.lock);
36158 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
36159 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
36160 }
36161 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
36162 __func__, stag_state, type, pdid, stag_idx);
36163 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
36164 index 79b3dbc..96e5fcc 100644
36165 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
36166 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
36167 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36168 struct ib_atomic_eth *ateth;
36169 struct ipath_ack_entry *e;
36170 u64 vaddr;
36171 - atomic64_t *maddr;
36172 + atomic64_unchecked_t *maddr;
36173 u64 sdata;
36174 u32 rkey;
36175 u8 next;
36176 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36177 IB_ACCESS_REMOTE_ATOMIC)))
36178 goto nack_acc_unlck;
36179 /* Perform atomic OP and save result. */
36180 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36181 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36182 sdata = be64_to_cpu(ateth->swap_data);
36183 e = &qp->s_ack_queue[qp->r_head_ack_queue];
36184 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
36185 - (u64) atomic64_add_return(sdata, maddr) - sdata :
36186 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36187 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36188 be64_to_cpu(ateth->compare_data),
36189 sdata);
36190 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
36191 index 1f95bba..9530f87 100644
36192 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
36193 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
36194 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
36195 unsigned long flags;
36196 struct ib_wc wc;
36197 u64 sdata;
36198 - atomic64_t *maddr;
36199 + atomic64_unchecked_t *maddr;
36200 enum ib_wc_status send_status;
36201
36202 /*
36203 @@ -382,11 +382,11 @@ again:
36204 IB_ACCESS_REMOTE_ATOMIC)))
36205 goto acc_err;
36206 /* Perform atomic OP and save result. */
36207 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36208 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36209 sdata = wqe->wr.wr.atomic.compare_add;
36210 *(u64 *) sqp->s_sge.sge.vaddr =
36211 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
36212 - (u64) atomic64_add_return(sdata, maddr) - sdata :
36213 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36214 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36215 sdata, wqe->wr.wr.atomic.swap);
36216 goto send_comp;
36217 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
36218 index 5b152a3..c1f3e83 100644
36219 --- a/drivers/infiniband/hw/nes/nes.c
36220 +++ b/drivers/infiniband/hw/nes/nes.c
36221 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
36222 LIST_HEAD(nes_adapter_list);
36223 static LIST_HEAD(nes_dev_list);
36224
36225 -atomic_t qps_destroyed;
36226 +atomic_unchecked_t qps_destroyed;
36227
36228 static unsigned int ee_flsh_adapter;
36229 static unsigned int sysfs_nonidx_addr;
36230 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
36231 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
36232 struct nes_adapter *nesadapter = nesdev->nesadapter;
36233
36234 - atomic_inc(&qps_destroyed);
36235 + atomic_inc_unchecked(&qps_destroyed);
36236
36237 /* Free the control structures */
36238
36239 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
36240 index 33cc589..3bd6538 100644
36241 --- a/drivers/infiniband/hw/nes/nes.h
36242 +++ b/drivers/infiniband/hw/nes/nes.h
36243 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
36244 extern unsigned int wqm_quanta;
36245 extern struct list_head nes_adapter_list;
36246
36247 -extern atomic_t cm_connects;
36248 -extern atomic_t cm_accepts;
36249 -extern atomic_t cm_disconnects;
36250 -extern atomic_t cm_closes;
36251 -extern atomic_t cm_connecteds;
36252 -extern atomic_t cm_connect_reqs;
36253 -extern atomic_t cm_rejects;
36254 -extern atomic_t mod_qp_timouts;
36255 -extern atomic_t qps_created;
36256 -extern atomic_t qps_destroyed;
36257 -extern atomic_t sw_qps_destroyed;
36258 +extern atomic_unchecked_t cm_connects;
36259 +extern atomic_unchecked_t cm_accepts;
36260 +extern atomic_unchecked_t cm_disconnects;
36261 +extern atomic_unchecked_t cm_closes;
36262 +extern atomic_unchecked_t cm_connecteds;
36263 +extern atomic_unchecked_t cm_connect_reqs;
36264 +extern atomic_unchecked_t cm_rejects;
36265 +extern atomic_unchecked_t mod_qp_timouts;
36266 +extern atomic_unchecked_t qps_created;
36267 +extern atomic_unchecked_t qps_destroyed;
36268 +extern atomic_unchecked_t sw_qps_destroyed;
36269 extern u32 mh_detected;
36270 extern u32 mh_pauses_sent;
36271 extern u32 cm_packets_sent;
36272 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
36273 extern u32 cm_packets_received;
36274 extern u32 cm_packets_dropped;
36275 extern u32 cm_packets_retrans;
36276 -extern atomic_t cm_listens_created;
36277 -extern atomic_t cm_listens_destroyed;
36278 +extern atomic_unchecked_t cm_listens_created;
36279 +extern atomic_unchecked_t cm_listens_destroyed;
36280 extern u32 cm_backlog_drops;
36281 -extern atomic_t cm_loopbacks;
36282 -extern atomic_t cm_nodes_created;
36283 -extern atomic_t cm_nodes_destroyed;
36284 -extern atomic_t cm_accel_dropped_pkts;
36285 -extern atomic_t cm_resets_recvd;
36286 -extern atomic_t pau_qps_created;
36287 -extern atomic_t pau_qps_destroyed;
36288 +extern atomic_unchecked_t cm_loopbacks;
36289 +extern atomic_unchecked_t cm_nodes_created;
36290 +extern atomic_unchecked_t cm_nodes_destroyed;
36291 +extern atomic_unchecked_t cm_accel_dropped_pkts;
36292 +extern atomic_unchecked_t cm_resets_recvd;
36293 +extern atomic_unchecked_t pau_qps_created;
36294 +extern atomic_unchecked_t pau_qps_destroyed;
36295
36296 extern u32 int_mod_timer_init;
36297 extern u32 int_mod_cq_depth_256;
36298 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
36299 index 22ea67e..dcbe3bc 100644
36300 --- a/drivers/infiniband/hw/nes/nes_cm.c
36301 +++ b/drivers/infiniband/hw/nes/nes_cm.c
36302 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
36303 u32 cm_packets_retrans;
36304 u32 cm_packets_created;
36305 u32 cm_packets_received;
36306 -atomic_t cm_listens_created;
36307 -atomic_t cm_listens_destroyed;
36308 +atomic_unchecked_t cm_listens_created;
36309 +atomic_unchecked_t cm_listens_destroyed;
36310 u32 cm_backlog_drops;
36311 -atomic_t cm_loopbacks;
36312 -atomic_t cm_nodes_created;
36313 -atomic_t cm_nodes_destroyed;
36314 -atomic_t cm_accel_dropped_pkts;
36315 -atomic_t cm_resets_recvd;
36316 +atomic_unchecked_t cm_loopbacks;
36317 +atomic_unchecked_t cm_nodes_created;
36318 +atomic_unchecked_t cm_nodes_destroyed;
36319 +atomic_unchecked_t cm_accel_dropped_pkts;
36320 +atomic_unchecked_t cm_resets_recvd;
36321
36322 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
36323 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
36324 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
36325
36326 static struct nes_cm_core *g_cm_core;
36327
36328 -atomic_t cm_connects;
36329 -atomic_t cm_accepts;
36330 -atomic_t cm_disconnects;
36331 -atomic_t cm_closes;
36332 -atomic_t cm_connecteds;
36333 -atomic_t cm_connect_reqs;
36334 -atomic_t cm_rejects;
36335 +atomic_unchecked_t cm_connects;
36336 +atomic_unchecked_t cm_accepts;
36337 +atomic_unchecked_t cm_disconnects;
36338 +atomic_unchecked_t cm_closes;
36339 +atomic_unchecked_t cm_connecteds;
36340 +atomic_unchecked_t cm_connect_reqs;
36341 +atomic_unchecked_t cm_rejects;
36342
36343 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
36344 {
36345 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
36346 kfree(listener);
36347 listener = NULL;
36348 ret = 0;
36349 - atomic_inc(&cm_listens_destroyed);
36350 + atomic_inc_unchecked(&cm_listens_destroyed);
36351 } else {
36352 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
36353 }
36354 @@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
36355 cm_node->rem_mac);
36356
36357 add_hte_node(cm_core, cm_node);
36358 - atomic_inc(&cm_nodes_created);
36359 + atomic_inc_unchecked(&cm_nodes_created);
36360
36361 return cm_node;
36362 }
36363 @@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
36364 }
36365
36366 atomic_dec(&cm_core->node_cnt);
36367 - atomic_inc(&cm_nodes_destroyed);
36368 + atomic_inc_unchecked(&cm_nodes_destroyed);
36369 nesqp = cm_node->nesqp;
36370 if (nesqp) {
36371 nesqp->cm_node = NULL;
36372 @@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
36373
36374 static void drop_packet(struct sk_buff *skb)
36375 {
36376 - atomic_inc(&cm_accel_dropped_pkts);
36377 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
36378 dev_kfree_skb_any(skb);
36379 }
36380
36381 @@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
36382 {
36383
36384 int reset = 0; /* whether to send reset in case of err.. */
36385 - atomic_inc(&cm_resets_recvd);
36386 + atomic_inc_unchecked(&cm_resets_recvd);
36387 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
36388 " refcnt=%d\n", cm_node, cm_node->state,
36389 atomic_read(&cm_node->ref_count));
36390 @@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
36391 rem_ref_cm_node(cm_node->cm_core, cm_node);
36392 return NULL;
36393 }
36394 - atomic_inc(&cm_loopbacks);
36395 + atomic_inc_unchecked(&cm_loopbacks);
36396 loopbackremotenode->loopbackpartner = cm_node;
36397 loopbackremotenode->tcp_cntxt.rcv_wscale =
36398 NES_CM_DEFAULT_RCV_WND_SCALE;
36399 @@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
36400 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
36401 else {
36402 rem_ref_cm_node(cm_core, cm_node);
36403 - atomic_inc(&cm_accel_dropped_pkts);
36404 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
36405 dev_kfree_skb_any(skb);
36406 }
36407 break;
36408 @@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36409
36410 if ((cm_id) && (cm_id->event_handler)) {
36411 if (issue_disconn) {
36412 - atomic_inc(&cm_disconnects);
36413 + atomic_inc_unchecked(&cm_disconnects);
36414 cm_event.event = IW_CM_EVENT_DISCONNECT;
36415 cm_event.status = disconn_status;
36416 cm_event.local_addr = cm_id->local_addr;
36417 @@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36418 }
36419
36420 if (issue_close) {
36421 - atomic_inc(&cm_closes);
36422 + atomic_inc_unchecked(&cm_closes);
36423 nes_disconnect(nesqp, 1);
36424
36425 cm_id->provider_data = nesqp;
36426 @@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36427
36428 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
36429 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
36430 - atomic_inc(&cm_accepts);
36431 + atomic_inc_unchecked(&cm_accepts);
36432
36433 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
36434 netdev_refcnt_read(nesvnic->netdev));
36435 @@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
36436 struct nes_cm_core *cm_core;
36437 u8 *start_buff;
36438
36439 - atomic_inc(&cm_rejects);
36440 + atomic_inc_unchecked(&cm_rejects);
36441 cm_node = (struct nes_cm_node *)cm_id->provider_data;
36442 loopback = cm_node->loopbackpartner;
36443 cm_core = cm_node->cm_core;
36444 @@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36445 ntohl(cm_id->local_addr.sin_addr.s_addr),
36446 ntohs(cm_id->local_addr.sin_port));
36447
36448 - atomic_inc(&cm_connects);
36449 + atomic_inc_unchecked(&cm_connects);
36450 nesqp->active_conn = 1;
36451
36452 /* cache the cm_id in the qp */
36453 @@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
36454 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
36455 return err;
36456 }
36457 - atomic_inc(&cm_listens_created);
36458 + atomic_inc_unchecked(&cm_listens_created);
36459 }
36460
36461 cm_id->add_ref(cm_id);
36462 @@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
36463
36464 if (nesqp->destroyed)
36465 return;
36466 - atomic_inc(&cm_connecteds);
36467 + atomic_inc_unchecked(&cm_connecteds);
36468 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
36469 " local port 0x%04X. jiffies = %lu.\n",
36470 nesqp->hwqp.qp_id,
36471 @@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
36472
36473 cm_id->add_ref(cm_id);
36474 ret = cm_id->event_handler(cm_id, &cm_event);
36475 - atomic_inc(&cm_closes);
36476 + atomic_inc_unchecked(&cm_closes);
36477 cm_event.event = IW_CM_EVENT_CLOSE;
36478 cm_event.status = 0;
36479 cm_event.provider_data = cm_id->provider_data;
36480 @@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
36481 return;
36482 cm_id = cm_node->cm_id;
36483
36484 - atomic_inc(&cm_connect_reqs);
36485 + atomic_inc_unchecked(&cm_connect_reqs);
36486 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36487 cm_node, cm_id, jiffies);
36488
36489 @@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
36490 return;
36491 cm_id = cm_node->cm_id;
36492
36493 - atomic_inc(&cm_connect_reqs);
36494 + atomic_inc_unchecked(&cm_connect_reqs);
36495 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36496 cm_node, cm_id, jiffies);
36497
36498 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
36499 index 4166452..fc952c3 100644
36500 --- a/drivers/infiniband/hw/nes/nes_mgt.c
36501 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
36502 @@ -40,8 +40,8 @@
36503 #include "nes.h"
36504 #include "nes_mgt.h"
36505
36506 -atomic_t pau_qps_created;
36507 -atomic_t pau_qps_destroyed;
36508 +atomic_unchecked_t pau_qps_created;
36509 +atomic_unchecked_t pau_qps_destroyed;
36510
36511 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
36512 {
36513 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
36514 {
36515 struct sk_buff *skb;
36516 unsigned long flags;
36517 - atomic_inc(&pau_qps_destroyed);
36518 + atomic_inc_unchecked(&pau_qps_destroyed);
36519
36520 /* Free packets that have not yet been forwarded */
36521 /* Lock is acquired by skb_dequeue when removing the skb */
36522 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
36523 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
36524 skb_queue_head_init(&nesqp->pau_list);
36525 spin_lock_init(&nesqp->pau_lock);
36526 - atomic_inc(&pau_qps_created);
36527 + atomic_inc_unchecked(&pau_qps_created);
36528 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
36529 }
36530
36531 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
36532 index 9542e16..a008c40 100644
36533 --- a/drivers/infiniband/hw/nes/nes_nic.c
36534 +++ b/drivers/infiniband/hw/nes/nes_nic.c
36535 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
36536 target_stat_values[++index] = mh_detected;
36537 target_stat_values[++index] = mh_pauses_sent;
36538 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
36539 - target_stat_values[++index] = atomic_read(&cm_connects);
36540 - target_stat_values[++index] = atomic_read(&cm_accepts);
36541 - target_stat_values[++index] = atomic_read(&cm_disconnects);
36542 - target_stat_values[++index] = atomic_read(&cm_connecteds);
36543 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
36544 - target_stat_values[++index] = atomic_read(&cm_rejects);
36545 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
36546 - target_stat_values[++index] = atomic_read(&qps_created);
36547 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
36548 - target_stat_values[++index] = atomic_read(&qps_destroyed);
36549 - target_stat_values[++index] = atomic_read(&cm_closes);
36550 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
36551 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
36552 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
36553 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
36554 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
36555 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
36556 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
36557 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
36558 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
36559 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
36560 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
36561 target_stat_values[++index] = cm_packets_sent;
36562 target_stat_values[++index] = cm_packets_bounced;
36563 target_stat_values[++index] = cm_packets_created;
36564 target_stat_values[++index] = cm_packets_received;
36565 target_stat_values[++index] = cm_packets_dropped;
36566 target_stat_values[++index] = cm_packets_retrans;
36567 - target_stat_values[++index] = atomic_read(&cm_listens_created);
36568 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
36569 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
36570 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
36571 target_stat_values[++index] = cm_backlog_drops;
36572 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
36573 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
36574 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
36575 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
36576 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
36577 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
36578 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
36579 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
36580 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
36581 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
36582 target_stat_values[++index] = nesadapter->free_4kpbl;
36583 target_stat_values[++index] = nesadapter->free_256pbl;
36584 target_stat_values[++index] = int_mod_timer_init;
36585 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
36586 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
36587 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
36588 - target_stat_values[++index] = atomic_read(&pau_qps_created);
36589 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
36590 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
36591 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
36592 }
36593
36594 /**
36595 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
36596 index 07e4fba..685f041 100644
36597 --- a/drivers/infiniband/hw/nes/nes_verbs.c
36598 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
36599 @@ -46,9 +46,9 @@
36600
36601 #include <rdma/ib_umem.h>
36602
36603 -atomic_t mod_qp_timouts;
36604 -atomic_t qps_created;
36605 -atomic_t sw_qps_destroyed;
36606 +atomic_unchecked_t mod_qp_timouts;
36607 +atomic_unchecked_t qps_created;
36608 +atomic_unchecked_t sw_qps_destroyed;
36609
36610 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
36611
36612 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
36613 if (init_attr->create_flags)
36614 return ERR_PTR(-EINVAL);
36615
36616 - atomic_inc(&qps_created);
36617 + atomic_inc_unchecked(&qps_created);
36618 switch (init_attr->qp_type) {
36619 case IB_QPT_RC:
36620 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
36621 @@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
36622 struct iw_cm_event cm_event;
36623 int ret = 0;
36624
36625 - atomic_inc(&sw_qps_destroyed);
36626 + atomic_inc_unchecked(&sw_qps_destroyed);
36627 nesqp->destroyed = 1;
36628
36629 /* Blow away the connection if it exists. */
36630 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
36631 index 4d11575..3e890e5 100644
36632 --- a/drivers/infiniband/hw/qib/qib.h
36633 +++ b/drivers/infiniband/hw/qib/qib.h
36634 @@ -51,6 +51,7 @@
36635 #include <linux/completion.h>
36636 #include <linux/kref.h>
36637 #include <linux/sched.h>
36638 +#include <linux/slab.h>
36639
36640 #include "qib_common.h"
36641 #include "qib_verbs.h"
36642 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
36643 index da739d9..da1c7f4 100644
36644 --- a/drivers/input/gameport/gameport.c
36645 +++ b/drivers/input/gameport/gameport.c
36646 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
36647 */
36648 static void gameport_init_port(struct gameport *gameport)
36649 {
36650 - static atomic_t gameport_no = ATOMIC_INIT(0);
36651 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
36652
36653 __module_get(THIS_MODULE);
36654
36655 mutex_init(&gameport->drv_mutex);
36656 device_initialize(&gameport->dev);
36657 dev_set_name(&gameport->dev, "gameport%lu",
36658 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
36659 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
36660 gameport->dev.bus = &gameport_bus;
36661 gameport->dev.release = gameport_release_port;
36662 if (gameport->parent)
36663 diff --git a/drivers/input/input.c b/drivers/input/input.c
36664 index c044699..174d71a 100644
36665 --- a/drivers/input/input.c
36666 +++ b/drivers/input/input.c
36667 @@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
36668 */
36669 int input_register_device(struct input_dev *dev)
36670 {
36671 - static atomic_t input_no = ATOMIC_INIT(0);
36672 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
36673 struct input_devres *devres = NULL;
36674 struct input_handler *handler;
36675 unsigned int packet_size;
36676 @@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
36677 dev->setkeycode = input_default_setkeycode;
36678
36679 dev_set_name(&dev->dev, "input%ld",
36680 - (unsigned long) atomic_inc_return(&input_no) - 1);
36681 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
36682
36683 error = device_add(&dev->dev);
36684 if (error)
36685 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
36686 index 04c69af..5f92d00 100644
36687 --- a/drivers/input/joystick/sidewinder.c
36688 +++ b/drivers/input/joystick/sidewinder.c
36689 @@ -30,6 +30,7 @@
36690 #include <linux/kernel.h>
36691 #include <linux/module.h>
36692 #include <linux/slab.h>
36693 +#include <linux/sched.h>
36694 #include <linux/init.h>
36695 #include <linux/input.h>
36696 #include <linux/gameport.h>
36697 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
36698 index d6cbfe9..6225402 100644
36699 --- a/drivers/input/joystick/xpad.c
36700 +++ b/drivers/input/joystick/xpad.c
36701 @@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
36702
36703 static int xpad_led_probe(struct usb_xpad *xpad)
36704 {
36705 - static atomic_t led_seq = ATOMIC_INIT(0);
36706 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
36707 long led_no;
36708 struct xpad_led *led;
36709 struct led_classdev *led_cdev;
36710 @@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
36711 if (!led)
36712 return -ENOMEM;
36713
36714 - led_no = (long)atomic_inc_return(&led_seq) - 1;
36715 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
36716
36717 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
36718 led->xpad = xpad;
36719 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
36720 index fe1df23..5b710f3 100644
36721 --- a/drivers/input/mouse/psmouse.h
36722 +++ b/drivers/input/mouse/psmouse.h
36723 @@ -115,7 +115,7 @@ struct psmouse_attribute {
36724 ssize_t (*set)(struct psmouse *psmouse, void *data,
36725 const char *buf, size_t count);
36726 bool protect;
36727 -};
36728 +} __do_const;
36729 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
36730
36731 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
36732 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
36733 index 4c842c3..590b0bf 100644
36734 --- a/drivers/input/mousedev.c
36735 +++ b/drivers/input/mousedev.c
36736 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
36737
36738 spin_unlock_irq(&client->packet_lock);
36739
36740 - if (copy_to_user(buffer, data, count))
36741 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
36742 return -EFAULT;
36743
36744 return count;
36745 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
36746 index 25fc597..558bf3b 100644
36747 --- a/drivers/input/serio/serio.c
36748 +++ b/drivers/input/serio/serio.c
36749 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
36750 */
36751 static void serio_init_port(struct serio *serio)
36752 {
36753 - static atomic_t serio_no = ATOMIC_INIT(0);
36754 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
36755
36756 __module_get(THIS_MODULE);
36757
36758 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
36759 mutex_init(&serio->drv_mutex);
36760 device_initialize(&serio->dev);
36761 dev_set_name(&serio->dev, "serio%ld",
36762 - (long)atomic_inc_return(&serio_no) - 1);
36763 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
36764 serio->dev.bus = &serio_bus;
36765 serio->dev.release = serio_release_port;
36766 serio->dev.groups = serio_device_attr_groups;
36767 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
36768 index ddbdaca..be18a78 100644
36769 --- a/drivers/iommu/iommu.c
36770 +++ b/drivers/iommu/iommu.c
36771 @@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
36772 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
36773 {
36774 bus_register_notifier(bus, &iommu_bus_nb);
36775 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
36776 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
36777 }
36778
36779 /**
36780 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
36781 index 89562a8..218999b 100644
36782 --- a/drivers/isdn/capi/capi.c
36783 +++ b/drivers/isdn/capi/capi.c
36784 @@ -81,8 +81,8 @@ struct capiminor {
36785
36786 struct capi20_appl *ap;
36787 u32 ncci;
36788 - atomic_t datahandle;
36789 - atomic_t msgid;
36790 + atomic_unchecked_t datahandle;
36791 + atomic_unchecked_t msgid;
36792
36793 struct tty_port port;
36794 int ttyinstop;
36795 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
36796 capimsg_setu16(s, 2, mp->ap->applid);
36797 capimsg_setu8 (s, 4, CAPI_DATA_B3);
36798 capimsg_setu8 (s, 5, CAPI_RESP);
36799 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
36800 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
36801 capimsg_setu32(s, 8, mp->ncci);
36802 capimsg_setu16(s, 12, datahandle);
36803 }
36804 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
36805 mp->outbytes -= len;
36806 spin_unlock_bh(&mp->outlock);
36807
36808 - datahandle = atomic_inc_return(&mp->datahandle);
36809 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
36810 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
36811 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
36812 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
36813 capimsg_setu16(skb->data, 2, mp->ap->applid);
36814 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
36815 capimsg_setu8 (skb->data, 5, CAPI_REQ);
36816 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
36817 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
36818 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
36819 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
36820 capimsg_setu16(skb->data, 16, len); /* Data length */
36821 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
36822 index 67abf3f..076b3a6 100644
36823 --- a/drivers/isdn/gigaset/interface.c
36824 +++ b/drivers/isdn/gigaset/interface.c
36825 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
36826 }
36827 tty->driver_data = cs;
36828
36829 - ++cs->port.count;
36830 + atomic_inc(&cs->port.count);
36831
36832 - if (cs->port.count == 1) {
36833 + if (atomic_read(&cs->port.count) == 1) {
36834 tty_port_tty_set(&cs->port, tty);
36835 tty->low_latency = 1;
36836 }
36837 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
36838
36839 if (!cs->connected)
36840 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
36841 - else if (!cs->port.count)
36842 + else if (!atomic_read(&cs->port.count))
36843 dev_warn(cs->dev, "%s: device not opened\n", __func__);
36844 - else if (!--cs->port.count)
36845 + else if (!atomic_dec_return(&cs->port.count))
36846 tty_port_tty_set(&cs->port, NULL);
36847
36848 mutex_unlock(&cs->mutex);
36849 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
36850 index 821f7ac..28d4030 100644
36851 --- a/drivers/isdn/hardware/avm/b1.c
36852 +++ b/drivers/isdn/hardware/avm/b1.c
36853 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
36854 }
36855 if (left) {
36856 if (t4file->user) {
36857 - if (copy_from_user(buf, dp, left))
36858 + if (left > sizeof buf || copy_from_user(buf, dp, left))
36859 return -EFAULT;
36860 } else {
36861 memcpy(buf, dp, left);
36862 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
36863 }
36864 if (left) {
36865 if (config->user) {
36866 - if (copy_from_user(buf, dp, left))
36867 + if (left > sizeof buf || copy_from_user(buf, dp, left))
36868 return -EFAULT;
36869 } else {
36870 memcpy(buf, dp, left);
36871 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
36872 index e09dc8a..15e2efb 100644
36873 --- a/drivers/isdn/i4l/isdn_tty.c
36874 +++ b/drivers/isdn/i4l/isdn_tty.c
36875 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
36876
36877 #ifdef ISDN_DEBUG_MODEM_OPEN
36878 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
36879 - port->count);
36880 + atomic_read(&port->count));
36881 #endif
36882 - port->count++;
36883 + atomic_inc(&port->count);
36884 port->tty = tty;
36885 /*
36886 * Start up serial port
36887 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
36888 #endif
36889 return;
36890 }
36891 - if ((tty->count == 1) && (port->count != 1)) {
36892 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
36893 /*
36894 * Uh, oh. tty->count is 1, which means that the tty
36895 * structure will be freed. Info->count should always
36896 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
36897 * serial port won't be shutdown.
36898 */
36899 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
36900 - "info->count is %d\n", port->count);
36901 - port->count = 1;
36902 + "info->count is %d\n", atomic_read(&port->count));
36903 + atomic_set(&port->count, 1);
36904 }
36905 - if (--port->count < 0) {
36906 + if (atomic_dec_return(&port->count) < 0) {
36907 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
36908 - info->line, port->count);
36909 - port->count = 0;
36910 + info->line, atomic_read(&port->count));
36911 + atomic_set(&port->count, 0);
36912 }
36913 - if (port->count) {
36914 + if (atomic_read(&port->count)) {
36915 #ifdef ISDN_DEBUG_MODEM_OPEN
36916 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
36917 #endif
36918 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
36919 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
36920 return;
36921 isdn_tty_shutdown(info);
36922 - port->count = 0;
36923 + atomic_set(&port->count, 0);
36924 port->flags &= ~ASYNC_NORMAL_ACTIVE;
36925 port->tty = NULL;
36926 wake_up_interruptible(&port->open_wait);
36927 @@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
36928 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
36929 modem_info *info = &dev->mdm.info[i];
36930
36931 - if (info->port.count == 0)
36932 + if (atomic_read(&info->port.count) == 0)
36933 continue;
36934 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
36935 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
36936 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
36937 index e74df7c..03a03ba 100644
36938 --- a/drivers/isdn/icn/icn.c
36939 +++ b/drivers/isdn/icn/icn.c
36940 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
36941 if (count > len)
36942 count = len;
36943 if (user) {
36944 - if (copy_from_user(msg, buf, count))
36945 + if (count > sizeof msg || copy_from_user(msg, buf, count))
36946 return -EFAULT;
36947 } else
36948 memcpy(msg, buf, count);
36949 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
36950 index 6a8405d..0bd1c7e 100644
36951 --- a/drivers/leds/leds-clevo-mail.c
36952 +++ b/drivers/leds/leds-clevo-mail.c
36953 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
36954 * detected as working, but in reality it is not) as low as
36955 * possible.
36956 */
36957 -static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
36958 +static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
36959 {
36960 .callback = clevo_mail_led_dmi_callback,
36961 .ident = "Clevo D410J",
36962 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
36963 index ec9b287..65c9bf4 100644
36964 --- a/drivers/leds/leds-ss4200.c
36965 +++ b/drivers/leds/leds-ss4200.c
36966 @@ -92,7 +92,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
36967 * detected as working, but in reality it is not) as low as
36968 * possible.
36969 */
36970 -static struct dmi_system_id __initdata nas_led_whitelist[] = {
36971 +static const struct dmi_system_id __initconst nas_led_whitelist[] = {
36972 {
36973 .callback = ss4200_led_dmi_callback,
36974 .ident = "Intel SS4200-E",
36975 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
36976 index a5ebc00..982886f 100644
36977 --- a/drivers/lguest/core.c
36978 +++ b/drivers/lguest/core.c
36979 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
36980 * it's worked so far. The end address needs +1 because __get_vm_area
36981 * allocates an extra guard page, so we need space for that.
36982 */
36983 +
36984 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
36985 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
36986 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
36987 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
36988 +#else
36989 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
36990 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
36991 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
36992 +#endif
36993 +
36994 if (!switcher_vma) {
36995 err = -ENOMEM;
36996 printk("lguest: could not map switcher pages high\n");
36997 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
36998 * Now the Switcher is mapped at the right address, we can't fail!
36999 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
37000 */
37001 - memcpy(switcher_vma->addr, start_switcher_text,
37002 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
37003 end_switcher_text - start_switcher_text);
37004
37005 printk(KERN_INFO "lguest: mapped switcher at %p\n",
37006 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
37007 index 4af12e1..0e89afe 100644
37008 --- a/drivers/lguest/x86/core.c
37009 +++ b/drivers/lguest/x86/core.c
37010 @@ -59,7 +59,7 @@ static struct {
37011 /* Offset from where switcher.S was compiled to where we've copied it */
37012 static unsigned long switcher_offset(void)
37013 {
37014 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
37015 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
37016 }
37017
37018 /* This cpu's struct lguest_pages. */
37019 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37020 * These copies are pretty cheap, so we do them unconditionally: */
37021 /* Save the current Host top-level page directory.
37022 */
37023 +
37024 +#ifdef CONFIG_PAX_PER_CPU_PGD
37025 + pages->state.host_cr3 = read_cr3();
37026 +#else
37027 pages->state.host_cr3 = __pa(current->mm->pgd);
37028 +#endif
37029 +
37030 /*
37031 * Set up the Guest's page tables to see this CPU's pages (and no
37032 * other CPU's pages).
37033 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37034 * compiled-in switcher code and the high-mapped copy we just made.
37035 */
37036 for (i = 0; i < IDT_ENTRIES; i++)
37037 - default_idt_entries[i] += switcher_offset();
37038 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37039
37040 /*
37041 * Set up the Switcher's per-cpu areas.
37042 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
37043 * it will be undisturbed when we switch. To change %cs and jump we
37044 * need this structure to feed to Intel's "lcall" instruction.
37045 */
37046 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
37047 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
37048 lguest_entry.segment = LGUEST_CS;
37049
37050 /*
37051 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
37052 index 40634b0..4f5855e 100644
37053 --- a/drivers/lguest/x86/switcher_32.S
37054 +++ b/drivers/lguest/x86/switcher_32.S
37055 @@ -87,6 +87,7 @@
37056 #include <asm/page.h>
37057 #include <asm/segment.h>
37058 #include <asm/lguest.h>
37059 +#include <asm/processor-flags.h>
37060
37061 // We mark the start of the code to copy
37062 // It's placed in .text tho it's never run here
37063 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
37064 // Changes type when we load it: damn Intel!
37065 // For after we switch over our page tables
37066 // That entry will be read-only: we'd crash.
37067 +
37068 +#ifdef CONFIG_PAX_KERNEXEC
37069 + mov %cr0, %edx
37070 + xor $X86_CR0_WP, %edx
37071 + mov %edx, %cr0
37072 +#endif
37073 +
37074 movl $(GDT_ENTRY_TSS*8), %edx
37075 ltr %dx
37076
37077 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
37078 // Let's clear it again for our return.
37079 // The GDT descriptor of the Host
37080 // Points to the table after two "size" bytes
37081 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
37082 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
37083 // Clear "used" from type field (byte 5, bit 2)
37084 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
37085 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
37086 +
37087 +#ifdef CONFIG_PAX_KERNEXEC
37088 + mov %cr0, %eax
37089 + xor $X86_CR0_WP, %eax
37090 + mov %eax, %cr0
37091 +#endif
37092
37093 // Once our page table's switched, the Guest is live!
37094 // The Host fades as we run this final step.
37095 @@ -295,13 +309,12 @@ deliver_to_host:
37096 // I consulted gcc, and it gave
37097 // These instructions, which I gladly credit:
37098 leal (%edx,%ebx,8), %eax
37099 - movzwl (%eax),%edx
37100 - movl 4(%eax), %eax
37101 - xorw %ax, %ax
37102 - orl %eax, %edx
37103 + movl 4(%eax), %edx
37104 + movw (%eax), %dx
37105 // Now the address of the handler's in %edx
37106 // We call it now: its "iret" drops us home.
37107 - jmp *%edx
37108 + ljmp $__KERNEL_CS, $1f
37109 +1: jmp *%edx
37110
37111 // Every interrupt can come to us here
37112 // But we must truly tell each apart.
37113 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
37114 index 7155945..4bcc562 100644
37115 --- a/drivers/md/bitmap.c
37116 +++ b/drivers/md/bitmap.c
37117 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
37118 chunk_kb ? "KB" : "B");
37119 if (bitmap->storage.file) {
37120 seq_printf(seq, ", file: ");
37121 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
37122 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
37123 }
37124
37125 seq_printf(seq, "\n");
37126 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
37127 index eee353d..74504c4 100644
37128 --- a/drivers/md/dm-ioctl.c
37129 +++ b/drivers/md/dm-ioctl.c
37130 @@ -1632,7 +1632,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
37131 cmd == DM_LIST_VERSIONS_CMD)
37132 return 0;
37133
37134 - if ((cmd == DM_DEV_CREATE_CMD)) {
37135 + if (cmd == DM_DEV_CREATE_CMD) {
37136 if (!*param->name) {
37137 DMWARN("name not supplied when creating device");
37138 return -EINVAL;
37139 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
37140 index 7f24190..0e18099 100644
37141 --- a/drivers/md/dm-raid1.c
37142 +++ b/drivers/md/dm-raid1.c
37143 @@ -40,7 +40,7 @@ enum dm_raid1_error {
37144
37145 struct mirror {
37146 struct mirror_set *ms;
37147 - atomic_t error_count;
37148 + atomic_unchecked_t error_count;
37149 unsigned long error_type;
37150 struct dm_dev *dev;
37151 sector_t offset;
37152 @@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
37153 struct mirror *m;
37154
37155 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
37156 - if (!atomic_read(&m->error_count))
37157 + if (!atomic_read_unchecked(&m->error_count))
37158 return m;
37159
37160 return NULL;
37161 @@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
37162 * simple way to tell if a device has encountered
37163 * errors.
37164 */
37165 - atomic_inc(&m->error_count);
37166 + atomic_inc_unchecked(&m->error_count);
37167
37168 if (test_and_set_bit(error_type, &m->error_type))
37169 return;
37170 @@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
37171 struct mirror *m = get_default_mirror(ms);
37172
37173 do {
37174 - if (likely(!atomic_read(&m->error_count)))
37175 + if (likely(!atomic_read_unchecked(&m->error_count)))
37176 return m;
37177
37178 if (m-- == ms->mirror)
37179 @@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
37180 {
37181 struct mirror *default_mirror = get_default_mirror(m->ms);
37182
37183 - return !atomic_read(&default_mirror->error_count);
37184 + return !atomic_read_unchecked(&default_mirror->error_count);
37185 }
37186
37187 static int mirror_available(struct mirror_set *ms, struct bio *bio)
37188 @@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
37189 */
37190 if (likely(region_in_sync(ms, region, 1)))
37191 m = choose_mirror(ms, bio->bi_sector);
37192 - else if (m && atomic_read(&m->error_count))
37193 + else if (m && atomic_read_unchecked(&m->error_count))
37194 m = NULL;
37195
37196 if (likely(m))
37197 @@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
37198 }
37199
37200 ms->mirror[mirror].ms = ms;
37201 - atomic_set(&(ms->mirror[mirror].error_count), 0);
37202 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
37203 ms->mirror[mirror].error_type = 0;
37204 ms->mirror[mirror].offset = offset;
37205
37206 @@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
37207 */
37208 static char device_status_char(struct mirror *m)
37209 {
37210 - if (!atomic_read(&(m->error_count)))
37211 + if (!atomic_read_unchecked(&(m->error_count)))
37212 return 'A';
37213
37214 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
37215 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
37216 index aaecefa..23b3026 100644
37217 --- a/drivers/md/dm-stripe.c
37218 +++ b/drivers/md/dm-stripe.c
37219 @@ -20,7 +20,7 @@ struct stripe {
37220 struct dm_dev *dev;
37221 sector_t physical_start;
37222
37223 - atomic_t error_count;
37224 + atomic_unchecked_t error_count;
37225 };
37226
37227 struct stripe_c {
37228 @@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
37229 kfree(sc);
37230 return r;
37231 }
37232 - atomic_set(&(sc->stripe[i].error_count), 0);
37233 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
37234 }
37235
37236 ti->private = sc;
37237 @@ -325,7 +325,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
37238 DMEMIT("%d ", sc->stripes);
37239 for (i = 0; i < sc->stripes; i++) {
37240 DMEMIT("%s ", sc->stripe[i].dev->name);
37241 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
37242 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
37243 'D' : 'A';
37244 }
37245 buffer[i] = '\0';
37246 @@ -370,8 +370,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
37247 */
37248 for (i = 0; i < sc->stripes; i++)
37249 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
37250 - atomic_inc(&(sc->stripe[i].error_count));
37251 - if (atomic_read(&(sc->stripe[i].error_count)) <
37252 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
37253 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
37254 DM_IO_ERROR_THRESHOLD)
37255 schedule_work(&sc->trigger_event);
37256 }
37257 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
37258 index daf25d0..d74f49f 100644
37259 --- a/drivers/md/dm-table.c
37260 +++ b/drivers/md/dm-table.c
37261 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
37262 if (!dev_size)
37263 return 0;
37264
37265 - if ((start >= dev_size) || (start + len > dev_size)) {
37266 + if ((start >= dev_size) || (len > dev_size - start)) {
37267 DMWARN("%s: %s too small for target: "
37268 "start=%llu, len=%llu, dev_size=%llu",
37269 dm_device_name(ti->table->md), bdevname(bdev, b),
37270 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
37271 index 4d6e853..a234157 100644
37272 --- a/drivers/md/dm-thin-metadata.c
37273 +++ b/drivers/md/dm-thin-metadata.c
37274 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37275 {
37276 pmd->info.tm = pmd->tm;
37277 pmd->info.levels = 2;
37278 - pmd->info.value_type.context = pmd->data_sm;
37279 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37280 pmd->info.value_type.size = sizeof(__le64);
37281 pmd->info.value_type.inc = data_block_inc;
37282 pmd->info.value_type.dec = data_block_dec;
37283 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37284
37285 pmd->bl_info.tm = pmd->tm;
37286 pmd->bl_info.levels = 1;
37287 - pmd->bl_info.value_type.context = pmd->data_sm;
37288 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37289 pmd->bl_info.value_type.size = sizeof(__le64);
37290 pmd->bl_info.value_type.inc = data_block_inc;
37291 pmd->bl_info.value_type.dec = data_block_dec;
37292 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
37293 index 0d8f086..f5a91d5 100644
37294 --- a/drivers/md/dm.c
37295 +++ b/drivers/md/dm.c
37296 @@ -170,9 +170,9 @@ struct mapped_device {
37297 /*
37298 * Event handling.
37299 */
37300 - atomic_t event_nr;
37301 + atomic_unchecked_t event_nr;
37302 wait_queue_head_t eventq;
37303 - atomic_t uevent_seq;
37304 + atomic_unchecked_t uevent_seq;
37305 struct list_head uevent_list;
37306 spinlock_t uevent_lock; /* Protect access to uevent_list */
37307
37308 @@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
37309 rwlock_init(&md->map_lock);
37310 atomic_set(&md->holders, 1);
37311 atomic_set(&md->open_count, 0);
37312 - atomic_set(&md->event_nr, 0);
37313 - atomic_set(&md->uevent_seq, 0);
37314 + atomic_set_unchecked(&md->event_nr, 0);
37315 + atomic_set_unchecked(&md->uevent_seq, 0);
37316 INIT_LIST_HEAD(&md->uevent_list);
37317 spin_lock_init(&md->uevent_lock);
37318
37319 @@ -2026,7 +2026,7 @@ static void event_callback(void *context)
37320
37321 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
37322
37323 - atomic_inc(&md->event_nr);
37324 + atomic_inc_unchecked(&md->event_nr);
37325 wake_up(&md->eventq);
37326 }
37327
37328 @@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
37329
37330 uint32_t dm_next_uevent_seq(struct mapped_device *md)
37331 {
37332 - return atomic_add_return(1, &md->uevent_seq);
37333 + return atomic_add_return_unchecked(1, &md->uevent_seq);
37334 }
37335
37336 uint32_t dm_get_event_nr(struct mapped_device *md)
37337 {
37338 - return atomic_read(&md->event_nr);
37339 + return atomic_read_unchecked(&md->event_nr);
37340 }
37341
37342 int dm_wait_event(struct mapped_device *md, int event_nr)
37343 {
37344 return wait_event_interruptible(md->eventq,
37345 - (event_nr != atomic_read(&md->event_nr)));
37346 + (event_nr != atomic_read_unchecked(&md->event_nr)));
37347 }
37348
37349 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
37350 diff --git a/drivers/md/md.c b/drivers/md/md.c
37351 index f363135..9b38815 100644
37352 --- a/drivers/md/md.c
37353 +++ b/drivers/md/md.c
37354 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
37355 * start build, activate spare
37356 */
37357 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
37358 -static atomic_t md_event_count;
37359 +static atomic_unchecked_t md_event_count;
37360 void md_new_event(struct mddev *mddev)
37361 {
37362 - atomic_inc(&md_event_count);
37363 + atomic_inc_unchecked(&md_event_count);
37364 wake_up(&md_event_waiters);
37365 }
37366 EXPORT_SYMBOL_GPL(md_new_event);
37367 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
37368 */
37369 static void md_new_event_inintr(struct mddev *mddev)
37370 {
37371 - atomic_inc(&md_event_count);
37372 + atomic_inc_unchecked(&md_event_count);
37373 wake_up(&md_event_waiters);
37374 }
37375
37376 @@ -1507,7 +1507,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
37377 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
37378 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
37379 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
37380 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37381 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37382
37383 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
37384 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
37385 @@ -1751,7 +1751,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
37386 else
37387 sb->resync_offset = cpu_to_le64(0);
37388
37389 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
37390 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
37391
37392 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
37393 sb->size = cpu_to_le64(mddev->dev_sectors);
37394 @@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
37395 static ssize_t
37396 errors_show(struct md_rdev *rdev, char *page)
37397 {
37398 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
37399 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
37400 }
37401
37402 static ssize_t
37403 @@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
37404 char *e;
37405 unsigned long n = simple_strtoul(buf, &e, 10);
37406 if (*buf && (*e == 0 || *e == '\n')) {
37407 - atomic_set(&rdev->corrected_errors, n);
37408 + atomic_set_unchecked(&rdev->corrected_errors, n);
37409 return len;
37410 }
37411 return -EINVAL;
37412 @@ -3210,8 +3210,8 @@ int md_rdev_init(struct md_rdev *rdev)
37413 rdev->sb_loaded = 0;
37414 rdev->bb_page = NULL;
37415 atomic_set(&rdev->nr_pending, 0);
37416 - atomic_set(&rdev->read_errors, 0);
37417 - atomic_set(&rdev->corrected_errors, 0);
37418 + atomic_set_unchecked(&rdev->read_errors, 0);
37419 + atomic_set_unchecked(&rdev->corrected_errors, 0);
37420
37421 INIT_LIST_HEAD(&rdev->same_set);
37422 init_waitqueue_head(&rdev->blocked_wait);
37423 @@ -6987,7 +6987,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
37424
37425 spin_unlock(&pers_lock);
37426 seq_printf(seq, "\n");
37427 - seq->poll_event = atomic_read(&md_event_count);
37428 + seq->poll_event = atomic_read_unchecked(&md_event_count);
37429 return 0;
37430 }
37431 if (v == (void*)2) {
37432 @@ -7090,7 +7090,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
37433 return error;
37434
37435 seq = file->private_data;
37436 - seq->poll_event = atomic_read(&md_event_count);
37437 + seq->poll_event = atomic_read_unchecked(&md_event_count);
37438 return error;
37439 }
37440
37441 @@ -7104,7 +7104,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
37442 /* always allow read */
37443 mask = POLLIN | POLLRDNORM;
37444
37445 - if (seq->poll_event != atomic_read(&md_event_count))
37446 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
37447 mask |= POLLERR | POLLPRI;
37448 return mask;
37449 }
37450 @@ -7148,7 +7148,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
37451 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
37452 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
37453 (int)part_stat_read(&disk->part0, sectors[1]) -
37454 - atomic_read(&disk->sync_io);
37455 + atomic_read_unchecked(&disk->sync_io);
37456 /* sync IO will cause sync_io to increase before the disk_stats
37457 * as sync_io is counted when a request starts, and
37458 * disk_stats is counted when it completes.
37459 diff --git a/drivers/md/md.h b/drivers/md/md.h
37460 index eca59c3..7c42285 100644
37461 --- a/drivers/md/md.h
37462 +++ b/drivers/md/md.h
37463 @@ -94,13 +94,13 @@ struct md_rdev {
37464 * only maintained for arrays that
37465 * support hot removal
37466 */
37467 - atomic_t read_errors; /* number of consecutive read errors that
37468 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
37469 * we have tried to ignore.
37470 */
37471 struct timespec last_read_error; /* monotonic time since our
37472 * last read error
37473 */
37474 - atomic_t corrected_errors; /* number of corrected read errors,
37475 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
37476 * for reporting to userspace and storing
37477 * in superblock.
37478 */
37479 @@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
37480
37481 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
37482 {
37483 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37484 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37485 }
37486
37487 struct md_personality
37488 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
37489 index 1cbfc6b..56e1dbb 100644
37490 --- a/drivers/md/persistent-data/dm-space-map.h
37491 +++ b/drivers/md/persistent-data/dm-space-map.h
37492 @@ -60,6 +60,7 @@ struct dm_space_map {
37493 int (*root_size)(struct dm_space_map *sm, size_t *result);
37494 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
37495 };
37496 +typedef struct dm_space_map __no_const dm_space_map_no_const;
37497
37498 /*----------------------------------------------------------------*/
37499
37500 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
37501 index 75b1f89..00ba344 100644
37502 --- a/drivers/md/raid1.c
37503 +++ b/drivers/md/raid1.c
37504 @@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
37505 if (r1_sync_page_io(rdev, sect, s,
37506 bio->bi_io_vec[idx].bv_page,
37507 READ) != 0)
37508 - atomic_add(s, &rdev->corrected_errors);
37509 + atomic_add_unchecked(s, &rdev->corrected_errors);
37510 }
37511 sectors -= s;
37512 sect += s;
37513 @@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
37514 test_bit(In_sync, &rdev->flags)) {
37515 if (r1_sync_page_io(rdev, sect, s,
37516 conf->tmppage, READ)) {
37517 - atomic_add(s, &rdev->corrected_errors);
37518 + atomic_add_unchecked(s, &rdev->corrected_errors);
37519 printk(KERN_INFO
37520 "md/raid1:%s: read error corrected "
37521 "(%d sectors at %llu on %s)\n",
37522 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
37523 index 8d925dc..11d674f 100644
37524 --- a/drivers/md/raid10.c
37525 +++ b/drivers/md/raid10.c
37526 @@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
37527 /* The write handler will notice the lack of
37528 * R10BIO_Uptodate and record any errors etc
37529 */
37530 - atomic_add(r10_bio->sectors,
37531 + atomic_add_unchecked(r10_bio->sectors,
37532 &conf->mirrors[d].rdev->corrected_errors);
37533
37534 /* for reconstruct, we always reschedule after a read.
37535 @@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
37536 {
37537 struct timespec cur_time_mon;
37538 unsigned long hours_since_last;
37539 - unsigned int read_errors = atomic_read(&rdev->read_errors);
37540 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
37541
37542 ktime_get_ts(&cur_time_mon);
37543
37544 @@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
37545 * overflowing the shift of read_errors by hours_since_last.
37546 */
37547 if (hours_since_last >= 8 * sizeof(read_errors))
37548 - atomic_set(&rdev->read_errors, 0);
37549 + atomic_set_unchecked(&rdev->read_errors, 0);
37550 else
37551 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
37552 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
37553 }
37554
37555 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
37556 @@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37557 return;
37558
37559 check_decay_read_errors(mddev, rdev);
37560 - atomic_inc(&rdev->read_errors);
37561 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
37562 + atomic_inc_unchecked(&rdev->read_errors);
37563 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
37564 char b[BDEVNAME_SIZE];
37565 bdevname(rdev->bdev, b);
37566
37567 @@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37568 "md/raid10:%s: %s: Raid device exceeded "
37569 "read_error threshold [cur %d:max %d]\n",
37570 mdname(mddev), b,
37571 - atomic_read(&rdev->read_errors), max_read_errors);
37572 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
37573 printk(KERN_NOTICE
37574 "md/raid10:%s: %s: Failing raid device\n",
37575 mdname(mddev), b);
37576 @@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37577 sect +
37578 choose_data_offset(r10_bio, rdev)),
37579 bdevname(rdev->bdev, b));
37580 - atomic_add(s, &rdev->corrected_errors);
37581 + atomic_add_unchecked(s, &rdev->corrected_errors);
37582 }
37583
37584 rdev_dec_pending(rdev, mddev);
37585 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
37586 index 19d77a0..56051b92 100644
37587 --- a/drivers/md/raid5.c
37588 +++ b/drivers/md/raid5.c
37589 @@ -1797,21 +1797,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
37590 mdname(conf->mddev), STRIPE_SECTORS,
37591 (unsigned long long)s,
37592 bdevname(rdev->bdev, b));
37593 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
37594 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
37595 clear_bit(R5_ReadError, &sh->dev[i].flags);
37596 clear_bit(R5_ReWrite, &sh->dev[i].flags);
37597 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
37598 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
37599
37600 - if (atomic_read(&rdev->read_errors))
37601 - atomic_set(&rdev->read_errors, 0);
37602 + if (atomic_read_unchecked(&rdev->read_errors))
37603 + atomic_set_unchecked(&rdev->read_errors, 0);
37604 } else {
37605 const char *bdn = bdevname(rdev->bdev, b);
37606 int retry = 0;
37607 int set_bad = 0;
37608
37609 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
37610 - atomic_inc(&rdev->read_errors);
37611 + atomic_inc_unchecked(&rdev->read_errors);
37612 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
37613 printk_ratelimited(
37614 KERN_WARNING
37615 @@ -1839,7 +1839,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
37616 mdname(conf->mddev),
37617 (unsigned long long)s,
37618 bdn);
37619 - } else if (atomic_read(&rdev->read_errors)
37620 + } else if (atomic_read_unchecked(&rdev->read_errors)
37621 > conf->max_nr_stripes)
37622 printk(KERN_WARNING
37623 "md/raid:%s: Too many read errors, failing device %s.\n",
37624 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
37625 index d33101a..6b13069 100644
37626 --- a/drivers/media/dvb-core/dvbdev.c
37627 +++ b/drivers/media/dvb-core/dvbdev.c
37628 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
37629 const struct dvb_device *template, void *priv, int type)
37630 {
37631 struct dvb_device *dvbdev;
37632 - struct file_operations *dvbdevfops;
37633 + file_operations_no_const *dvbdevfops;
37634 struct device *clsdev;
37635 int minor;
37636 int id;
37637 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
37638 index 404f63a..4796533 100644
37639 --- a/drivers/media/dvb-frontends/dib3000.h
37640 +++ b/drivers/media/dvb-frontends/dib3000.h
37641 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
37642 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
37643 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
37644 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
37645 -};
37646 +} __no_const;
37647
37648 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
37649 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
37650 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
37651 index 8e9a668..78d6310 100644
37652 --- a/drivers/media/platform/omap/omap_vout.c
37653 +++ b/drivers/media/platform/omap/omap_vout.c
37654 @@ -63,7 +63,6 @@ enum omap_vout_channels {
37655 OMAP_VIDEO2,
37656 };
37657
37658 -static struct videobuf_queue_ops video_vbq_ops;
37659 /* Variables configurable through module params*/
37660 static u32 video1_numbuffers = 3;
37661 static u32 video2_numbuffers = 3;
37662 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
37663 {
37664 struct videobuf_queue *q;
37665 struct omap_vout_device *vout = NULL;
37666 + static struct videobuf_queue_ops video_vbq_ops = {
37667 + .buf_setup = omap_vout_buffer_setup,
37668 + .buf_prepare = omap_vout_buffer_prepare,
37669 + .buf_release = omap_vout_buffer_release,
37670 + .buf_queue = omap_vout_buffer_queue,
37671 + };
37672
37673 vout = video_drvdata(file);
37674 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
37675 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
37676 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
37677
37678 q = &vout->vbq;
37679 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
37680 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
37681 - video_vbq_ops.buf_release = omap_vout_buffer_release;
37682 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
37683 spin_lock_init(&vout->vbq_lock);
37684
37685 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
37686 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
37687 index b671e20..34088b7 100644
37688 --- a/drivers/media/platform/s5p-tv/mixer.h
37689 +++ b/drivers/media/platform/s5p-tv/mixer.h
37690 @@ -155,7 +155,7 @@ struct mxr_layer {
37691 /** layer index (unique identifier) */
37692 int idx;
37693 /** callbacks for layer methods */
37694 - struct mxr_layer_ops ops;
37695 + struct mxr_layer_ops *ops;
37696 /** format array */
37697 const struct mxr_format **fmt_array;
37698 /** size of format array */
37699 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
37700 index b93a21f..2535195 100644
37701 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
37702 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
37703 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
37704 {
37705 struct mxr_layer *layer;
37706 int ret;
37707 - struct mxr_layer_ops ops = {
37708 + static struct mxr_layer_ops ops = {
37709 .release = mxr_graph_layer_release,
37710 .buffer_set = mxr_graph_buffer_set,
37711 .stream_set = mxr_graph_stream_set,
37712 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
37713 index 3b1670a..595c939 100644
37714 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
37715 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
37716 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
37717 layer->update_buf = next;
37718 }
37719
37720 - layer->ops.buffer_set(layer, layer->update_buf);
37721 + layer->ops->buffer_set(layer, layer->update_buf);
37722
37723 if (done && done != layer->shadow_buf)
37724 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
37725 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
37726 index 1f3b743..e839271 100644
37727 --- a/drivers/media/platform/s5p-tv/mixer_video.c
37728 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
37729 @@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
37730 layer->geo.src.height = layer->geo.src.full_height;
37731
37732 mxr_geometry_dump(mdev, &layer->geo);
37733 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37734 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37735 mxr_geometry_dump(mdev, &layer->geo);
37736 }
37737
37738 @@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
37739 layer->geo.dst.full_width = mbus_fmt.width;
37740 layer->geo.dst.full_height = mbus_fmt.height;
37741 layer->geo.dst.field = mbus_fmt.field;
37742 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37743 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37744
37745 mxr_geometry_dump(mdev, &layer->geo);
37746 }
37747 @@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
37748 /* set source size to highest accepted value */
37749 geo->src.full_width = max(geo->dst.full_width, pix->width);
37750 geo->src.full_height = max(geo->dst.full_height, pix->height);
37751 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37752 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37753 mxr_geometry_dump(mdev, &layer->geo);
37754 /* set cropping to total visible screen */
37755 geo->src.width = pix->width;
37756 @@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
37757 geo->src.x_offset = 0;
37758 geo->src.y_offset = 0;
37759 /* assure consistency of geometry */
37760 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
37761 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
37762 mxr_geometry_dump(mdev, &layer->geo);
37763 /* set full size to lowest possible value */
37764 geo->src.full_width = 0;
37765 geo->src.full_height = 0;
37766 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37767 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37768 mxr_geometry_dump(mdev, &layer->geo);
37769
37770 /* returning results */
37771 @@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
37772 target->width = s->r.width;
37773 target->height = s->r.height;
37774
37775 - layer->ops.fix_geometry(layer, stage, s->flags);
37776 + layer->ops->fix_geometry(layer, stage, s->flags);
37777
37778 /* retrieve update selection rectangle */
37779 res.left = target->x_offset;
37780 @@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
37781 mxr_output_get(mdev);
37782
37783 mxr_layer_update_output(layer);
37784 - layer->ops.format_set(layer);
37785 + layer->ops->format_set(layer);
37786 /* enabling layer in hardware */
37787 spin_lock_irqsave(&layer->enq_slock, flags);
37788 layer->state = MXR_LAYER_STREAMING;
37789 spin_unlock_irqrestore(&layer->enq_slock, flags);
37790
37791 - layer->ops.stream_set(layer, MXR_ENABLE);
37792 + layer->ops->stream_set(layer, MXR_ENABLE);
37793 mxr_streamer_get(mdev);
37794
37795 return 0;
37796 @@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
37797 spin_unlock_irqrestore(&layer->enq_slock, flags);
37798
37799 /* disabling layer in hardware */
37800 - layer->ops.stream_set(layer, MXR_DISABLE);
37801 + layer->ops->stream_set(layer, MXR_DISABLE);
37802 /* remove one streamer */
37803 mxr_streamer_put(mdev);
37804 /* allow changes in output configuration */
37805 @@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
37806
37807 void mxr_layer_release(struct mxr_layer *layer)
37808 {
37809 - if (layer->ops.release)
37810 - layer->ops.release(layer);
37811 + if (layer->ops->release)
37812 + layer->ops->release(layer);
37813 }
37814
37815 void mxr_base_layer_release(struct mxr_layer *layer)
37816 @@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
37817
37818 layer->mdev = mdev;
37819 layer->idx = idx;
37820 - layer->ops = *ops;
37821 + layer->ops = ops;
37822
37823 spin_lock_init(&layer->enq_slock);
37824 INIT_LIST_HEAD(&layer->enq_list);
37825 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
37826 index 3d13a63..da31bf1 100644
37827 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
37828 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
37829 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
37830 {
37831 struct mxr_layer *layer;
37832 int ret;
37833 - struct mxr_layer_ops ops = {
37834 + static struct mxr_layer_ops ops = {
37835 .release = mxr_vp_layer_release,
37836 .buffer_set = mxr_vp_buffer_set,
37837 .stream_set = mxr_vp_stream_set,
37838 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
37839 index 643d80a..56bb96b 100644
37840 --- a/drivers/media/radio/radio-cadet.c
37841 +++ b/drivers/media/radio/radio-cadet.c
37842 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
37843 unsigned char readbuf[RDS_BUFFER];
37844 int i = 0;
37845
37846 + if (count > RDS_BUFFER)
37847 + return -EFAULT;
37848 mutex_lock(&dev->lock);
37849 if (dev->rdsstat == 0)
37850 cadet_start_rds(dev);
37851 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
37852 while (i < count && dev->rdsin != dev->rdsout)
37853 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
37854
37855 - if (i && copy_to_user(data, readbuf, i))
37856 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
37857 i = -EFAULT;
37858 unlock:
37859 mutex_unlock(&dev->lock);
37860 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
37861 index 3940bb0..fb3952a 100644
37862 --- a/drivers/media/usb/dvb-usb/cxusb.c
37863 +++ b/drivers/media/usb/dvb-usb/cxusb.c
37864 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
37865
37866 struct dib0700_adapter_state {
37867 int (*set_param_save) (struct dvb_frontend *);
37868 -};
37869 +} __no_const;
37870
37871 static int dib7070_set_param_override(struct dvb_frontend *fe)
37872 {
37873 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
37874 index 9382895..ac8093c 100644
37875 --- a/drivers/media/usb/dvb-usb/dw2102.c
37876 +++ b/drivers/media/usb/dvb-usb/dw2102.c
37877 @@ -95,7 +95,7 @@ struct su3000_state {
37878
37879 struct s6x0_state {
37880 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
37881 -};
37882 +} __no_const;
37883
37884 /* debug */
37885 static int dvb_usb_dw2102_debug;
37886 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
37887 index aa6e7c7..4cd8061 100644
37888 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
37889 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
37890 @@ -1923,7 +1923,8 @@ struct v4l2_ioctl_info {
37891 struct file *file, void *fh, void *p);
37892 } u;
37893 void (*debug)(const void *arg, bool write_only);
37894 -};
37895 +} __do_const;
37896 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
37897
37898 /* This control needs a priority check */
37899 #define INFO_FL_PRIO (1 << 0)
37900 @@ -2108,7 +2109,7 @@ static long __video_do_ioctl(struct file *file,
37901 struct video_device *vfd = video_devdata(file);
37902 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
37903 bool write_only = false;
37904 - struct v4l2_ioctl_info default_info;
37905 + v4l2_ioctl_info_no_const default_info;
37906 const struct v4l2_ioctl_info *info;
37907 void *fh = file->private_data;
37908 struct v4l2_fh *vfh = NULL;
37909 diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
37910 index 29b2172..a7c5b31 100644
37911 --- a/drivers/memstick/host/r592.c
37912 +++ b/drivers/memstick/host/r592.c
37913 @@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
37914 /* Executes one TPC (data is read/written from small or large fifo) */
37915 static void r592_execute_tpc(struct r592_device *dev)
37916 {
37917 - bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
37918 + bool is_write;
37919 int len, error;
37920 u32 status, reg;
37921
37922 @@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
37923 return;
37924 }
37925
37926 + is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
37927 len = dev->req->long_data ?
37928 dev->req->sg.length : dev->req->data_len;
37929
37930 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
37931 index fb69baa..cf7ad22 100644
37932 --- a/drivers/message/fusion/mptbase.c
37933 +++ b/drivers/message/fusion/mptbase.c
37934 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
37935 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
37936 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
37937
37938 +#ifdef CONFIG_GRKERNSEC_HIDESYM
37939 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
37940 +#else
37941 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
37942 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
37943 +#endif
37944 +
37945 /*
37946 * Rounding UP to nearest 4-kB boundary here...
37947 */
37948 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
37949 index fa43c39..daeb158 100644
37950 --- a/drivers/message/fusion/mptsas.c
37951 +++ b/drivers/message/fusion/mptsas.c
37952 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
37953 return 0;
37954 }
37955
37956 +static inline void
37957 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
37958 +{
37959 + if (phy_info->port_details) {
37960 + phy_info->port_details->rphy = rphy;
37961 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
37962 + ioc->name, rphy));
37963 + }
37964 +
37965 + if (rphy) {
37966 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
37967 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
37968 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
37969 + ioc->name, rphy, rphy->dev.release));
37970 + }
37971 +}
37972 +
37973 /* no mutex */
37974 static void
37975 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
37976 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
37977 return NULL;
37978 }
37979
37980 -static inline void
37981 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
37982 -{
37983 - if (phy_info->port_details) {
37984 - phy_info->port_details->rphy = rphy;
37985 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
37986 - ioc->name, rphy));
37987 - }
37988 -
37989 - if (rphy) {
37990 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
37991 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
37992 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
37993 - ioc->name, rphy, rphy->dev.release));
37994 - }
37995 -}
37996 -
37997 static inline struct sas_port *
37998 mptsas_get_port(struct mptsas_phyinfo *phy_info)
37999 {
38000 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
38001 index 164afa7..b6b2e74 100644
38002 --- a/drivers/message/fusion/mptscsih.c
38003 +++ b/drivers/message/fusion/mptscsih.c
38004 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
38005
38006 h = shost_priv(SChost);
38007
38008 - if (h) {
38009 - if (h->info_kbuf == NULL)
38010 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38011 - return h->info_kbuf;
38012 - h->info_kbuf[0] = '\0';
38013 + if (!h)
38014 + return NULL;
38015
38016 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38017 - h->info_kbuf[size-1] = '\0';
38018 - }
38019 + if (h->info_kbuf == NULL)
38020 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38021 + return h->info_kbuf;
38022 + h->info_kbuf[0] = '\0';
38023 +
38024 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38025 + h->info_kbuf[size-1] = '\0';
38026
38027 return h->info_kbuf;
38028 }
38029 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
38030 index 8001aa6..b137580 100644
38031 --- a/drivers/message/i2o/i2o_proc.c
38032 +++ b/drivers/message/i2o/i2o_proc.c
38033 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
38034 "Array Controller Device"
38035 };
38036
38037 -static char *chtostr(char *tmp, u8 *chars, int n)
38038 -{
38039 - tmp[0] = 0;
38040 - return strncat(tmp, (char *)chars, n);
38041 -}
38042 -
38043 static int i2o_report_query_status(struct seq_file *seq, int block_status,
38044 char *group)
38045 {
38046 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38047 } *result;
38048
38049 i2o_exec_execute_ddm_table ddm_table;
38050 - char tmp[28 + 1];
38051
38052 result = kmalloc(sizeof(*result), GFP_KERNEL);
38053 if (!result)
38054 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38055
38056 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
38057 seq_printf(seq, "%-#8x", ddm_table.module_id);
38058 - seq_printf(seq, "%-29s",
38059 - chtostr(tmp, ddm_table.module_name_version, 28));
38060 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
38061 seq_printf(seq, "%9d ", ddm_table.data_size);
38062 seq_printf(seq, "%8d", ddm_table.code_size);
38063
38064 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38065
38066 i2o_driver_result_table *result;
38067 i2o_driver_store_table *dst;
38068 - char tmp[28 + 1];
38069
38070 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
38071 if (result == NULL)
38072 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38073
38074 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
38075 seq_printf(seq, "%-#8x", dst->module_id);
38076 - seq_printf(seq, "%-29s",
38077 - chtostr(tmp, dst->module_name_version, 28));
38078 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
38079 + seq_printf(seq, "%-.28s", dst->module_name_version);
38080 + seq_printf(seq, "%-.8s", dst->date);
38081 seq_printf(seq, "%8d ", dst->module_size);
38082 seq_printf(seq, "%8d ", dst->mpb_size);
38083 seq_printf(seq, "0x%04x", dst->module_flags);
38084 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38085 // == (allow) 512d bytes (max)
38086 static u16 *work16 = (u16 *) work32;
38087 int token;
38088 - char tmp[16 + 1];
38089
38090 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
38091
38092 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38093 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
38094 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
38095 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
38096 - seq_printf(seq, "Vendor info : %s\n",
38097 - chtostr(tmp, (u8 *) (work32 + 2), 16));
38098 - seq_printf(seq, "Product info : %s\n",
38099 - chtostr(tmp, (u8 *) (work32 + 6), 16));
38100 - seq_printf(seq, "Description : %s\n",
38101 - chtostr(tmp, (u8 *) (work32 + 10), 16));
38102 - seq_printf(seq, "Product rev. : %s\n",
38103 - chtostr(tmp, (u8 *) (work32 + 14), 8));
38104 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
38105 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
38106 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
38107 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
38108
38109 seq_printf(seq, "Serial number : ");
38110 print_serial_number(seq, (u8 *) (work32 + 16),
38111 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38112 u8 pad[256]; // allow up to 256 byte (max) serial number
38113 } result;
38114
38115 - char tmp[24 + 1];
38116 -
38117 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
38118
38119 if (token < 0) {
38120 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38121 }
38122
38123 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
38124 - seq_printf(seq, "Module name : %s\n",
38125 - chtostr(tmp, result.module_name, 24));
38126 - seq_printf(seq, "Module revision : %s\n",
38127 - chtostr(tmp, result.module_rev, 8));
38128 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
38129 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
38130
38131 seq_printf(seq, "Serial number : ");
38132 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
38133 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38134 u8 instance_number[4];
38135 } result;
38136
38137 - char tmp[64 + 1];
38138 -
38139 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
38140
38141 if (token < 0) {
38142 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38143 return 0;
38144 }
38145
38146 - seq_printf(seq, "Device name : %s\n",
38147 - chtostr(tmp, result.device_name, 64));
38148 - seq_printf(seq, "Service name : %s\n",
38149 - chtostr(tmp, result.service_name, 64));
38150 - seq_printf(seq, "Physical name : %s\n",
38151 - chtostr(tmp, result.physical_location, 64));
38152 - seq_printf(seq, "Instance number : %s\n",
38153 - chtostr(tmp, result.instance_number, 4));
38154 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
38155 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
38156 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
38157 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
38158
38159 return 0;
38160 }
38161 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
38162 index a8c08f3..155fe3d 100644
38163 --- a/drivers/message/i2o/iop.c
38164 +++ b/drivers/message/i2o/iop.c
38165 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
38166
38167 spin_lock_irqsave(&c->context_list_lock, flags);
38168
38169 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
38170 - atomic_inc(&c->context_list_counter);
38171 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
38172 + atomic_inc_unchecked(&c->context_list_counter);
38173
38174 - entry->context = atomic_read(&c->context_list_counter);
38175 + entry->context = atomic_read_unchecked(&c->context_list_counter);
38176
38177 list_add(&entry->list, &c->context_list);
38178
38179 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
38180
38181 #if BITS_PER_LONG == 64
38182 spin_lock_init(&c->context_list_lock);
38183 - atomic_set(&c->context_list_counter, 0);
38184 + atomic_set_unchecked(&c->context_list_counter, 0);
38185 INIT_LIST_HEAD(&c->context_list);
38186 #endif
38187
38188 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
38189 index 45ece11..8efa218 100644
38190 --- a/drivers/mfd/janz-cmodio.c
38191 +++ b/drivers/mfd/janz-cmodio.c
38192 @@ -13,6 +13,7 @@
38193
38194 #include <linux/kernel.h>
38195 #include <linux/module.h>
38196 +#include <linux/slab.h>
38197 #include <linux/init.h>
38198 #include <linux/pci.h>
38199 #include <linux/interrupt.h>
38200 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
38201 index a5f9888..1c0ed56 100644
38202 --- a/drivers/mfd/twl4030-irq.c
38203 +++ b/drivers/mfd/twl4030-irq.c
38204 @@ -35,6 +35,7 @@
38205 #include <linux/of.h>
38206 #include <linux/irqdomain.h>
38207 #include <linux/i2c/twl.h>
38208 +#include <asm/pgtable.h>
38209
38210 #include "twl-core.h"
38211
38212 @@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
38213 * Install an irq handler for each of the SIH modules;
38214 * clone dummy irq_chip since PIH can't *do* anything
38215 */
38216 - twl4030_irq_chip = dummy_irq_chip;
38217 - twl4030_irq_chip.name = "twl4030";
38218 + pax_open_kernel();
38219 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
38220 + *(const char **)&twl4030_irq_chip.name = "twl4030";
38221
38222 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38223 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38224 + pax_close_kernel();
38225
38226 for (i = irq_base; i < irq_end; i++) {
38227 irq_set_chip_and_handler(i, &twl4030_irq_chip,
38228 diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
38229 index 277a8db..0e0b754 100644
38230 --- a/drivers/mfd/twl6030-irq.c
38231 +++ b/drivers/mfd/twl6030-irq.c
38232 @@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
38233 * install an irq handler for each of the modules;
38234 * clone dummy irq_chip since PIH can't *do* anything
38235 */
38236 - twl6030_irq_chip = dummy_irq_chip;
38237 - twl6030_irq_chip.name = "twl6030";
38238 - twl6030_irq_chip.irq_set_type = NULL;
38239 - twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38240 + pax_open_kernel();
38241 + memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
38242 + *(const char **)&twl6030_irq_chip.name = "twl6030";
38243 + *(void **)&twl6030_irq_chip.irq_set_type = NULL;
38244 + *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38245 + pax_close_kernel();
38246
38247 for (i = irq_base; i < irq_end; i++) {
38248 irq_set_chip_and_handler(i, &twl6030_irq_chip,
38249 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
38250 index f428d86..274c368 100644
38251 --- a/drivers/misc/c2port/core.c
38252 +++ b/drivers/misc/c2port/core.c
38253 @@ -924,7 +924,9 @@ struct c2port_device *c2port_device_register(char *name,
38254 mutex_init(&c2dev->mutex);
38255
38256 /* Create binary file */
38257 - c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38258 + pax_open_kernel();
38259 + *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38260 + pax_close_kernel();
38261 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
38262 if (unlikely(ret))
38263 goto error_device_create_bin_file;
38264 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
38265 index 3aa9a96..59cf685 100644
38266 --- a/drivers/misc/kgdbts.c
38267 +++ b/drivers/misc/kgdbts.c
38268 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
38269 char before[BREAK_INSTR_SIZE];
38270 char after[BREAK_INSTR_SIZE];
38271
38272 - probe_kernel_read(before, (char *)kgdbts_break_test,
38273 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
38274 BREAK_INSTR_SIZE);
38275 init_simple_test();
38276 ts.tst = plant_and_detach_test;
38277 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
38278 /* Activate test with initial breakpoint */
38279 if (!is_early)
38280 kgdb_breakpoint();
38281 - probe_kernel_read(after, (char *)kgdbts_break_test,
38282 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
38283 BREAK_INSTR_SIZE);
38284 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
38285 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
38286 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
38287 index 4a87e5c..76bdf5c 100644
38288 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
38289 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
38290 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
38291 * the lid is closed. This leads to interrupts as soon as a little move
38292 * is done.
38293 */
38294 - atomic_inc(&lis3->count);
38295 + atomic_inc_unchecked(&lis3->count);
38296
38297 wake_up_interruptible(&lis3->misc_wait);
38298 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
38299 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
38300 if (lis3->pm_dev)
38301 pm_runtime_get_sync(lis3->pm_dev);
38302
38303 - atomic_set(&lis3->count, 0);
38304 + atomic_set_unchecked(&lis3->count, 0);
38305 return 0;
38306 }
38307
38308 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
38309 add_wait_queue(&lis3->misc_wait, &wait);
38310 while (true) {
38311 set_current_state(TASK_INTERRUPTIBLE);
38312 - data = atomic_xchg(&lis3->count, 0);
38313 + data = atomic_xchg_unchecked(&lis3->count, 0);
38314 if (data)
38315 break;
38316
38317 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
38318 struct lis3lv02d, miscdev);
38319
38320 poll_wait(file, &lis3->misc_wait, wait);
38321 - if (atomic_read(&lis3->count))
38322 + if (atomic_read_unchecked(&lis3->count))
38323 return POLLIN | POLLRDNORM;
38324 return 0;
38325 }
38326 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
38327 index c439c82..1f20f57 100644
38328 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
38329 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
38330 @@ -297,7 +297,7 @@ struct lis3lv02d {
38331 struct input_polled_dev *idev; /* input device */
38332 struct platform_device *pdev; /* platform device */
38333 struct regulator_bulk_data regulators[2];
38334 - atomic_t count; /* interrupt count after last read */
38335 + atomic_unchecked_t count; /* interrupt count after last read */
38336 union axis_conversion ac; /* hw -> logical axis */
38337 int mapped_btns[3];
38338
38339 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
38340 index 2f30bad..c4c13d0 100644
38341 --- a/drivers/misc/sgi-gru/gruhandles.c
38342 +++ b/drivers/misc/sgi-gru/gruhandles.c
38343 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
38344 unsigned long nsec;
38345
38346 nsec = CLKS2NSEC(clks);
38347 - atomic_long_inc(&mcs_op_statistics[op].count);
38348 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
38349 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
38350 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
38351 if (mcs_op_statistics[op].max < nsec)
38352 mcs_op_statistics[op].max = nsec;
38353 }
38354 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
38355 index 950dbe9..eeef0f8 100644
38356 --- a/drivers/misc/sgi-gru/gruprocfs.c
38357 +++ b/drivers/misc/sgi-gru/gruprocfs.c
38358 @@ -32,9 +32,9 @@
38359
38360 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
38361
38362 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
38363 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
38364 {
38365 - unsigned long val = atomic_long_read(v);
38366 + unsigned long val = atomic_long_read_unchecked(v);
38367
38368 seq_printf(s, "%16lu %s\n", val, id);
38369 }
38370 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
38371
38372 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
38373 for (op = 0; op < mcsop_last; op++) {
38374 - count = atomic_long_read(&mcs_op_statistics[op].count);
38375 - total = atomic_long_read(&mcs_op_statistics[op].total);
38376 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
38377 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
38378 max = mcs_op_statistics[op].max;
38379 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
38380 count ? total / count : 0, max);
38381 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
38382 index 5c3ce24..4915ccb 100644
38383 --- a/drivers/misc/sgi-gru/grutables.h
38384 +++ b/drivers/misc/sgi-gru/grutables.h
38385 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
38386 * GRU statistics.
38387 */
38388 struct gru_stats_s {
38389 - atomic_long_t vdata_alloc;
38390 - atomic_long_t vdata_free;
38391 - atomic_long_t gts_alloc;
38392 - atomic_long_t gts_free;
38393 - atomic_long_t gms_alloc;
38394 - atomic_long_t gms_free;
38395 - atomic_long_t gts_double_allocate;
38396 - atomic_long_t assign_context;
38397 - atomic_long_t assign_context_failed;
38398 - atomic_long_t free_context;
38399 - atomic_long_t load_user_context;
38400 - atomic_long_t load_kernel_context;
38401 - atomic_long_t lock_kernel_context;
38402 - atomic_long_t unlock_kernel_context;
38403 - atomic_long_t steal_user_context;
38404 - atomic_long_t steal_kernel_context;
38405 - atomic_long_t steal_context_failed;
38406 - atomic_long_t nopfn;
38407 - atomic_long_t asid_new;
38408 - atomic_long_t asid_next;
38409 - atomic_long_t asid_wrap;
38410 - atomic_long_t asid_reuse;
38411 - atomic_long_t intr;
38412 - atomic_long_t intr_cbr;
38413 - atomic_long_t intr_tfh;
38414 - atomic_long_t intr_spurious;
38415 - atomic_long_t intr_mm_lock_failed;
38416 - atomic_long_t call_os;
38417 - atomic_long_t call_os_wait_queue;
38418 - atomic_long_t user_flush_tlb;
38419 - atomic_long_t user_unload_context;
38420 - atomic_long_t user_exception;
38421 - atomic_long_t set_context_option;
38422 - atomic_long_t check_context_retarget_intr;
38423 - atomic_long_t check_context_unload;
38424 - atomic_long_t tlb_dropin;
38425 - atomic_long_t tlb_preload_page;
38426 - atomic_long_t tlb_dropin_fail_no_asid;
38427 - atomic_long_t tlb_dropin_fail_upm;
38428 - atomic_long_t tlb_dropin_fail_invalid;
38429 - atomic_long_t tlb_dropin_fail_range_active;
38430 - atomic_long_t tlb_dropin_fail_idle;
38431 - atomic_long_t tlb_dropin_fail_fmm;
38432 - atomic_long_t tlb_dropin_fail_no_exception;
38433 - atomic_long_t tfh_stale_on_fault;
38434 - atomic_long_t mmu_invalidate_range;
38435 - atomic_long_t mmu_invalidate_page;
38436 - atomic_long_t flush_tlb;
38437 - atomic_long_t flush_tlb_gru;
38438 - atomic_long_t flush_tlb_gru_tgh;
38439 - atomic_long_t flush_tlb_gru_zero_asid;
38440 + atomic_long_unchecked_t vdata_alloc;
38441 + atomic_long_unchecked_t vdata_free;
38442 + atomic_long_unchecked_t gts_alloc;
38443 + atomic_long_unchecked_t gts_free;
38444 + atomic_long_unchecked_t gms_alloc;
38445 + atomic_long_unchecked_t gms_free;
38446 + atomic_long_unchecked_t gts_double_allocate;
38447 + atomic_long_unchecked_t assign_context;
38448 + atomic_long_unchecked_t assign_context_failed;
38449 + atomic_long_unchecked_t free_context;
38450 + atomic_long_unchecked_t load_user_context;
38451 + atomic_long_unchecked_t load_kernel_context;
38452 + atomic_long_unchecked_t lock_kernel_context;
38453 + atomic_long_unchecked_t unlock_kernel_context;
38454 + atomic_long_unchecked_t steal_user_context;
38455 + atomic_long_unchecked_t steal_kernel_context;
38456 + atomic_long_unchecked_t steal_context_failed;
38457 + atomic_long_unchecked_t nopfn;
38458 + atomic_long_unchecked_t asid_new;
38459 + atomic_long_unchecked_t asid_next;
38460 + atomic_long_unchecked_t asid_wrap;
38461 + atomic_long_unchecked_t asid_reuse;
38462 + atomic_long_unchecked_t intr;
38463 + atomic_long_unchecked_t intr_cbr;
38464 + atomic_long_unchecked_t intr_tfh;
38465 + atomic_long_unchecked_t intr_spurious;
38466 + atomic_long_unchecked_t intr_mm_lock_failed;
38467 + atomic_long_unchecked_t call_os;
38468 + atomic_long_unchecked_t call_os_wait_queue;
38469 + atomic_long_unchecked_t user_flush_tlb;
38470 + atomic_long_unchecked_t user_unload_context;
38471 + atomic_long_unchecked_t user_exception;
38472 + atomic_long_unchecked_t set_context_option;
38473 + atomic_long_unchecked_t check_context_retarget_intr;
38474 + atomic_long_unchecked_t check_context_unload;
38475 + atomic_long_unchecked_t tlb_dropin;
38476 + atomic_long_unchecked_t tlb_preload_page;
38477 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
38478 + atomic_long_unchecked_t tlb_dropin_fail_upm;
38479 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
38480 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
38481 + atomic_long_unchecked_t tlb_dropin_fail_idle;
38482 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
38483 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
38484 + atomic_long_unchecked_t tfh_stale_on_fault;
38485 + atomic_long_unchecked_t mmu_invalidate_range;
38486 + atomic_long_unchecked_t mmu_invalidate_page;
38487 + atomic_long_unchecked_t flush_tlb;
38488 + atomic_long_unchecked_t flush_tlb_gru;
38489 + atomic_long_unchecked_t flush_tlb_gru_tgh;
38490 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
38491
38492 - atomic_long_t copy_gpa;
38493 - atomic_long_t read_gpa;
38494 + atomic_long_unchecked_t copy_gpa;
38495 + atomic_long_unchecked_t read_gpa;
38496
38497 - atomic_long_t mesq_receive;
38498 - atomic_long_t mesq_receive_none;
38499 - atomic_long_t mesq_send;
38500 - atomic_long_t mesq_send_failed;
38501 - atomic_long_t mesq_noop;
38502 - atomic_long_t mesq_send_unexpected_error;
38503 - atomic_long_t mesq_send_lb_overflow;
38504 - atomic_long_t mesq_send_qlimit_reached;
38505 - atomic_long_t mesq_send_amo_nacked;
38506 - atomic_long_t mesq_send_put_nacked;
38507 - atomic_long_t mesq_page_overflow;
38508 - atomic_long_t mesq_qf_locked;
38509 - atomic_long_t mesq_qf_noop_not_full;
38510 - atomic_long_t mesq_qf_switch_head_failed;
38511 - atomic_long_t mesq_qf_unexpected_error;
38512 - atomic_long_t mesq_noop_unexpected_error;
38513 - atomic_long_t mesq_noop_lb_overflow;
38514 - atomic_long_t mesq_noop_qlimit_reached;
38515 - atomic_long_t mesq_noop_amo_nacked;
38516 - atomic_long_t mesq_noop_put_nacked;
38517 - atomic_long_t mesq_noop_page_overflow;
38518 + atomic_long_unchecked_t mesq_receive;
38519 + atomic_long_unchecked_t mesq_receive_none;
38520 + atomic_long_unchecked_t mesq_send;
38521 + atomic_long_unchecked_t mesq_send_failed;
38522 + atomic_long_unchecked_t mesq_noop;
38523 + atomic_long_unchecked_t mesq_send_unexpected_error;
38524 + atomic_long_unchecked_t mesq_send_lb_overflow;
38525 + atomic_long_unchecked_t mesq_send_qlimit_reached;
38526 + atomic_long_unchecked_t mesq_send_amo_nacked;
38527 + atomic_long_unchecked_t mesq_send_put_nacked;
38528 + atomic_long_unchecked_t mesq_page_overflow;
38529 + atomic_long_unchecked_t mesq_qf_locked;
38530 + atomic_long_unchecked_t mesq_qf_noop_not_full;
38531 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
38532 + atomic_long_unchecked_t mesq_qf_unexpected_error;
38533 + atomic_long_unchecked_t mesq_noop_unexpected_error;
38534 + atomic_long_unchecked_t mesq_noop_lb_overflow;
38535 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
38536 + atomic_long_unchecked_t mesq_noop_amo_nacked;
38537 + atomic_long_unchecked_t mesq_noop_put_nacked;
38538 + atomic_long_unchecked_t mesq_noop_page_overflow;
38539
38540 };
38541
38542 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
38543 tghop_invalidate, mcsop_last};
38544
38545 struct mcs_op_statistic {
38546 - atomic_long_t count;
38547 - atomic_long_t total;
38548 + atomic_long_unchecked_t count;
38549 + atomic_long_unchecked_t total;
38550 unsigned long max;
38551 };
38552
38553 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
38554
38555 #define STAT(id) do { \
38556 if (gru_options & OPT_STATS) \
38557 - atomic_long_inc(&gru_stats.id); \
38558 + atomic_long_inc_unchecked(&gru_stats.id); \
38559 } while (0)
38560
38561 #ifdef CONFIG_SGI_GRU_DEBUG
38562 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
38563 index c862cd4..0d176fe 100644
38564 --- a/drivers/misc/sgi-xp/xp.h
38565 +++ b/drivers/misc/sgi-xp/xp.h
38566 @@ -288,7 +288,7 @@ struct xpc_interface {
38567 xpc_notify_func, void *);
38568 void (*received) (short, int, void *);
38569 enum xp_retval (*partid_to_nasids) (short, void *);
38570 -};
38571 +} __no_const;
38572
38573 extern struct xpc_interface xpc_interface;
38574
38575 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
38576 index b94d5f7..7f494c5 100644
38577 --- a/drivers/misc/sgi-xp/xpc.h
38578 +++ b/drivers/misc/sgi-xp/xpc.h
38579 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
38580 void (*received_payload) (struct xpc_channel *, void *);
38581 void (*notify_senders_of_disconnect) (struct xpc_channel *);
38582 };
38583 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
38584
38585 /* struct xpc_partition act_state values (for XPC HB) */
38586
38587 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
38588 /* found in xpc_main.c */
38589 extern struct device *xpc_part;
38590 extern struct device *xpc_chan;
38591 -extern struct xpc_arch_operations xpc_arch_ops;
38592 +extern xpc_arch_operations_no_const xpc_arch_ops;
38593 extern int xpc_disengage_timelimit;
38594 extern int xpc_disengage_timedout;
38595 extern int xpc_activate_IRQ_rcvd;
38596 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
38597 index d971817..33bdca5 100644
38598 --- a/drivers/misc/sgi-xp/xpc_main.c
38599 +++ b/drivers/misc/sgi-xp/xpc_main.c
38600 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
38601 .notifier_call = xpc_system_die,
38602 };
38603
38604 -struct xpc_arch_operations xpc_arch_ops;
38605 +xpc_arch_operations_no_const xpc_arch_ops;
38606
38607 /*
38608 * Timer function to enforce the timelimit on the partition disengage.
38609 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
38610
38611 if (((die_args->trapnr == X86_TRAP_MF) ||
38612 (die_args->trapnr == X86_TRAP_XF)) &&
38613 - !user_mode_vm(die_args->regs))
38614 + !user_mode(die_args->regs))
38615 xpc_die_deactivate();
38616
38617 break;
38618 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
38619 index 6d8f701..35b6369 100644
38620 --- a/drivers/mmc/core/mmc_ops.c
38621 +++ b/drivers/mmc/core/mmc_ops.c
38622 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
38623 void *data_buf;
38624 int is_on_stack;
38625
38626 - is_on_stack = object_is_on_stack(buf);
38627 + is_on_stack = object_starts_on_stack(buf);
38628 if (is_on_stack) {
38629 /*
38630 * dma onto stack is unsafe/nonportable, but callers to this
38631 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
38632 index 53b8fd9..615b462 100644
38633 --- a/drivers/mmc/host/dw_mmc.h
38634 +++ b/drivers/mmc/host/dw_mmc.h
38635 @@ -205,5 +205,5 @@ struct dw_mci_drv_data {
38636 int (*parse_dt)(struct dw_mci *host);
38637 int (*setup_bus)(struct dw_mci *host,
38638 struct device_node *slot_np, u8 bus_width);
38639 -};
38640 +} __do_const;
38641 #endif /* _DW_MMC_H_ */
38642 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
38643 index 82a8de1..3c56ccb 100644
38644 --- a/drivers/mmc/host/sdhci-s3c.c
38645 +++ b/drivers/mmc/host/sdhci-s3c.c
38646 @@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
38647 * we can use overriding functions instead of default.
38648 */
38649 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
38650 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
38651 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
38652 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
38653 + pax_open_kernel();
38654 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
38655 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
38656 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
38657 + pax_close_kernel();
38658 }
38659
38660 /* It supports additional host capabilities if needed */
38661 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
38662 index a4eb8b5..8c0628f 100644
38663 --- a/drivers/mtd/devices/doc2000.c
38664 +++ b/drivers/mtd/devices/doc2000.c
38665 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
38666
38667 /* The ECC will not be calculated correctly if less than 512 is written */
38668 /* DBB-
38669 - if (len != 0x200 && eccbuf)
38670 + if (len != 0x200)
38671 printk(KERN_WARNING
38672 "ECC needs a full sector write (adr: %lx size %lx)\n",
38673 (long) to, (long) len);
38674 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
38675 index 0c8bb6b..6f35deb 100644
38676 --- a/drivers/mtd/nand/denali.c
38677 +++ b/drivers/mtd/nand/denali.c
38678 @@ -24,6 +24,7 @@
38679 #include <linux/slab.h>
38680 #include <linux/mtd/mtd.h>
38681 #include <linux/module.h>
38682 +#include <linux/slab.h>
38683
38684 #include "denali.h"
38685
38686 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
38687 index 51b9d6a..52af9a7 100644
38688 --- a/drivers/mtd/nftlmount.c
38689 +++ b/drivers/mtd/nftlmount.c
38690 @@ -24,6 +24,7 @@
38691 #include <asm/errno.h>
38692 #include <linux/delay.h>
38693 #include <linux/slab.h>
38694 +#include <linux/sched.h>
38695 #include <linux/mtd/mtd.h>
38696 #include <linux/mtd/nand.h>
38697 #include <linux/mtd/nftl.h>
38698 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
38699 index 8dd6ba5..419cc1d 100644
38700 --- a/drivers/mtd/sm_ftl.c
38701 +++ b/drivers/mtd/sm_ftl.c
38702 @@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
38703 #define SM_CIS_VENDOR_OFFSET 0x59
38704 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
38705 {
38706 - struct attribute_group *attr_group;
38707 + attribute_group_no_const *attr_group;
38708 struct attribute **attributes;
38709 struct sm_sysfs_attribute *vendor_attribute;
38710
38711 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
38712 index b7d45f3..b5c89d9 100644
38713 --- a/drivers/net/bonding/bond_main.c
38714 +++ b/drivers/net/bonding/bond_main.c
38715 @@ -4861,7 +4861,7 @@ static unsigned int bond_get_num_tx_queues(void)
38716 return tx_queues;
38717 }
38718
38719 -static struct rtnl_link_ops bond_link_ops __read_mostly = {
38720 +static struct rtnl_link_ops bond_link_ops = {
38721 .kind = "bond",
38722 .priv_size = sizeof(struct bonding),
38723 .setup = bond_setup,
38724 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
38725 index 70dba5d..11a0919 100644
38726 --- a/drivers/net/ethernet/8390/ax88796.c
38727 +++ b/drivers/net/ethernet/8390/ax88796.c
38728 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
38729 if (ax->plat->reg_offsets)
38730 ei_local->reg_offset = ax->plat->reg_offsets;
38731 else {
38732 + resource_size_t _mem_size = mem_size;
38733 + do_div(_mem_size, 0x18);
38734 ei_local->reg_offset = ax->reg_offsets;
38735 for (ret = 0; ret < 0x18; ret++)
38736 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
38737 + ax->reg_offsets[ret] = _mem_size * ret;
38738 }
38739
38740 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
38741 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
38742 index 0991534..8098e92 100644
38743 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
38744 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
38745 @@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
38746 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
38747 {
38748 /* RX_MODE controlling object */
38749 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
38750 + bnx2x_init_rx_mode_obj(bp);
38751
38752 /* multicast configuration controlling object */
38753 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
38754 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
38755 index 09b625e..15b16fe 100644
38756 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
38757 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
38758 @@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
38759 return rc;
38760 }
38761
38762 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
38763 - struct bnx2x_rx_mode_obj *o)
38764 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
38765 {
38766 if (CHIP_IS_E1x(bp)) {
38767 - o->wait_comp = bnx2x_empty_rx_mode_wait;
38768 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
38769 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
38770 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
38771 } else {
38772 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
38773 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
38774 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
38775 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
38776 }
38777 }
38778
38779 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
38780 index adbd91b..58ec94a 100644
38781 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
38782 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
38783 @@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
38784
38785 /********************* RX MODE ****************/
38786
38787 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
38788 - struct bnx2x_rx_mode_obj *o);
38789 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
38790
38791 /**
38792 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
38793 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
38794 index d330e81..ce1fb9a 100644
38795 --- a/drivers/net/ethernet/broadcom/tg3.h
38796 +++ b/drivers/net/ethernet/broadcom/tg3.h
38797 @@ -146,6 +146,7 @@
38798 #define CHIPREV_ID_5750_A0 0x4000
38799 #define CHIPREV_ID_5750_A1 0x4001
38800 #define CHIPREV_ID_5750_A3 0x4003
38801 +#define CHIPREV_ID_5750_C1 0x4201
38802 #define CHIPREV_ID_5750_C2 0x4202
38803 #define CHIPREV_ID_5752_A0_HW 0x5000
38804 #define CHIPREV_ID_5752_A0 0x6000
38805 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
38806 index 8cffcdf..aadf043 100644
38807 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
38808 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
38809 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
38810 */
38811 struct l2t_skb_cb {
38812 arp_failure_handler_func arp_failure_handler;
38813 -};
38814 +} __no_const;
38815
38816 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
38817
38818 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
38819 index 4c83003..2a2a5b9 100644
38820 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
38821 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
38822 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38823 for (i=0; i<ETH_ALEN; i++) {
38824 tmp.addr[i] = dev->dev_addr[i];
38825 }
38826 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
38827 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
38828 break;
38829
38830 case DE4X5_SET_HWADDR: /* Set the hardware address */
38831 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38832 spin_lock_irqsave(&lp->lock, flags);
38833 memcpy(&statbuf, &lp->pktStats, ioc->len);
38834 spin_unlock_irqrestore(&lp->lock, flags);
38835 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
38836 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
38837 return -EFAULT;
38838 break;
38839 }
38840 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
38841 index 4d6f3c5..6169e60 100644
38842 --- a/drivers/net/ethernet/emulex/benet/be_main.c
38843 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
38844 @@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
38845
38846 if (wrapped)
38847 newacc += 65536;
38848 - ACCESS_ONCE(*acc) = newacc;
38849 + ACCESS_ONCE_RW(*acc) = newacc;
38850 }
38851
38852 void be_parse_stats(struct be_adapter *adapter)
38853 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
38854 index 74d749e..eefb1bd 100644
38855 --- a/drivers/net/ethernet/faraday/ftgmac100.c
38856 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
38857 @@ -31,6 +31,8 @@
38858 #include <linux/netdevice.h>
38859 #include <linux/phy.h>
38860 #include <linux/platform_device.h>
38861 +#include <linux/interrupt.h>
38862 +#include <linux/irqreturn.h>
38863 #include <net/ip.h>
38864
38865 #include "ftgmac100.h"
38866 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
38867 index b901a01..1ff32ee 100644
38868 --- a/drivers/net/ethernet/faraday/ftmac100.c
38869 +++ b/drivers/net/ethernet/faraday/ftmac100.c
38870 @@ -31,6 +31,8 @@
38871 #include <linux/module.h>
38872 #include <linux/netdevice.h>
38873 #include <linux/platform_device.h>
38874 +#include <linux/interrupt.h>
38875 +#include <linux/irqreturn.h>
38876
38877 #include "ftmac100.h"
38878
38879 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
38880 index bb9256a..56d8752 100644
38881 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
38882 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
38883 @@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
38884 }
38885
38886 /* update the base incval used to calculate frequency adjustment */
38887 - ACCESS_ONCE(adapter->base_incval) = incval;
38888 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
38889 smp_mb();
38890
38891 /* need lock to prevent incorrect read while modifying cyclecounter */
38892 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
38893 index fbe5363..266b4e3 100644
38894 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
38895 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
38896 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
38897 struct __vxge_hw_fifo *fifo;
38898 struct vxge_hw_fifo_config *config;
38899 u32 txdl_size, txdl_per_memblock;
38900 - struct vxge_hw_mempool_cbs fifo_mp_callback;
38901 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
38902 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
38903 + };
38904 +
38905 struct __vxge_hw_virtualpath *vpath;
38906
38907 if ((vp == NULL) || (attr == NULL)) {
38908 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
38909 goto exit;
38910 }
38911
38912 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
38913 -
38914 fifo->mempool =
38915 __vxge_hw_mempool_create(vpath->hldev,
38916 fifo->config->memblock_size,
38917 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
38918 index 998974f..ecd26db 100644
38919 --- a/drivers/net/ethernet/realtek/r8169.c
38920 +++ b/drivers/net/ethernet/realtek/r8169.c
38921 @@ -741,22 +741,22 @@ struct rtl8169_private {
38922 struct mdio_ops {
38923 void (*write)(struct rtl8169_private *, int, int);
38924 int (*read)(struct rtl8169_private *, int);
38925 - } mdio_ops;
38926 + } __no_const mdio_ops;
38927
38928 struct pll_power_ops {
38929 void (*down)(struct rtl8169_private *);
38930 void (*up)(struct rtl8169_private *);
38931 - } pll_power_ops;
38932 + } __no_const pll_power_ops;
38933
38934 struct jumbo_ops {
38935 void (*enable)(struct rtl8169_private *);
38936 void (*disable)(struct rtl8169_private *);
38937 - } jumbo_ops;
38938 + } __no_const jumbo_ops;
38939
38940 struct csi_ops {
38941 void (*write)(struct rtl8169_private *, int, int);
38942 u32 (*read)(struct rtl8169_private *, int);
38943 - } csi_ops;
38944 + } __no_const csi_ops;
38945
38946 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
38947 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
38948 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
38949 index 0767043f..08c2553 100644
38950 --- a/drivers/net/ethernet/sfc/ptp.c
38951 +++ b/drivers/net/ethernet/sfc/ptp.c
38952 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
38953 (u32)((u64)ptp->start.dma_addr >> 32));
38954
38955 /* Clear flag that signals MC ready */
38956 - ACCESS_ONCE(*start) = 0;
38957 + ACCESS_ONCE_RW(*start) = 0;
38958 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
38959 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
38960
38961 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
38962 index 0c74a70..3bc6f68 100644
38963 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
38964 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
38965 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
38966
38967 writel(value, ioaddr + MMC_CNTRL);
38968
38969 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
38970 - MMC_CNTRL, value);
38971 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
38972 +// MMC_CNTRL, value);
38973 }
38974
38975 /* To mask all all interrupts.*/
38976 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
38977 index e6fe0d8..2b7d752 100644
38978 --- a/drivers/net/hyperv/hyperv_net.h
38979 +++ b/drivers/net/hyperv/hyperv_net.h
38980 @@ -101,7 +101,7 @@ struct rndis_device {
38981
38982 enum rndis_device_state state;
38983 bool link_state;
38984 - atomic_t new_req_id;
38985 + atomic_unchecked_t new_req_id;
38986
38987 spinlock_t request_lock;
38988 struct list_head req_list;
38989 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
38990 index 2b657d4..9903bc0 100644
38991 --- a/drivers/net/hyperv/rndis_filter.c
38992 +++ b/drivers/net/hyperv/rndis_filter.c
38993 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
38994 * template
38995 */
38996 set = &rndis_msg->msg.set_req;
38997 - set->req_id = atomic_inc_return(&dev->new_req_id);
38998 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
38999
39000 /* Add to the request list */
39001 spin_lock_irqsave(&dev->request_lock, flags);
39002 @@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
39003
39004 /* Setup the rndis set */
39005 halt = &request->request_msg.msg.halt_req;
39006 - halt->req_id = atomic_inc_return(&dev->new_req_id);
39007 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39008
39009 /* Ignore return since this msg is optional. */
39010 rndis_filter_send_request(dev, request);
39011 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
39012 index 1e9cb0b..7839125 100644
39013 --- a/drivers/net/ieee802154/fakehard.c
39014 +++ b/drivers/net/ieee802154/fakehard.c
39015 @@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
39016 phy->transmit_power = 0xbf;
39017
39018 dev->netdev_ops = &fake_ops;
39019 - dev->ml_priv = &fake_mlme;
39020 + dev->ml_priv = (void *)&fake_mlme;
39021
39022 priv = netdev_priv(dev);
39023 priv->phy = phy;
39024 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
39025 index d3fb97d..19520c7 100644
39026 --- a/drivers/net/macvlan.c
39027 +++ b/drivers/net/macvlan.c
39028 @@ -851,13 +851,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
39029 int macvlan_link_register(struct rtnl_link_ops *ops)
39030 {
39031 /* common fields */
39032 - ops->priv_size = sizeof(struct macvlan_dev);
39033 - ops->validate = macvlan_validate;
39034 - ops->maxtype = IFLA_MACVLAN_MAX;
39035 - ops->policy = macvlan_policy;
39036 - ops->changelink = macvlan_changelink;
39037 - ops->get_size = macvlan_get_size;
39038 - ops->fill_info = macvlan_fill_info;
39039 + pax_open_kernel();
39040 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
39041 + *(void **)&ops->validate = macvlan_validate;
39042 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
39043 + *(const void **)&ops->policy = macvlan_policy;
39044 + *(void **)&ops->changelink = macvlan_changelink;
39045 + *(void **)&ops->get_size = macvlan_get_size;
39046 + *(void **)&ops->fill_info = macvlan_fill_info;
39047 + pax_close_kernel();
39048
39049 return rtnl_link_register(ops);
39050 };
39051 @@ -913,7 +915,7 @@ static int macvlan_device_event(struct notifier_block *unused,
39052 return NOTIFY_DONE;
39053 }
39054
39055 -static struct notifier_block macvlan_notifier_block __read_mostly = {
39056 +static struct notifier_block macvlan_notifier_block = {
39057 .notifier_call = macvlan_device_event,
39058 };
39059
39060 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
39061 index 0f0f9ce..0ca5819 100644
39062 --- a/drivers/net/macvtap.c
39063 +++ b/drivers/net/macvtap.c
39064 @@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
39065 return NOTIFY_DONE;
39066 }
39067
39068 -static struct notifier_block macvtap_notifier_block __read_mostly = {
39069 +static struct notifier_block macvtap_notifier_block = {
39070 .notifier_call = macvtap_device_event,
39071 };
39072
39073 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
39074 index daec9b0..6428fcb 100644
39075 --- a/drivers/net/phy/mdio-bitbang.c
39076 +++ b/drivers/net/phy/mdio-bitbang.c
39077 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
39078 struct mdiobb_ctrl *ctrl = bus->priv;
39079
39080 module_put(ctrl->ops->owner);
39081 + mdiobus_unregister(bus);
39082 mdiobus_free(bus);
39083 }
39084 EXPORT_SYMBOL(free_mdio_bitbang);
39085 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
39086 index 508570e..f706dc7 100644
39087 --- a/drivers/net/ppp/ppp_generic.c
39088 +++ b/drivers/net/ppp/ppp_generic.c
39089 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39090 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
39091 struct ppp_stats stats;
39092 struct ppp_comp_stats cstats;
39093 - char *vers;
39094
39095 switch (cmd) {
39096 case SIOCGPPPSTATS:
39097 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39098 break;
39099
39100 case SIOCGPPPVER:
39101 - vers = PPP_VERSION;
39102 - if (copy_to_user(addr, vers, strlen(vers) + 1))
39103 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
39104 break;
39105 err = 0;
39106 break;
39107 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
39108 index ad86660..9fd0884 100644
39109 --- a/drivers/net/team/team.c
39110 +++ b/drivers/net/team/team.c
39111 @@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
39112 return NOTIFY_DONE;
39113 }
39114
39115 -static struct notifier_block team_notifier_block __read_mostly = {
39116 +static struct notifier_block team_notifier_block = {
39117 .notifier_call = team_device_event,
39118 };
39119
39120 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
39121 index 2917a86..edd463f 100644
39122 --- a/drivers/net/tun.c
39123 +++ b/drivers/net/tun.c
39124 @@ -1836,7 +1836,7 @@ unlock:
39125 }
39126
39127 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39128 - unsigned long arg, int ifreq_len)
39129 + unsigned long arg, size_t ifreq_len)
39130 {
39131 struct tun_file *tfile = file->private_data;
39132 struct tun_struct *tun;
39133 @@ -1848,6 +1848,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39134 int vnet_hdr_sz;
39135 int ret;
39136
39137 + if (ifreq_len > sizeof ifr)
39138 + return -EFAULT;
39139 +
39140 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
39141 if (copy_from_user(&ifr, argp, ifreq_len))
39142 return -EFAULT;
39143 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
39144 index cd8ccb2..cff5144 100644
39145 --- a/drivers/net/usb/hso.c
39146 +++ b/drivers/net/usb/hso.c
39147 @@ -71,7 +71,7 @@
39148 #include <asm/byteorder.h>
39149 #include <linux/serial_core.h>
39150 #include <linux/serial.h>
39151 -
39152 +#include <asm/local.h>
39153
39154 #define MOD_AUTHOR "Option Wireless"
39155 #define MOD_DESCRIPTION "USB High Speed Option driver"
39156 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
39157 struct urb *urb;
39158
39159 urb = serial->rx_urb[0];
39160 - if (serial->port.count > 0) {
39161 + if (atomic_read(&serial->port.count) > 0) {
39162 count = put_rxbuf_data(urb, serial);
39163 if (count == -1)
39164 return;
39165 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
39166 DUMP1(urb->transfer_buffer, urb->actual_length);
39167
39168 /* Anyone listening? */
39169 - if (serial->port.count == 0)
39170 + if (atomic_read(&serial->port.count) == 0)
39171 return;
39172
39173 if (status == 0) {
39174 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39175 tty_port_tty_set(&serial->port, tty);
39176
39177 /* check for port already opened, if not set the termios */
39178 - serial->port.count++;
39179 - if (serial->port.count == 1) {
39180 + if (atomic_inc_return(&serial->port.count) == 1) {
39181 serial->rx_state = RX_IDLE;
39182 /* Force default termio settings */
39183 _hso_serial_set_termios(tty, NULL);
39184 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39185 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
39186 if (result) {
39187 hso_stop_serial_device(serial->parent);
39188 - serial->port.count--;
39189 + atomic_dec(&serial->port.count);
39190 kref_put(&serial->parent->ref, hso_serial_ref_free);
39191 }
39192 } else {
39193 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
39194
39195 /* reset the rts and dtr */
39196 /* do the actual close */
39197 - serial->port.count--;
39198 + atomic_dec(&serial->port.count);
39199
39200 - if (serial->port.count <= 0) {
39201 - serial->port.count = 0;
39202 + if (atomic_read(&serial->port.count) <= 0) {
39203 + atomic_set(&serial->port.count, 0);
39204 tty_port_tty_set(&serial->port, NULL);
39205 if (!usb_gone)
39206 hso_stop_serial_device(serial->parent);
39207 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
39208
39209 /* the actual setup */
39210 spin_lock_irqsave(&serial->serial_lock, flags);
39211 - if (serial->port.count)
39212 + if (atomic_read(&serial->port.count))
39213 _hso_serial_set_termios(tty, old);
39214 else
39215 tty->termios = *old;
39216 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
39217 D1("Pending read interrupt on port %d\n", i);
39218 spin_lock(&serial->serial_lock);
39219 if (serial->rx_state == RX_IDLE &&
39220 - serial->port.count > 0) {
39221 + atomic_read(&serial->port.count) > 0) {
39222 /* Setup and send a ctrl req read on
39223 * port i */
39224 if (!serial->rx_urb_filled[0]) {
39225 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
39226 /* Start all serial ports */
39227 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
39228 if (serial_table[i] && (serial_table[i]->interface == iface)) {
39229 - if (dev2ser(serial_table[i])->port.count) {
39230 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
39231 result =
39232 hso_start_serial_device(serial_table[i], GFP_NOIO);
39233 hso_kick_transmit(dev2ser(serial_table[i]));
39234 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
39235 index 656230e..15525a8 100644
39236 --- a/drivers/net/vxlan.c
39237 +++ b/drivers/net/vxlan.c
39238 @@ -1428,7 +1428,7 @@ nla_put_failure:
39239 return -EMSGSIZE;
39240 }
39241
39242 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
39243 +static struct rtnl_link_ops vxlan_link_ops = {
39244 .kind = "vxlan",
39245 .maxtype = IFLA_VXLAN_MAX,
39246 .policy = vxlan_policy,
39247 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39248 index 8d78253..bebbb68 100644
39249 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39250 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39251 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39252 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
39253 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
39254
39255 - ACCESS_ONCE(ads->ds_link) = i->link;
39256 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
39257 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
39258 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
39259
39260 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
39261 ctl6 = SM(i->keytype, AR_EncrType);
39262 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39263
39264 if ((i->is_first || i->is_last) &&
39265 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
39266 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
39267 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
39268 | set11nTries(i->rates, 1)
39269 | set11nTries(i->rates, 2)
39270 | set11nTries(i->rates, 3)
39271 | (i->dur_update ? AR_DurUpdateEna : 0)
39272 | SM(0, AR_BurstDur);
39273
39274 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
39275 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
39276 | set11nRate(i->rates, 1)
39277 | set11nRate(i->rates, 2)
39278 | set11nRate(i->rates, 3);
39279 } else {
39280 - ACCESS_ONCE(ads->ds_ctl2) = 0;
39281 - ACCESS_ONCE(ads->ds_ctl3) = 0;
39282 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
39283 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
39284 }
39285
39286 if (!i->is_first) {
39287 - ACCESS_ONCE(ads->ds_ctl0) = 0;
39288 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39289 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39290 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
39291 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39292 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39293 return;
39294 }
39295
39296 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39297 break;
39298 }
39299
39300 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39301 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39302 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39303 | SM(i->txpower, AR_XmitPower)
39304 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39305 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39306 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
39307 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
39308
39309 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39310 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39311 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39312 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39313
39314 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
39315 return;
39316
39317 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39318 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39319 | set11nPktDurRTSCTS(i->rates, 1);
39320
39321 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39322 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39323 | set11nPktDurRTSCTS(i->rates, 3);
39324
39325 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39326 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39327 | set11nRateFlags(i->rates, 1)
39328 | set11nRateFlags(i->rates, 2)
39329 | set11nRateFlags(i->rates, 3)
39330 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39331 index 301bf72..3f5654f 100644
39332 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39333 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39334 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39335 (i->qcu << AR_TxQcuNum_S) | desc_len;
39336
39337 checksum += val;
39338 - ACCESS_ONCE(ads->info) = val;
39339 + ACCESS_ONCE_RW(ads->info) = val;
39340
39341 checksum += i->link;
39342 - ACCESS_ONCE(ads->link) = i->link;
39343 + ACCESS_ONCE_RW(ads->link) = i->link;
39344
39345 checksum += i->buf_addr[0];
39346 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
39347 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
39348 checksum += i->buf_addr[1];
39349 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
39350 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
39351 checksum += i->buf_addr[2];
39352 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
39353 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
39354 checksum += i->buf_addr[3];
39355 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
39356 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
39357
39358 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
39359 - ACCESS_ONCE(ads->ctl3) = val;
39360 + ACCESS_ONCE_RW(ads->ctl3) = val;
39361 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
39362 - ACCESS_ONCE(ads->ctl5) = val;
39363 + ACCESS_ONCE_RW(ads->ctl5) = val;
39364 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
39365 - ACCESS_ONCE(ads->ctl7) = val;
39366 + ACCESS_ONCE_RW(ads->ctl7) = val;
39367 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
39368 - ACCESS_ONCE(ads->ctl9) = val;
39369 + ACCESS_ONCE_RW(ads->ctl9) = val;
39370
39371 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
39372 - ACCESS_ONCE(ads->ctl10) = checksum;
39373 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
39374
39375 if (i->is_first || i->is_last) {
39376 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
39377 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
39378 | set11nTries(i->rates, 1)
39379 | set11nTries(i->rates, 2)
39380 | set11nTries(i->rates, 3)
39381 | (i->dur_update ? AR_DurUpdateEna : 0)
39382 | SM(0, AR_BurstDur);
39383
39384 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
39385 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
39386 | set11nRate(i->rates, 1)
39387 | set11nRate(i->rates, 2)
39388 | set11nRate(i->rates, 3);
39389 } else {
39390 - ACCESS_ONCE(ads->ctl13) = 0;
39391 - ACCESS_ONCE(ads->ctl14) = 0;
39392 + ACCESS_ONCE_RW(ads->ctl13) = 0;
39393 + ACCESS_ONCE_RW(ads->ctl14) = 0;
39394 }
39395
39396 ads->ctl20 = 0;
39397 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39398
39399 ctl17 = SM(i->keytype, AR_EncrType);
39400 if (!i->is_first) {
39401 - ACCESS_ONCE(ads->ctl11) = 0;
39402 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39403 - ACCESS_ONCE(ads->ctl15) = 0;
39404 - ACCESS_ONCE(ads->ctl16) = 0;
39405 - ACCESS_ONCE(ads->ctl17) = ctl17;
39406 - ACCESS_ONCE(ads->ctl18) = 0;
39407 - ACCESS_ONCE(ads->ctl19) = 0;
39408 + ACCESS_ONCE_RW(ads->ctl11) = 0;
39409 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39410 + ACCESS_ONCE_RW(ads->ctl15) = 0;
39411 + ACCESS_ONCE_RW(ads->ctl16) = 0;
39412 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39413 + ACCESS_ONCE_RW(ads->ctl18) = 0;
39414 + ACCESS_ONCE_RW(ads->ctl19) = 0;
39415 return;
39416 }
39417
39418 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39419 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39420 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39421 | SM(i->txpower, AR_XmitPower)
39422 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39423 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39424 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
39425 ctl12 |= SM(val, AR_PAPRDChainMask);
39426
39427 - ACCESS_ONCE(ads->ctl12) = ctl12;
39428 - ACCESS_ONCE(ads->ctl17) = ctl17;
39429 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
39430 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39431
39432 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39433 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39434 | set11nPktDurRTSCTS(i->rates, 1);
39435
39436 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39437 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39438 | set11nPktDurRTSCTS(i->rates, 3);
39439
39440 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
39441 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
39442 | set11nRateFlags(i->rates, 1)
39443 | set11nRateFlags(i->rates, 2)
39444 | set11nRateFlags(i->rates, 3)
39445 | SM(i->rtscts_rate, AR_RTSCTSRate);
39446
39447 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
39448 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
39449 }
39450
39451 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
39452 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
39453 index 9d26fc5..60d9f14 100644
39454 --- a/drivers/net/wireless/ath/ath9k/hw.h
39455 +++ b/drivers/net/wireless/ath/ath9k/hw.h
39456 @@ -658,7 +658,7 @@ struct ath_hw_private_ops {
39457
39458 /* ANI */
39459 void (*ani_cache_ini_regs)(struct ath_hw *ah);
39460 -};
39461 +} __no_const;
39462
39463 /**
39464 * struct ath_hw_ops - callbacks used by hardware code and driver code
39465 @@ -688,7 +688,7 @@ struct ath_hw_ops {
39466 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
39467 struct ath_hw_antcomb_conf *antconf);
39468 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
39469 -};
39470 +} __no_const;
39471
39472 struct ath_nf_limits {
39473 s16 max;
39474 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
39475 index 3726cd6..b655808 100644
39476 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
39477 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
39478 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
39479 */
39480 if (il3945_mod_params.disable_hw_scan) {
39481 D_INFO("Disabling hw_scan\n");
39482 - il3945_mac_ops.hw_scan = NULL;
39483 + pax_open_kernel();
39484 + *(void **)&il3945_mac_ops.hw_scan = NULL;
39485 + pax_close_kernel();
39486 }
39487
39488 D_INFO("*** LOAD DRIVER ***\n");
39489 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39490 index 5b9533e..7733880 100644
39491 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39492 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39493 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
39494 {
39495 struct iwl_priv *priv = file->private_data;
39496 char buf[64];
39497 - int buf_size;
39498 + size_t buf_size;
39499 u32 offset, len;
39500
39501 memset(buf, 0, sizeof(buf));
39502 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
39503 struct iwl_priv *priv = file->private_data;
39504
39505 char buf[8];
39506 - int buf_size;
39507 + size_t buf_size;
39508 u32 reset_flag;
39509
39510 memset(buf, 0, sizeof(buf));
39511 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
39512 {
39513 struct iwl_priv *priv = file->private_data;
39514 char buf[8];
39515 - int buf_size;
39516 + size_t buf_size;
39517 int ht40;
39518
39519 memset(buf, 0, sizeof(buf));
39520 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
39521 {
39522 struct iwl_priv *priv = file->private_data;
39523 char buf[8];
39524 - int buf_size;
39525 + size_t buf_size;
39526 int value;
39527
39528 memset(buf, 0, sizeof(buf));
39529 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
39530 {
39531 struct iwl_priv *priv = file->private_data;
39532 char buf[8];
39533 - int buf_size;
39534 + size_t buf_size;
39535 int clear;
39536
39537 memset(buf, 0, sizeof(buf));
39538 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
39539 {
39540 struct iwl_priv *priv = file->private_data;
39541 char buf[8];
39542 - int buf_size;
39543 + size_t buf_size;
39544 int trace;
39545
39546 memset(buf, 0, sizeof(buf));
39547 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
39548 {
39549 struct iwl_priv *priv = file->private_data;
39550 char buf[8];
39551 - int buf_size;
39552 + size_t buf_size;
39553 int missed;
39554
39555 memset(buf, 0, sizeof(buf));
39556 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
39557
39558 struct iwl_priv *priv = file->private_data;
39559 char buf[8];
39560 - int buf_size;
39561 + size_t buf_size;
39562 int plcp;
39563
39564 memset(buf, 0, sizeof(buf));
39565 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
39566
39567 struct iwl_priv *priv = file->private_data;
39568 char buf[8];
39569 - int buf_size;
39570 + size_t buf_size;
39571 int flush;
39572
39573 memset(buf, 0, sizeof(buf));
39574 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
39575
39576 struct iwl_priv *priv = file->private_data;
39577 char buf[8];
39578 - int buf_size;
39579 + size_t buf_size;
39580 int rts;
39581
39582 if (!priv->cfg->ht_params)
39583 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
39584 {
39585 struct iwl_priv *priv = file->private_data;
39586 char buf[8];
39587 - int buf_size;
39588 + size_t buf_size;
39589
39590 memset(buf, 0, sizeof(buf));
39591 buf_size = min(count, sizeof(buf) - 1);
39592 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
39593 struct iwl_priv *priv = file->private_data;
39594 u32 event_log_flag;
39595 char buf[8];
39596 - int buf_size;
39597 + size_t buf_size;
39598
39599 /* check that the interface is up */
39600 if (!iwl_is_ready(priv))
39601 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
39602 struct iwl_priv *priv = file->private_data;
39603 char buf[8];
39604 u32 calib_disabled;
39605 - int buf_size;
39606 + size_t buf_size;
39607
39608 memset(buf, 0, sizeof(buf));
39609 buf_size = min(count, sizeof(buf) - 1);
39610 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
39611 index 35708b9..31f7754 100644
39612 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
39613 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
39614 @@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
39615 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
39616
39617 char buf[8];
39618 - int buf_size;
39619 + size_t buf_size;
39620 u32 reset_flag;
39621
39622 memset(buf, 0, sizeof(buf));
39623 @@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
39624 {
39625 struct iwl_trans *trans = file->private_data;
39626 char buf[8];
39627 - int buf_size;
39628 + size_t buf_size;
39629 int csr;
39630
39631 memset(buf, 0, sizeof(buf));
39632 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
39633 index ff90855..e46d223 100644
39634 --- a/drivers/net/wireless/mac80211_hwsim.c
39635 +++ b/drivers/net/wireless/mac80211_hwsim.c
39636 @@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
39637
39638 if (channels > 1) {
39639 hwsim_if_comb.num_different_channels = channels;
39640 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
39641 - mac80211_hwsim_ops.cancel_hw_scan =
39642 - mac80211_hwsim_cancel_hw_scan;
39643 - mac80211_hwsim_ops.sw_scan_start = NULL;
39644 - mac80211_hwsim_ops.sw_scan_complete = NULL;
39645 - mac80211_hwsim_ops.remain_on_channel =
39646 - mac80211_hwsim_roc;
39647 - mac80211_hwsim_ops.cancel_remain_on_channel =
39648 - mac80211_hwsim_croc;
39649 - mac80211_hwsim_ops.add_chanctx =
39650 - mac80211_hwsim_add_chanctx;
39651 - mac80211_hwsim_ops.remove_chanctx =
39652 - mac80211_hwsim_remove_chanctx;
39653 - mac80211_hwsim_ops.change_chanctx =
39654 - mac80211_hwsim_change_chanctx;
39655 - mac80211_hwsim_ops.assign_vif_chanctx =
39656 - mac80211_hwsim_assign_vif_chanctx;
39657 - mac80211_hwsim_ops.unassign_vif_chanctx =
39658 - mac80211_hwsim_unassign_vif_chanctx;
39659 + pax_open_kernel();
39660 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
39661 + *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
39662 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
39663 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
39664 + *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
39665 + *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
39666 + *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
39667 + *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
39668 + *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
39669 + *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
39670 + *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
39671 + pax_close_kernel();
39672 }
39673
39674 spin_lock_init(&hwsim_radio_lock);
39675 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
39676 index abe1d03..fb02c22 100644
39677 --- a/drivers/net/wireless/rndis_wlan.c
39678 +++ b/drivers/net/wireless/rndis_wlan.c
39679 @@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
39680
39681 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
39682
39683 - if (rts_threshold < 0 || rts_threshold > 2347)
39684 + if (rts_threshold > 2347)
39685 rts_threshold = 2347;
39686
39687 tmp = cpu_to_le32(rts_threshold);
39688 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
39689 index 0751b35..246ba3e 100644
39690 --- a/drivers/net/wireless/rt2x00/rt2x00.h
39691 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
39692 @@ -398,7 +398,7 @@ struct rt2x00_intf {
39693 * for hardware which doesn't support hardware
39694 * sequence counting.
39695 */
39696 - atomic_t seqno;
39697 + atomic_unchecked_t seqno;
39698 };
39699
39700 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
39701 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
39702 index e488b94..14b6a0c 100644
39703 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
39704 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
39705 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
39706 * sequence counter given by mac80211.
39707 */
39708 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
39709 - seqno = atomic_add_return(0x10, &intf->seqno);
39710 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
39711 else
39712 - seqno = atomic_read(&intf->seqno);
39713 + seqno = atomic_read_unchecked(&intf->seqno);
39714
39715 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
39716 hdr->seq_ctrl |= cpu_to_le16(seqno);
39717 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
39718 index e57ee48..541cf6c 100644
39719 --- a/drivers/net/wireless/ti/wl1251/sdio.c
39720 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
39721 @@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
39722
39723 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
39724
39725 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
39726 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
39727 + pax_open_kernel();
39728 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
39729 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
39730 + pax_close_kernel();
39731
39732 wl1251_info("using dedicated interrupt line");
39733 } else {
39734 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
39735 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
39736 + pax_open_kernel();
39737 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
39738 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
39739 + pax_close_kernel();
39740
39741 wl1251_info("using SDIO interrupt");
39742 }
39743 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
39744 index e5f5f8f..fdf15b7 100644
39745 --- a/drivers/net/wireless/ti/wl12xx/main.c
39746 +++ b/drivers/net/wireless/ti/wl12xx/main.c
39747 @@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
39748 sizeof(wl->conf.mem));
39749
39750 /* read data preparation is only needed by wl127x */
39751 - wl->ops->prepare_read = wl127x_prepare_read;
39752 + pax_open_kernel();
39753 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
39754 + pax_close_kernel();
39755
39756 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
39757 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
39758 @@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
39759 sizeof(wl->conf.mem));
39760
39761 /* read data preparation is only needed by wl127x */
39762 - wl->ops->prepare_read = wl127x_prepare_read;
39763 + pax_open_kernel();
39764 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
39765 + pax_close_kernel();
39766
39767 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
39768 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
39769 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
39770 index 8d8c1f8..e754844 100644
39771 --- a/drivers/net/wireless/ti/wl18xx/main.c
39772 +++ b/drivers/net/wireless/ti/wl18xx/main.c
39773 @@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
39774 }
39775
39776 if (!checksum_param) {
39777 - wl18xx_ops.set_rx_csum = NULL;
39778 - wl18xx_ops.init_vif = NULL;
39779 + pax_open_kernel();
39780 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
39781 + *(void **)&wl18xx_ops.init_vif = NULL;
39782 + pax_close_kernel();
39783 }
39784
39785 /* Enable 11a Band only if we have 5G antennas */
39786 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
39787 index d93b2b6..ae50401 100644
39788 --- a/drivers/oprofile/buffer_sync.c
39789 +++ b/drivers/oprofile/buffer_sync.c
39790 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
39791 if (cookie == NO_COOKIE)
39792 offset = pc;
39793 if (cookie == INVALID_COOKIE) {
39794 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39795 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39796 offset = pc;
39797 }
39798 if (cookie != last_cookie) {
39799 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
39800 /* add userspace sample */
39801
39802 if (!mm) {
39803 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
39804 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
39805 return 0;
39806 }
39807
39808 cookie = lookup_dcookie(mm, s->eip, &offset);
39809
39810 if (cookie == INVALID_COOKIE) {
39811 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39812 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39813 return 0;
39814 }
39815
39816 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
39817 /* ignore backtraces if failed to add a sample */
39818 if (state == sb_bt_start) {
39819 state = sb_bt_ignore;
39820 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
39821 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
39822 }
39823 }
39824 release_mm(mm);
39825 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
39826 index c0cc4e7..44d4e54 100644
39827 --- a/drivers/oprofile/event_buffer.c
39828 +++ b/drivers/oprofile/event_buffer.c
39829 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
39830 }
39831
39832 if (buffer_pos == buffer_size) {
39833 - atomic_inc(&oprofile_stats.event_lost_overflow);
39834 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
39835 return;
39836 }
39837
39838 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
39839 index ed2c3ec..deda85a 100644
39840 --- a/drivers/oprofile/oprof.c
39841 +++ b/drivers/oprofile/oprof.c
39842 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
39843 if (oprofile_ops.switch_events())
39844 return;
39845
39846 - atomic_inc(&oprofile_stats.multiplex_counter);
39847 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
39848 start_switch_worker();
39849 }
39850
39851 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
39852 index 917d28e..d62d981 100644
39853 --- a/drivers/oprofile/oprofile_stats.c
39854 +++ b/drivers/oprofile/oprofile_stats.c
39855 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
39856 cpu_buf->sample_invalid_eip = 0;
39857 }
39858
39859 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
39860 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
39861 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
39862 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
39863 - atomic_set(&oprofile_stats.multiplex_counter, 0);
39864 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
39865 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
39866 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
39867 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
39868 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
39869 }
39870
39871
39872 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
39873 index 38b6fc0..b5cbfce 100644
39874 --- a/drivers/oprofile/oprofile_stats.h
39875 +++ b/drivers/oprofile/oprofile_stats.h
39876 @@ -13,11 +13,11 @@
39877 #include <linux/atomic.h>
39878
39879 struct oprofile_stat_struct {
39880 - atomic_t sample_lost_no_mm;
39881 - atomic_t sample_lost_no_mapping;
39882 - atomic_t bt_lost_no_mapping;
39883 - atomic_t event_lost_overflow;
39884 - atomic_t multiplex_counter;
39885 + atomic_unchecked_t sample_lost_no_mm;
39886 + atomic_unchecked_t sample_lost_no_mapping;
39887 + atomic_unchecked_t bt_lost_no_mapping;
39888 + atomic_unchecked_t event_lost_overflow;
39889 + atomic_unchecked_t multiplex_counter;
39890 };
39891
39892 extern struct oprofile_stat_struct oprofile_stats;
39893 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
39894 index 849357c..b83c1e0 100644
39895 --- a/drivers/oprofile/oprofilefs.c
39896 +++ b/drivers/oprofile/oprofilefs.c
39897 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
39898
39899
39900 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
39901 - char const *name, atomic_t *val)
39902 + char const *name, atomic_unchecked_t *val)
39903 {
39904 return __oprofilefs_create_file(sb, root, name,
39905 &atomic_ro_fops, 0444, val);
39906 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
39907 index 93404f7..4a313d8 100644
39908 --- a/drivers/oprofile/timer_int.c
39909 +++ b/drivers/oprofile/timer_int.c
39910 @@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
39911 return NOTIFY_OK;
39912 }
39913
39914 -static struct notifier_block __refdata oprofile_cpu_notifier = {
39915 +static struct notifier_block oprofile_cpu_notifier = {
39916 .notifier_call = oprofile_cpu_notify,
39917 };
39918
39919 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
39920 index 3f56bc0..707d642 100644
39921 --- a/drivers/parport/procfs.c
39922 +++ b/drivers/parport/procfs.c
39923 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
39924
39925 *ppos += len;
39926
39927 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
39928 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
39929 }
39930
39931 #ifdef CONFIG_PARPORT_1284
39932 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
39933
39934 *ppos += len;
39935
39936 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
39937 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
39938 }
39939 #endif /* IEEE1284.3 support. */
39940
39941 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
39942 index c35e8ad..fc33beb 100644
39943 --- a/drivers/pci/hotplug/acpiphp_ibm.c
39944 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
39945 @@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
39946 goto init_cleanup;
39947 }
39948
39949 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
39950 + pax_open_kernel();
39951 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
39952 + pax_close_kernel();
39953 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
39954
39955 return retval;
39956 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
39957 index a6a71c4..c91097b 100644
39958 --- a/drivers/pci/hotplug/cpcihp_generic.c
39959 +++ b/drivers/pci/hotplug/cpcihp_generic.c
39960 @@ -73,7 +73,6 @@ static u16 port;
39961 static unsigned int enum_bit;
39962 static u8 enum_mask;
39963
39964 -static struct cpci_hp_controller_ops generic_hpc_ops;
39965 static struct cpci_hp_controller generic_hpc;
39966
39967 static int __init validate_parameters(void)
39968 @@ -139,6 +138,10 @@ static int query_enum(void)
39969 return ((value & enum_mask) == enum_mask);
39970 }
39971
39972 +static struct cpci_hp_controller_ops generic_hpc_ops = {
39973 + .query_enum = query_enum,
39974 +};
39975 +
39976 static int __init cpcihp_generic_init(void)
39977 {
39978 int status;
39979 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
39980 pci_dev_put(dev);
39981
39982 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
39983 - generic_hpc_ops.query_enum = query_enum;
39984 generic_hpc.ops = &generic_hpc_ops;
39985
39986 status = cpci_hp_register_controller(&generic_hpc);
39987 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
39988 index 449b4bb..257e2e8 100644
39989 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
39990 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
39991 @@ -59,7 +59,6 @@
39992 /* local variables */
39993 static bool debug;
39994 static bool poll;
39995 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
39996 static struct cpci_hp_controller zt5550_hpc;
39997
39998 /* Primary cPCI bus bridge device */
39999 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
40000 return 0;
40001 }
40002
40003 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
40004 + .query_enum = zt5550_hc_query_enum,
40005 +};
40006 +
40007 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
40008 {
40009 int status;
40010 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
40011 dbg("returned from zt5550_hc_config");
40012
40013 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
40014 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
40015 zt5550_hpc.ops = &zt5550_hpc_ops;
40016 if(!poll) {
40017 zt5550_hpc.irq = hc_dev->irq;
40018 zt5550_hpc.irq_flags = IRQF_SHARED;
40019 zt5550_hpc.dev_id = hc_dev;
40020
40021 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40022 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40023 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40024 + pax_open_kernel();
40025 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40026 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40027 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40028 + pax_open_kernel();
40029 } else {
40030 info("using ENUM# polling mode");
40031 }
40032 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
40033 index 76ba8a1..20ca857 100644
40034 --- a/drivers/pci/hotplug/cpqphp_nvram.c
40035 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
40036 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
40037
40038 void compaq_nvram_init (void __iomem *rom_start)
40039 {
40040 +
40041 +#ifndef CONFIG_PAX_KERNEXEC
40042 if (rom_start) {
40043 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
40044 }
40045 +#endif
40046 +
40047 dbg("int15 entry = %p\n", compaq_int15_entry_point);
40048
40049 /* initialize our int15 lock */
40050 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
40051 index 202f4a9..8ee47d0 100644
40052 --- a/drivers/pci/hotplug/pci_hotplug_core.c
40053 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
40054 @@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
40055 return -EINVAL;
40056 }
40057
40058 - slot->ops->owner = owner;
40059 - slot->ops->mod_name = mod_name;
40060 + pax_open_kernel();
40061 + *(struct module **)&slot->ops->owner = owner;
40062 + *(const char **)&slot->ops->mod_name = mod_name;
40063 + pax_close_kernel();
40064
40065 mutex_lock(&pci_hp_mutex);
40066 /*
40067 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
40068 index 939bd1d..a1459c9 100644
40069 --- a/drivers/pci/hotplug/pciehp_core.c
40070 +++ b/drivers/pci/hotplug/pciehp_core.c
40071 @@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
40072 struct slot *slot = ctrl->slot;
40073 struct hotplug_slot *hotplug = NULL;
40074 struct hotplug_slot_info *info = NULL;
40075 - struct hotplug_slot_ops *ops = NULL;
40076 + hotplug_slot_ops_no_const *ops = NULL;
40077 char name[SLOT_NAME_SIZE];
40078 int retval = -ENOMEM;
40079
40080 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
40081 index 9c6e9bb..2916736 100644
40082 --- a/drivers/pci/pci-sysfs.c
40083 +++ b/drivers/pci/pci-sysfs.c
40084 @@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
40085 {
40086 /* allocate attribute structure, piggyback attribute name */
40087 int name_len = write_combine ? 13 : 10;
40088 - struct bin_attribute *res_attr;
40089 + bin_attribute_no_const *res_attr;
40090 int retval;
40091
40092 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
40093 @@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
40094 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
40095 {
40096 int retval;
40097 - struct bin_attribute *attr;
40098 + bin_attribute_no_const *attr;
40099
40100 /* If the device has VPD, try to expose it in sysfs. */
40101 if (dev->vpd) {
40102 @@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
40103 {
40104 int retval;
40105 int rom_size = 0;
40106 - struct bin_attribute *attr;
40107 + bin_attribute_no_const *attr;
40108
40109 if (!sysfs_initialized)
40110 return -EACCES;
40111 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
40112 index e851829..a1a7196 100644
40113 --- a/drivers/pci/pci.h
40114 +++ b/drivers/pci/pci.h
40115 @@ -98,7 +98,7 @@ struct pci_vpd_ops {
40116 struct pci_vpd {
40117 unsigned int len;
40118 const struct pci_vpd_ops *ops;
40119 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
40120 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
40121 };
40122
40123 extern int pci_vpd_pci22_init(struct pci_dev *dev);
40124 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
40125 index 8474b6a..ee81993 100644
40126 --- a/drivers/pci/pcie/aspm.c
40127 +++ b/drivers/pci/pcie/aspm.c
40128 @@ -27,9 +27,9 @@
40129 #define MODULE_PARAM_PREFIX "pcie_aspm."
40130
40131 /* Note: those are not register definitions */
40132 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
40133 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
40134 -#define ASPM_STATE_L1 (4) /* L1 state */
40135 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
40136 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
40137 +#define ASPM_STATE_L1 (4U) /* L1 state */
40138 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
40139 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
40140
40141 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
40142 index 6186f03..1a78714 100644
40143 --- a/drivers/pci/probe.c
40144 +++ b/drivers/pci/probe.c
40145 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
40146 struct pci_bus_region region;
40147 bool bar_too_big = false, bar_disabled = false;
40148
40149 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
40150 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
40151
40152 /* No printks while decoding is disabled! */
40153 if (!dev->mmio_always_on) {
40154 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
40155 index 9b8505c..f00870a 100644
40156 --- a/drivers/pci/proc.c
40157 +++ b/drivers/pci/proc.c
40158 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
40159 static int __init pci_proc_init(void)
40160 {
40161 struct pci_dev *dev = NULL;
40162 +
40163 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
40164 +#ifdef CONFIG_GRKERNSEC_PROC_USER
40165 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
40166 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
40167 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
40168 +#endif
40169 +#else
40170 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
40171 +#endif
40172 proc_create("devices", 0, proc_bus_pci_dir,
40173 &proc_bus_pci_dev_operations);
40174 proc_initialized = 1;
40175 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
40176 index 2111dbb..79e434b 100644
40177 --- a/drivers/platform/x86/msi-laptop.c
40178 +++ b/drivers/platform/x86/msi-laptop.c
40179 @@ -820,12 +820,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
40180 int result;
40181
40182 /* allow userland write sysfs file */
40183 - dev_attr_bluetooth.store = store_bluetooth;
40184 - dev_attr_wlan.store = store_wlan;
40185 - dev_attr_threeg.store = store_threeg;
40186 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
40187 - dev_attr_wlan.attr.mode |= S_IWUSR;
40188 - dev_attr_threeg.attr.mode |= S_IWUSR;
40189 + pax_open_kernel();
40190 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
40191 + *(void **)&dev_attr_wlan.store = store_wlan;
40192 + *(void **)&dev_attr_threeg.store = store_threeg;
40193 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
40194 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
40195 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
40196 + pax_close_kernel();
40197
40198 /* disable hardware control by fn key */
40199 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
40200 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
40201 index 0fe987f..6f3d5c3 100644
40202 --- a/drivers/platform/x86/sony-laptop.c
40203 +++ b/drivers/platform/x86/sony-laptop.c
40204 @@ -2356,7 +2356,7 @@ static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
40205 }
40206
40207 /* High speed charging function */
40208 -static struct device_attribute *hsc_handle;
40209 +static device_attribute_no_const *hsc_handle;
40210
40211 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
40212 struct device_attribute *attr,
40213 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
40214 index f946ca7..f25c833 100644
40215 --- a/drivers/platform/x86/thinkpad_acpi.c
40216 +++ b/drivers/platform/x86/thinkpad_acpi.c
40217 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
40218 return 0;
40219 }
40220
40221 -void static hotkey_mask_warn_incomplete_mask(void)
40222 +static void hotkey_mask_warn_incomplete_mask(void)
40223 {
40224 /* log only what the user can fix... */
40225 const u32 wantedmask = hotkey_driver_mask &
40226 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
40227 }
40228 }
40229
40230 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40231 - struct tp_nvram_state *newn,
40232 - const u32 event_mask)
40233 -{
40234 -
40235 #define TPACPI_COMPARE_KEY(__scancode, __member) \
40236 do { \
40237 if ((event_mask & (1 << __scancode)) && \
40238 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40239 tpacpi_hotkey_send_key(__scancode); \
40240 } while (0)
40241
40242 - void issue_volchange(const unsigned int oldvol,
40243 - const unsigned int newvol)
40244 - {
40245 - unsigned int i = oldvol;
40246 +static void issue_volchange(const unsigned int oldvol,
40247 + const unsigned int newvol,
40248 + const u32 event_mask)
40249 +{
40250 + unsigned int i = oldvol;
40251
40252 - while (i > newvol) {
40253 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40254 - i--;
40255 - }
40256 - while (i < newvol) {
40257 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40258 - i++;
40259 - }
40260 + while (i > newvol) {
40261 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40262 + i--;
40263 }
40264 + while (i < newvol) {
40265 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40266 + i++;
40267 + }
40268 +}
40269
40270 - void issue_brightnesschange(const unsigned int oldbrt,
40271 - const unsigned int newbrt)
40272 - {
40273 - unsigned int i = oldbrt;
40274 +static void issue_brightnesschange(const unsigned int oldbrt,
40275 + const unsigned int newbrt,
40276 + const u32 event_mask)
40277 +{
40278 + unsigned int i = oldbrt;
40279
40280 - while (i > newbrt) {
40281 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40282 - i--;
40283 - }
40284 - while (i < newbrt) {
40285 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40286 - i++;
40287 - }
40288 + while (i > newbrt) {
40289 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40290 + i--;
40291 + }
40292 + while (i < newbrt) {
40293 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40294 + i++;
40295 }
40296 +}
40297
40298 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40299 + struct tp_nvram_state *newn,
40300 + const u32 event_mask)
40301 +{
40302 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
40303 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
40304 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
40305 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40306 oldn->volume_level != newn->volume_level) {
40307 /* recently muted, or repeated mute keypress, or
40308 * multiple presses ending in mute */
40309 - issue_volchange(oldn->volume_level, newn->volume_level);
40310 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40311 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
40312 }
40313 } else {
40314 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40315 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40316 }
40317 if (oldn->volume_level != newn->volume_level) {
40318 - issue_volchange(oldn->volume_level, newn->volume_level);
40319 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40320 } else if (oldn->volume_toggle != newn->volume_toggle) {
40321 /* repeated vol up/down keypress at end of scale ? */
40322 if (newn->volume_level == 0)
40323 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40324 /* handle brightness */
40325 if (oldn->brightness_level != newn->brightness_level) {
40326 issue_brightnesschange(oldn->brightness_level,
40327 - newn->brightness_level);
40328 + newn->brightness_level,
40329 + event_mask);
40330 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
40331 /* repeated key presses that didn't change state */
40332 if (newn->brightness_level == 0)
40333 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40334 && !tp_features.bright_unkfw)
40335 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40336 }
40337 +}
40338
40339 #undef TPACPI_COMPARE_KEY
40340 #undef TPACPI_MAY_SEND_KEY
40341 -}
40342
40343 /*
40344 * Polling driver
40345 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
40346 index 769d265..a3a05ca 100644
40347 --- a/drivers/pnp/pnpbios/bioscalls.c
40348 +++ b/drivers/pnp/pnpbios/bioscalls.c
40349 @@ -58,7 +58,7 @@ do { \
40350 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
40351 } while(0)
40352
40353 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
40354 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
40355 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
40356
40357 /*
40358 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40359
40360 cpu = get_cpu();
40361 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
40362 +
40363 + pax_open_kernel();
40364 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
40365 + pax_close_kernel();
40366
40367 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
40368 spin_lock_irqsave(&pnp_bios_lock, flags);
40369 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40370 :"memory");
40371 spin_unlock_irqrestore(&pnp_bios_lock, flags);
40372
40373 + pax_open_kernel();
40374 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
40375 + pax_close_kernel();
40376 +
40377 put_cpu();
40378
40379 /* If we get here and this is set then the PnP BIOS faulted on us. */
40380 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
40381 return status;
40382 }
40383
40384 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
40385 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
40386 {
40387 int i;
40388
40389 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40390 pnp_bios_callpoint.offset = header->fields.pm16offset;
40391 pnp_bios_callpoint.segment = PNP_CS16;
40392
40393 + pax_open_kernel();
40394 +
40395 for_each_possible_cpu(i) {
40396 struct desc_struct *gdt = get_cpu_gdt_table(i);
40397 if (!gdt)
40398 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40399 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
40400 (unsigned long)__va(header->fields.pm16dseg));
40401 }
40402 +
40403 + pax_close_kernel();
40404 }
40405 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
40406 index 3e6db1c..1fbbdae 100644
40407 --- a/drivers/pnp/resource.c
40408 +++ b/drivers/pnp/resource.c
40409 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
40410 return 1;
40411
40412 /* check if the resource is valid */
40413 - if (*irq < 0 || *irq > 15)
40414 + if (*irq > 15)
40415 return 0;
40416
40417 /* check if the resource is reserved */
40418 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
40419 return 1;
40420
40421 /* check if the resource is valid */
40422 - if (*dma < 0 || *dma == 4 || *dma > 7)
40423 + if (*dma == 4 || *dma > 7)
40424 return 0;
40425
40426 /* check if the resource is reserved */
40427 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
40428 index 7df7c5f..bd48c47 100644
40429 --- a/drivers/power/pda_power.c
40430 +++ b/drivers/power/pda_power.c
40431 @@ -37,7 +37,11 @@ static int polling;
40432
40433 #ifdef CONFIG_USB_OTG_UTILS
40434 static struct usb_phy *transceiver;
40435 -static struct notifier_block otg_nb;
40436 +static int otg_handle_notification(struct notifier_block *nb,
40437 + unsigned long event, void *unused);
40438 +static struct notifier_block otg_nb = {
40439 + .notifier_call = otg_handle_notification
40440 +};
40441 #endif
40442
40443 static struct regulator *ac_draw;
40444 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
40445
40446 #ifdef CONFIG_USB_OTG_UTILS
40447 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
40448 - otg_nb.notifier_call = otg_handle_notification;
40449 ret = usb_register_notifier(transceiver, &otg_nb);
40450 if (ret) {
40451 dev_err(dev, "failure to register otg notifier\n");
40452 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
40453 index cc439fd..8fa30df 100644
40454 --- a/drivers/power/power_supply.h
40455 +++ b/drivers/power/power_supply.h
40456 @@ -16,12 +16,12 @@ struct power_supply;
40457
40458 #ifdef CONFIG_SYSFS
40459
40460 -extern void power_supply_init_attrs(struct device_type *dev_type);
40461 +extern void power_supply_init_attrs(void);
40462 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
40463
40464 #else
40465
40466 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
40467 +static inline void power_supply_init_attrs(void) {}
40468 #define power_supply_uevent NULL
40469
40470 #endif /* CONFIG_SYSFS */
40471 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
40472 index 8a7cfb3..493e0a2 100644
40473 --- a/drivers/power/power_supply_core.c
40474 +++ b/drivers/power/power_supply_core.c
40475 @@ -24,7 +24,10 @@
40476 struct class *power_supply_class;
40477 EXPORT_SYMBOL_GPL(power_supply_class);
40478
40479 -static struct device_type power_supply_dev_type;
40480 +extern const struct attribute_group *power_supply_attr_groups[];
40481 +static struct device_type power_supply_dev_type = {
40482 + .groups = power_supply_attr_groups,
40483 +};
40484
40485 static int __power_supply_changed_work(struct device *dev, void *data)
40486 {
40487 @@ -393,7 +396,6 @@ static int __init power_supply_class_init(void)
40488 return PTR_ERR(power_supply_class);
40489
40490 power_supply_class->dev_uevent = power_supply_uevent;
40491 - power_supply_init_attrs(&power_supply_dev_type);
40492
40493 return 0;
40494 }
40495 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
40496 index 40fa3b7..d9c2e0e 100644
40497 --- a/drivers/power/power_supply_sysfs.c
40498 +++ b/drivers/power/power_supply_sysfs.c
40499 @@ -229,17 +229,15 @@ static struct attribute_group power_supply_attr_group = {
40500 .is_visible = power_supply_attr_is_visible,
40501 };
40502
40503 -static const struct attribute_group *power_supply_attr_groups[] = {
40504 +const struct attribute_group *power_supply_attr_groups[] = {
40505 &power_supply_attr_group,
40506 NULL,
40507 };
40508
40509 -void power_supply_init_attrs(struct device_type *dev_type)
40510 +void power_supply_init_attrs(void)
40511 {
40512 int i;
40513
40514 - dev_type->groups = power_supply_attr_groups;
40515 -
40516 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
40517 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
40518 }
40519 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
40520 index 4d7c635..9860196 100644
40521 --- a/drivers/regulator/max8660.c
40522 +++ b/drivers/regulator/max8660.c
40523 @@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
40524 max8660->shadow_regs[MAX8660_OVER1] = 5;
40525 } else {
40526 /* Otherwise devices can be toggled via software */
40527 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
40528 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
40529 + pax_open_kernel();
40530 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
40531 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
40532 + pax_close_kernel();
40533 }
40534
40535 /*
40536 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
40537 index 9a8ea91..c483dd9 100644
40538 --- a/drivers/regulator/max8973-regulator.c
40539 +++ b/drivers/regulator/max8973-regulator.c
40540 @@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
40541 if (!pdata->enable_ext_control) {
40542 max->desc.enable_reg = MAX8973_VOUT;
40543 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
40544 - max8973_dcdc_ops.enable = regulator_enable_regmap;
40545 - max8973_dcdc_ops.disable = regulator_disable_regmap;
40546 - max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
40547 + pax_open_kernel();
40548 + *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
40549 + *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
40550 + *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
40551 + pax_close_kernel();
40552 }
40553
40554 max->enable_external_control = pdata->enable_ext_control;
40555 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
40556 index 0d84b1f..c2da6ac 100644
40557 --- a/drivers/regulator/mc13892-regulator.c
40558 +++ b/drivers/regulator/mc13892-regulator.c
40559 @@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
40560 }
40561 mc13xxx_unlock(mc13892);
40562
40563 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
40564 + pax_open_kernel();
40565 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
40566 = mc13892_vcam_set_mode;
40567 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
40568 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
40569 = mc13892_vcam_get_mode;
40570 + pax_close_kernel();
40571
40572 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
40573 ARRAY_SIZE(mc13892_regulators));
40574 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
40575 index 16630aa..6afc992 100644
40576 --- a/drivers/rtc/rtc-cmos.c
40577 +++ b/drivers/rtc/rtc-cmos.c
40578 @@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
40579 hpet_rtc_timer_init();
40580
40581 /* export at least the first block of NVRAM */
40582 - nvram.size = address_space - NVRAM_OFFSET;
40583 + pax_open_kernel();
40584 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
40585 + pax_close_kernel();
40586 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
40587 if (retval < 0) {
40588 dev_dbg(dev, "can't create nvram file? %d\n", retval);
40589 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
40590 index 9a86b4b..3a383dc 100644
40591 --- a/drivers/rtc/rtc-dev.c
40592 +++ b/drivers/rtc/rtc-dev.c
40593 @@ -14,6 +14,7 @@
40594 #include <linux/module.h>
40595 #include <linux/rtc.h>
40596 #include <linux/sched.h>
40597 +#include <linux/grsecurity.h>
40598 #include "rtc-core.h"
40599
40600 static dev_t rtc_devt;
40601 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
40602 if (copy_from_user(&tm, uarg, sizeof(tm)))
40603 return -EFAULT;
40604
40605 + gr_log_timechange();
40606 +
40607 return rtc_set_time(rtc, &tm);
40608
40609 case RTC_PIE_ON:
40610 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
40611 index e0d0ba4..3c65868 100644
40612 --- a/drivers/rtc/rtc-ds1307.c
40613 +++ b/drivers/rtc/rtc-ds1307.c
40614 @@ -106,7 +106,7 @@ struct ds1307 {
40615 u8 offset; /* register's offset */
40616 u8 regs[11];
40617 u16 nvram_offset;
40618 - struct bin_attribute *nvram;
40619 + bin_attribute_no_const *nvram;
40620 enum ds_type type;
40621 unsigned long flags;
40622 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
40623 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
40624 index 130f29a..6179d03 100644
40625 --- a/drivers/rtc/rtc-m48t59.c
40626 +++ b/drivers/rtc/rtc-m48t59.c
40627 @@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
40628 goto out;
40629 }
40630
40631 - m48t59_nvram_attr.size = pdata->offset;
40632 + pax_open_kernel();
40633 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
40634 + pax_close_kernel();
40635
40636 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
40637 if (ret) {
40638 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
40639 index e693af6..2e525b6 100644
40640 --- a/drivers/scsi/bfa/bfa_fcpim.h
40641 +++ b/drivers/scsi/bfa/bfa_fcpim.h
40642 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
40643
40644 struct bfa_itn_s {
40645 bfa_isr_func_t isr;
40646 -};
40647 +} __no_const;
40648
40649 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
40650 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
40651 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
40652 index 23a90e7..9cf04ee 100644
40653 --- a/drivers/scsi/bfa/bfa_ioc.h
40654 +++ b/drivers/scsi/bfa/bfa_ioc.h
40655 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
40656 bfa_ioc_disable_cbfn_t disable_cbfn;
40657 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
40658 bfa_ioc_reset_cbfn_t reset_cbfn;
40659 -};
40660 +} __no_const;
40661
40662 /*
40663 * IOC event notification mechanism.
40664 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
40665 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
40666 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
40667 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
40668 -};
40669 +} __no_const;
40670
40671 /*
40672 * Queue element to wait for room in request queue. FIFO order is
40673 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
40674 index 593085a..47aa999 100644
40675 --- a/drivers/scsi/hosts.c
40676 +++ b/drivers/scsi/hosts.c
40677 @@ -42,7 +42,7 @@
40678 #include "scsi_logging.h"
40679
40680
40681 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
40682 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
40683
40684
40685 static void scsi_host_cls_release(struct device *dev)
40686 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
40687 * subtract one because we increment first then return, but we need to
40688 * know what the next host number was before increment
40689 */
40690 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
40691 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
40692 shost->dma_channel = 0xff;
40693
40694 /* These three are default values which can be overridden */
40695 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
40696 index 4f33806..afd6f60 100644
40697 --- a/drivers/scsi/hpsa.c
40698 +++ b/drivers/scsi/hpsa.c
40699 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
40700 unsigned long flags;
40701
40702 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
40703 - return h->access.command_completed(h, q);
40704 + return h->access->command_completed(h, q);
40705
40706 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
40707 a = rq->head[rq->current_entry];
40708 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
40709 while (!list_empty(&h->reqQ)) {
40710 c = list_entry(h->reqQ.next, struct CommandList, list);
40711 /* can't do anything if fifo is full */
40712 - if ((h->access.fifo_full(h))) {
40713 + if ((h->access->fifo_full(h))) {
40714 dev_warn(&h->pdev->dev, "fifo full\n");
40715 break;
40716 }
40717 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
40718
40719 /* Tell the controller execute command */
40720 spin_unlock_irqrestore(&h->lock, flags);
40721 - h->access.submit_command(h, c);
40722 + h->access->submit_command(h, c);
40723 spin_lock_irqsave(&h->lock, flags);
40724 }
40725 spin_unlock_irqrestore(&h->lock, flags);
40726 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
40727
40728 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
40729 {
40730 - return h->access.command_completed(h, q);
40731 + return h->access->command_completed(h, q);
40732 }
40733
40734 static inline bool interrupt_pending(struct ctlr_info *h)
40735 {
40736 - return h->access.intr_pending(h);
40737 + return h->access->intr_pending(h);
40738 }
40739
40740 static inline long interrupt_not_for_us(struct ctlr_info *h)
40741 {
40742 - return (h->access.intr_pending(h) == 0) ||
40743 + return (h->access->intr_pending(h) == 0) ||
40744 (h->interrupts_enabled == 0);
40745 }
40746
40747 @@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
40748 if (prod_index < 0)
40749 return -ENODEV;
40750 h->product_name = products[prod_index].product_name;
40751 - h->access = *(products[prod_index].access);
40752 + h->access = products[prod_index].access;
40753
40754 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
40755 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
40756 @@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
40757
40758 assert_spin_locked(&lockup_detector_lock);
40759 remove_ctlr_from_lockup_detector_list(h);
40760 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40761 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40762 spin_lock_irqsave(&h->lock, flags);
40763 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
40764 spin_unlock_irqrestore(&h->lock, flags);
40765 @@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
40766 }
40767
40768 /* make sure the board interrupts are off */
40769 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40770 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40771
40772 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
40773 goto clean2;
40774 @@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
40775 * fake ones to scoop up any residual completions.
40776 */
40777 spin_lock_irqsave(&h->lock, flags);
40778 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40779 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40780 spin_unlock_irqrestore(&h->lock, flags);
40781 free_irqs(h);
40782 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
40783 @@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
40784 dev_info(&h->pdev->dev, "Board READY.\n");
40785 dev_info(&h->pdev->dev,
40786 "Waiting for stale completions to drain.\n");
40787 - h->access.set_intr_mask(h, HPSA_INTR_ON);
40788 + h->access->set_intr_mask(h, HPSA_INTR_ON);
40789 msleep(10000);
40790 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40791 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40792
40793 rc = controller_reset_failed(h->cfgtable);
40794 if (rc)
40795 @@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
40796 }
40797
40798 /* Turn the interrupts on so we can service requests */
40799 - h->access.set_intr_mask(h, HPSA_INTR_ON);
40800 + h->access->set_intr_mask(h, HPSA_INTR_ON);
40801
40802 hpsa_hba_inquiry(h);
40803 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
40804 @@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
40805 * To write all data in the battery backed cache to disks
40806 */
40807 hpsa_flush_cache(h);
40808 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
40809 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
40810 hpsa_free_irqs_and_disable_msix(h);
40811 }
40812
40813 @@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
40814 return;
40815 }
40816 /* Change the access methods to the performant access methods */
40817 - h->access = SA5_performant_access;
40818 + h->access = &SA5_performant_access;
40819 h->transMethod = CFGTBL_Trans_Performant;
40820 }
40821
40822 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
40823 index 9816479..c5d4e97 100644
40824 --- a/drivers/scsi/hpsa.h
40825 +++ b/drivers/scsi/hpsa.h
40826 @@ -79,7 +79,7 @@ struct ctlr_info {
40827 unsigned int msix_vector;
40828 unsigned int msi_vector;
40829 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
40830 - struct access_method access;
40831 + struct access_method *access;
40832
40833 /* queue and queue Info */
40834 struct list_head reqQ;
40835 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
40836 index c772d8d..35c362c 100644
40837 --- a/drivers/scsi/libfc/fc_exch.c
40838 +++ b/drivers/scsi/libfc/fc_exch.c
40839 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
40840 u16 pool_max_index;
40841
40842 struct {
40843 - atomic_t no_free_exch;
40844 - atomic_t no_free_exch_xid;
40845 - atomic_t xid_not_found;
40846 - atomic_t xid_busy;
40847 - atomic_t seq_not_found;
40848 - atomic_t non_bls_resp;
40849 + atomic_unchecked_t no_free_exch;
40850 + atomic_unchecked_t no_free_exch_xid;
40851 + atomic_unchecked_t xid_not_found;
40852 + atomic_unchecked_t xid_busy;
40853 + atomic_unchecked_t seq_not_found;
40854 + atomic_unchecked_t non_bls_resp;
40855 } stats;
40856 };
40857
40858 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
40859 /* allocate memory for exchange */
40860 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
40861 if (!ep) {
40862 - atomic_inc(&mp->stats.no_free_exch);
40863 + atomic_inc_unchecked(&mp->stats.no_free_exch);
40864 goto out;
40865 }
40866 memset(ep, 0, sizeof(*ep));
40867 @@ -786,7 +786,7 @@ out:
40868 return ep;
40869 err:
40870 spin_unlock_bh(&pool->lock);
40871 - atomic_inc(&mp->stats.no_free_exch_xid);
40872 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
40873 mempool_free(ep, mp->ep_pool);
40874 return NULL;
40875 }
40876 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40877 xid = ntohs(fh->fh_ox_id); /* we originated exch */
40878 ep = fc_exch_find(mp, xid);
40879 if (!ep) {
40880 - atomic_inc(&mp->stats.xid_not_found);
40881 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40882 reject = FC_RJT_OX_ID;
40883 goto out;
40884 }
40885 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40886 ep = fc_exch_find(mp, xid);
40887 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
40888 if (ep) {
40889 - atomic_inc(&mp->stats.xid_busy);
40890 + atomic_inc_unchecked(&mp->stats.xid_busy);
40891 reject = FC_RJT_RX_ID;
40892 goto rel;
40893 }
40894 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40895 }
40896 xid = ep->xid; /* get our XID */
40897 } else if (!ep) {
40898 - atomic_inc(&mp->stats.xid_not_found);
40899 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40900 reject = FC_RJT_RX_ID; /* XID not found */
40901 goto out;
40902 }
40903 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40904 } else {
40905 sp = &ep->seq;
40906 if (sp->id != fh->fh_seq_id) {
40907 - atomic_inc(&mp->stats.seq_not_found);
40908 + atomic_inc_unchecked(&mp->stats.seq_not_found);
40909 if (f_ctl & FC_FC_END_SEQ) {
40910 /*
40911 * Update sequence_id based on incoming last
40912 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40913
40914 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
40915 if (!ep) {
40916 - atomic_inc(&mp->stats.xid_not_found);
40917 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40918 goto out;
40919 }
40920 if (ep->esb_stat & ESB_ST_COMPLETE) {
40921 - atomic_inc(&mp->stats.xid_not_found);
40922 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40923 goto rel;
40924 }
40925 if (ep->rxid == FC_XID_UNKNOWN)
40926 ep->rxid = ntohs(fh->fh_rx_id);
40927 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
40928 - atomic_inc(&mp->stats.xid_not_found);
40929 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40930 goto rel;
40931 }
40932 if (ep->did != ntoh24(fh->fh_s_id) &&
40933 ep->did != FC_FID_FLOGI) {
40934 - atomic_inc(&mp->stats.xid_not_found);
40935 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40936 goto rel;
40937 }
40938 sof = fr_sof(fp);
40939 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40940 sp->ssb_stat |= SSB_ST_RESP;
40941 sp->id = fh->fh_seq_id;
40942 } else if (sp->id != fh->fh_seq_id) {
40943 - atomic_inc(&mp->stats.seq_not_found);
40944 + atomic_inc_unchecked(&mp->stats.seq_not_found);
40945 goto rel;
40946 }
40947
40948 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40949 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
40950
40951 if (!sp)
40952 - atomic_inc(&mp->stats.xid_not_found);
40953 + atomic_inc_unchecked(&mp->stats.xid_not_found);
40954 else
40955 - atomic_inc(&mp->stats.non_bls_resp);
40956 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
40957
40958 fc_frame_free(fp);
40959 }
40960 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
40961
40962 list_for_each_entry(ema, &lport->ema_list, ema_list) {
40963 mp = ema->mp;
40964 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
40965 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
40966 st->fc_no_free_exch_xid +=
40967 - atomic_read(&mp->stats.no_free_exch_xid);
40968 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
40969 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
40970 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
40971 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
40972 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
40973 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
40974 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
40975 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
40976 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
40977 }
40978 }
40979 EXPORT_SYMBOL(fc_exch_update_stats);
40980 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
40981 index bdb81cd..d3c7c2c 100644
40982 --- a/drivers/scsi/libsas/sas_ata.c
40983 +++ b/drivers/scsi/libsas/sas_ata.c
40984 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
40985 .postreset = ata_std_postreset,
40986 .error_handler = ata_std_error_handler,
40987 .post_internal_cmd = sas_ata_post_internal,
40988 - .qc_defer = ata_std_qc_defer,
40989 + .qc_defer = ata_std_qc_defer,
40990 .qc_prep = ata_noop_qc_prep,
40991 .qc_issue = sas_ata_qc_issue,
40992 .qc_fill_rtf = sas_ata_qc_fill_rtf,
40993 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
40994 index df4c13a..a51e90c 100644
40995 --- a/drivers/scsi/lpfc/lpfc.h
40996 +++ b/drivers/scsi/lpfc/lpfc.h
40997 @@ -424,7 +424,7 @@ struct lpfc_vport {
40998 struct dentry *debug_nodelist;
40999 struct dentry *vport_debugfs_root;
41000 struct lpfc_debugfs_trc *disc_trc;
41001 - atomic_t disc_trc_cnt;
41002 + atomic_unchecked_t disc_trc_cnt;
41003 #endif
41004 uint8_t stat_data_enabled;
41005 uint8_t stat_data_blocked;
41006 @@ -842,8 +842,8 @@ struct lpfc_hba {
41007 struct timer_list fabric_block_timer;
41008 unsigned long bit_flags;
41009 #define FABRIC_COMANDS_BLOCKED 0
41010 - atomic_t num_rsrc_err;
41011 - atomic_t num_cmd_success;
41012 + atomic_unchecked_t num_rsrc_err;
41013 + atomic_unchecked_t num_cmd_success;
41014 unsigned long last_rsrc_error_time;
41015 unsigned long last_ramp_down_time;
41016 unsigned long last_ramp_up_time;
41017 @@ -879,7 +879,7 @@ struct lpfc_hba {
41018
41019 struct dentry *debug_slow_ring_trc;
41020 struct lpfc_debugfs_trc *slow_ring_trc;
41021 - atomic_t slow_ring_trc_cnt;
41022 + atomic_unchecked_t slow_ring_trc_cnt;
41023 /* iDiag debugfs sub-directory */
41024 struct dentry *idiag_root;
41025 struct dentry *idiag_pci_cfg;
41026 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
41027 index f63f5ff..de29189 100644
41028 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
41029 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
41030 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
41031
41032 #include <linux/debugfs.h>
41033
41034 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41035 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41036 static unsigned long lpfc_debugfs_start_time = 0L;
41037
41038 /* iDiag */
41039 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
41040 lpfc_debugfs_enable = 0;
41041
41042 len = 0;
41043 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
41044 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
41045 (lpfc_debugfs_max_disc_trc - 1);
41046 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
41047 dtp = vport->disc_trc + i;
41048 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
41049 lpfc_debugfs_enable = 0;
41050
41051 len = 0;
41052 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
41053 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
41054 (lpfc_debugfs_max_slow_ring_trc - 1);
41055 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
41056 dtp = phba->slow_ring_trc + i;
41057 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
41058 !vport || !vport->disc_trc)
41059 return;
41060
41061 - index = atomic_inc_return(&vport->disc_trc_cnt) &
41062 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
41063 (lpfc_debugfs_max_disc_trc - 1);
41064 dtp = vport->disc_trc + index;
41065 dtp->fmt = fmt;
41066 dtp->data1 = data1;
41067 dtp->data2 = data2;
41068 dtp->data3 = data3;
41069 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41070 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41071 dtp->jif = jiffies;
41072 #endif
41073 return;
41074 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
41075 !phba || !phba->slow_ring_trc)
41076 return;
41077
41078 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
41079 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
41080 (lpfc_debugfs_max_slow_ring_trc - 1);
41081 dtp = phba->slow_ring_trc + index;
41082 dtp->fmt = fmt;
41083 dtp->data1 = data1;
41084 dtp->data2 = data2;
41085 dtp->data3 = data3;
41086 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41087 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41088 dtp->jif = jiffies;
41089 #endif
41090 return;
41091 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41092 "slow_ring buffer\n");
41093 goto debug_failed;
41094 }
41095 - atomic_set(&phba->slow_ring_trc_cnt, 0);
41096 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
41097 memset(phba->slow_ring_trc, 0,
41098 (sizeof(struct lpfc_debugfs_trc) *
41099 lpfc_debugfs_max_slow_ring_trc));
41100 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41101 "buffer\n");
41102 goto debug_failed;
41103 }
41104 - atomic_set(&vport->disc_trc_cnt, 0);
41105 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
41106
41107 snprintf(name, sizeof(name), "discovery_trace");
41108 vport->debug_disc_trc =
41109 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
41110 index 89ad558..76956c4 100644
41111 --- a/drivers/scsi/lpfc/lpfc_init.c
41112 +++ b/drivers/scsi/lpfc/lpfc_init.c
41113 @@ -10618,8 +10618,10 @@ lpfc_init(void)
41114 "misc_register returned with status %d", error);
41115
41116 if (lpfc_enable_npiv) {
41117 - lpfc_transport_functions.vport_create = lpfc_vport_create;
41118 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41119 + pax_open_kernel();
41120 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
41121 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41122 + pax_close_kernel();
41123 }
41124 lpfc_transport_template =
41125 fc_attach_transport(&lpfc_transport_functions);
41126 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
41127 index 60e5a17..ff7a793 100644
41128 --- a/drivers/scsi/lpfc/lpfc_scsi.c
41129 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
41130 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
41131 uint32_t evt_posted;
41132
41133 spin_lock_irqsave(&phba->hbalock, flags);
41134 - atomic_inc(&phba->num_rsrc_err);
41135 + atomic_inc_unchecked(&phba->num_rsrc_err);
41136 phba->last_rsrc_error_time = jiffies;
41137
41138 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
41139 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
41140 unsigned long flags;
41141 struct lpfc_hba *phba = vport->phba;
41142 uint32_t evt_posted;
41143 - atomic_inc(&phba->num_cmd_success);
41144 + atomic_inc_unchecked(&phba->num_cmd_success);
41145
41146 if (vport->cfg_lun_queue_depth <= queue_depth)
41147 return;
41148 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41149 unsigned long num_rsrc_err, num_cmd_success;
41150 int i;
41151
41152 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
41153 - num_cmd_success = atomic_read(&phba->num_cmd_success);
41154 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
41155 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
41156
41157 /*
41158 * The error and success command counters are global per
41159 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41160 }
41161 }
41162 lpfc_destroy_vport_work_array(phba, vports);
41163 - atomic_set(&phba->num_rsrc_err, 0);
41164 - atomic_set(&phba->num_cmd_success, 0);
41165 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
41166 + atomic_set_unchecked(&phba->num_cmd_success, 0);
41167 }
41168
41169 /**
41170 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
41171 }
41172 }
41173 lpfc_destroy_vport_work_array(phba, vports);
41174 - atomic_set(&phba->num_rsrc_err, 0);
41175 - atomic_set(&phba->num_cmd_success, 0);
41176 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
41177 + atomic_set_unchecked(&phba->num_cmd_success, 0);
41178 }
41179
41180 /**
41181 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
41182 index b46f5e9..c4c4ccb 100644
41183 --- a/drivers/scsi/pmcraid.c
41184 +++ b/drivers/scsi/pmcraid.c
41185 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
41186 res->scsi_dev = scsi_dev;
41187 scsi_dev->hostdata = res;
41188 res->change_detected = 0;
41189 - atomic_set(&res->read_failures, 0);
41190 - atomic_set(&res->write_failures, 0);
41191 + atomic_set_unchecked(&res->read_failures, 0);
41192 + atomic_set_unchecked(&res->write_failures, 0);
41193 rc = 0;
41194 }
41195 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
41196 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
41197
41198 /* If this was a SCSI read/write command keep count of errors */
41199 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
41200 - atomic_inc(&res->read_failures);
41201 + atomic_inc_unchecked(&res->read_failures);
41202 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
41203 - atomic_inc(&res->write_failures);
41204 + atomic_inc_unchecked(&res->write_failures);
41205
41206 if (!RES_IS_GSCSI(res->cfg_entry) &&
41207 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
41208 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
41209 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41210 * hrrq_id assigned here in queuecommand
41211 */
41212 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41213 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41214 pinstance->num_hrrq;
41215 cmd->cmd_done = pmcraid_io_done;
41216
41217 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
41218 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41219 * hrrq_id assigned here in queuecommand
41220 */
41221 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41222 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41223 pinstance->num_hrrq;
41224
41225 if (request_size) {
41226 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
41227
41228 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
41229 /* add resources only after host is added into system */
41230 - if (!atomic_read(&pinstance->expose_resources))
41231 + if (!atomic_read_unchecked(&pinstance->expose_resources))
41232 return;
41233
41234 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
41235 @@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
41236 init_waitqueue_head(&pinstance->reset_wait_q);
41237
41238 atomic_set(&pinstance->outstanding_cmds, 0);
41239 - atomic_set(&pinstance->last_message_id, 0);
41240 - atomic_set(&pinstance->expose_resources, 0);
41241 + atomic_set_unchecked(&pinstance->last_message_id, 0);
41242 + atomic_set_unchecked(&pinstance->expose_resources, 0);
41243
41244 INIT_LIST_HEAD(&pinstance->free_res_q);
41245 INIT_LIST_HEAD(&pinstance->used_res_q);
41246 @@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
41247 /* Schedule worker thread to handle CCN and take care of adding and
41248 * removing devices to OS
41249 */
41250 - atomic_set(&pinstance->expose_resources, 1);
41251 + atomic_set_unchecked(&pinstance->expose_resources, 1);
41252 schedule_work(&pinstance->worker_q);
41253 return rc;
41254
41255 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
41256 index e1d150f..6c6df44 100644
41257 --- a/drivers/scsi/pmcraid.h
41258 +++ b/drivers/scsi/pmcraid.h
41259 @@ -748,7 +748,7 @@ struct pmcraid_instance {
41260 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
41261
41262 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
41263 - atomic_t last_message_id;
41264 + atomic_unchecked_t last_message_id;
41265
41266 /* configuration table */
41267 struct pmcraid_config_table *cfg_table;
41268 @@ -777,7 +777,7 @@ struct pmcraid_instance {
41269 atomic_t outstanding_cmds;
41270
41271 /* should add/delete resources to mid-layer now ?*/
41272 - atomic_t expose_resources;
41273 + atomic_unchecked_t expose_resources;
41274
41275
41276
41277 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
41278 struct pmcraid_config_table_entry_ext cfg_entry_ext;
41279 };
41280 struct scsi_device *scsi_dev; /* Link scsi_device structure */
41281 - atomic_t read_failures; /* count of failed READ commands */
41282 - atomic_t write_failures; /* count of failed WRITE commands */
41283 + atomic_unchecked_t read_failures; /* count of failed READ commands */
41284 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
41285
41286 /* To indicate add/delete/modify during CCN */
41287 u8 change_detected;
41288 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
41289 index 83d7984..a27d947 100644
41290 --- a/drivers/scsi/qla2xxx/qla_attr.c
41291 +++ b/drivers/scsi/qla2xxx/qla_attr.c
41292 @@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
41293 return 0;
41294 }
41295
41296 -struct fc_function_template qla2xxx_transport_functions = {
41297 +fc_function_template_no_const qla2xxx_transport_functions = {
41298
41299 .show_host_node_name = 1,
41300 .show_host_port_name = 1,
41301 @@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
41302 .bsg_timeout = qla24xx_bsg_timeout,
41303 };
41304
41305 -struct fc_function_template qla2xxx_transport_vport_functions = {
41306 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
41307
41308 .show_host_node_name = 1,
41309 .show_host_port_name = 1,
41310 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
41311 index 2411d1a..4673766 100644
41312 --- a/drivers/scsi/qla2xxx/qla_gbl.h
41313 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
41314 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
41315 struct device_attribute;
41316 extern struct device_attribute *qla2x00_host_attrs[];
41317 struct fc_function_template;
41318 -extern struct fc_function_template qla2xxx_transport_functions;
41319 -extern struct fc_function_template qla2xxx_transport_vport_functions;
41320 +extern fc_function_template_no_const qla2xxx_transport_functions;
41321 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
41322 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
41323 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
41324 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
41325 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
41326 index 10d23f8..a7d5d4c 100644
41327 --- a/drivers/scsi/qla2xxx/qla_os.c
41328 +++ b/drivers/scsi/qla2xxx/qla_os.c
41329 @@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
41330 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
41331 /* Ok, a 64bit DMA mask is applicable. */
41332 ha->flags.enable_64bit_addressing = 1;
41333 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41334 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41335 + pax_open_kernel();
41336 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41337 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41338 + pax_close_kernel();
41339 return;
41340 }
41341 }
41342 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
41343 index 329d553..f20d31d 100644
41344 --- a/drivers/scsi/qla4xxx/ql4_def.h
41345 +++ b/drivers/scsi/qla4xxx/ql4_def.h
41346 @@ -273,7 +273,7 @@ struct ddb_entry {
41347 * (4000 only) */
41348 atomic_t relogin_timer; /* Max Time to wait for
41349 * relogin to complete */
41350 - atomic_t relogin_retry_count; /* Num of times relogin has been
41351 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
41352 * retried */
41353 uint32_t default_time2wait; /* Default Min time between
41354 * relogins (+aens) */
41355 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
41356 index 4cec123..7c1329f 100644
41357 --- a/drivers/scsi/qla4xxx/ql4_os.c
41358 +++ b/drivers/scsi/qla4xxx/ql4_os.c
41359 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
41360 */
41361 if (!iscsi_is_session_online(cls_sess)) {
41362 /* Reset retry relogin timer */
41363 - atomic_inc(&ddb_entry->relogin_retry_count);
41364 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
41365 DEBUG2(ql4_printk(KERN_INFO, ha,
41366 "%s: index[%d] relogin timed out-retrying"
41367 " relogin (%d), retry (%d)\n", __func__,
41368 ddb_entry->fw_ddb_index,
41369 - atomic_read(&ddb_entry->relogin_retry_count),
41370 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
41371 ddb_entry->default_time2wait + 4));
41372 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
41373 atomic_set(&ddb_entry->retry_relogin_timer,
41374 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
41375
41376 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
41377 atomic_set(&ddb_entry->relogin_timer, 0);
41378 - atomic_set(&ddb_entry->relogin_retry_count, 0);
41379 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41380 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
41381 ddb_entry->default_relogin_timeout =
41382 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
41383 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
41384 index 2c0d0ec..4e8681a 100644
41385 --- a/drivers/scsi/scsi.c
41386 +++ b/drivers/scsi/scsi.c
41387 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
41388 unsigned long timeout;
41389 int rtn = 0;
41390
41391 - atomic_inc(&cmd->device->iorequest_cnt);
41392 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41393
41394 /* check if the device is still usable */
41395 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
41396 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
41397 index f1bf5af..f67e943 100644
41398 --- a/drivers/scsi/scsi_lib.c
41399 +++ b/drivers/scsi/scsi_lib.c
41400 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
41401 shost = sdev->host;
41402 scsi_init_cmd_errh(cmd);
41403 cmd->result = DID_NO_CONNECT << 16;
41404 - atomic_inc(&cmd->device->iorequest_cnt);
41405 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41406
41407 /*
41408 * SCSI request completion path will do scsi_device_unbusy(),
41409 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
41410
41411 INIT_LIST_HEAD(&cmd->eh_entry);
41412
41413 - atomic_inc(&cmd->device->iodone_cnt);
41414 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
41415 if (cmd->result)
41416 - atomic_inc(&cmd->device->ioerr_cnt);
41417 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
41418
41419 disposition = scsi_decide_disposition(cmd);
41420 if (disposition != SUCCESS &&
41421 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
41422 index 931a7d9..0c2a754 100644
41423 --- a/drivers/scsi/scsi_sysfs.c
41424 +++ b/drivers/scsi/scsi_sysfs.c
41425 @@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
41426 char *buf) \
41427 { \
41428 struct scsi_device *sdev = to_scsi_device(dev); \
41429 - unsigned long long count = atomic_read(&sdev->field); \
41430 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
41431 return snprintf(buf, 20, "0x%llx\n", count); \
41432 } \
41433 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
41434 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
41435 index 84a1fdf..693b0d6 100644
41436 --- a/drivers/scsi/scsi_tgt_lib.c
41437 +++ b/drivers/scsi/scsi_tgt_lib.c
41438 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
41439 int err;
41440
41441 dprintk("%lx %u\n", uaddr, len);
41442 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
41443 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
41444 if (err) {
41445 /*
41446 * TODO: need to fixup sg_tablesize, max_segment_size,
41447 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
41448 index e894ca7..de9d7660 100644
41449 --- a/drivers/scsi/scsi_transport_fc.c
41450 +++ b/drivers/scsi/scsi_transport_fc.c
41451 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
41452 * Netlink Infrastructure
41453 */
41454
41455 -static atomic_t fc_event_seq;
41456 +static atomic_unchecked_t fc_event_seq;
41457
41458 /**
41459 * fc_get_event_number - Obtain the next sequential FC event number
41460 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
41461 u32
41462 fc_get_event_number(void)
41463 {
41464 - return atomic_add_return(1, &fc_event_seq);
41465 + return atomic_add_return_unchecked(1, &fc_event_seq);
41466 }
41467 EXPORT_SYMBOL(fc_get_event_number);
41468
41469 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
41470 {
41471 int error;
41472
41473 - atomic_set(&fc_event_seq, 0);
41474 + atomic_set_unchecked(&fc_event_seq, 0);
41475
41476 error = transport_class_register(&fc_host_class);
41477 if (error)
41478 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
41479 char *cp;
41480
41481 *val = simple_strtoul(buf, &cp, 0);
41482 - if ((*cp && (*cp != '\n')) || (*val < 0))
41483 + if (*cp && (*cp != '\n'))
41484 return -EINVAL;
41485 /*
41486 * Check for overflow; dev_loss_tmo is u32
41487 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
41488 index 31969f2..2b348f0 100644
41489 --- a/drivers/scsi/scsi_transport_iscsi.c
41490 +++ b/drivers/scsi/scsi_transport_iscsi.c
41491 @@ -79,7 +79,7 @@ struct iscsi_internal {
41492 struct transport_container session_cont;
41493 };
41494
41495 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
41496 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
41497 static struct workqueue_struct *iscsi_eh_timer_workq;
41498
41499 static DEFINE_IDA(iscsi_sess_ida);
41500 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
41501 int err;
41502
41503 ihost = shost->shost_data;
41504 - session->sid = atomic_add_return(1, &iscsi_session_nr);
41505 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
41506
41507 if (target_id == ISCSI_MAX_TARGET) {
41508 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
41509 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
41510 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
41511 ISCSI_TRANSPORT_VERSION);
41512
41513 - atomic_set(&iscsi_session_nr, 0);
41514 + atomic_set_unchecked(&iscsi_session_nr, 0);
41515
41516 err = class_register(&iscsi_transport_class);
41517 if (err)
41518 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
41519 index f379c7f..e8fc69c 100644
41520 --- a/drivers/scsi/scsi_transport_srp.c
41521 +++ b/drivers/scsi/scsi_transport_srp.c
41522 @@ -33,7 +33,7 @@
41523 #include "scsi_transport_srp_internal.h"
41524
41525 struct srp_host_attrs {
41526 - atomic_t next_port_id;
41527 + atomic_unchecked_t next_port_id;
41528 };
41529 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
41530
41531 @@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
41532 struct Scsi_Host *shost = dev_to_shost(dev);
41533 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
41534
41535 - atomic_set(&srp_host->next_port_id, 0);
41536 + atomic_set_unchecked(&srp_host->next_port_id, 0);
41537 return 0;
41538 }
41539
41540 @@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
41541 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
41542 rport->roles = ids->roles;
41543
41544 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
41545 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
41546 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
41547
41548 transport_setup_device(&rport->dev);
41549 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
41550 index 7992635..609faf8 100644
41551 --- a/drivers/scsi/sd.c
41552 +++ b/drivers/scsi/sd.c
41553 @@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
41554 sdkp->disk = gd;
41555 sdkp->index = index;
41556 atomic_set(&sdkp->openers, 0);
41557 - atomic_set(&sdkp->device->ioerr_cnt, 0);
41558 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
41559
41560 if (!sdp->request_queue->rq_timeout) {
41561 if (sdp->type != TYPE_MOD)
41562 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
41563 index be2c9a6..275525c 100644
41564 --- a/drivers/scsi/sg.c
41565 +++ b/drivers/scsi/sg.c
41566 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
41567 sdp->disk->disk_name,
41568 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
41569 NULL,
41570 - (char *)arg);
41571 + (char __user *)arg);
41572 case BLKTRACESTART:
41573 return blk_trace_startstop(sdp->device->request_queue, 1);
41574 case BLKTRACESTOP:
41575 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
41576 index 19ee901..6e8c2ef 100644
41577 --- a/drivers/spi/spi.c
41578 +++ b/drivers/spi/spi.c
41579 @@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
41580 EXPORT_SYMBOL_GPL(spi_bus_unlock);
41581
41582 /* portable code must never pass more than 32 bytes */
41583 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
41584 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
41585
41586 static u8 *buf;
41587
41588 diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
41589 index c7a5f97..71ecd35 100644
41590 --- a/drivers/staging/iio/iio_hwmon.c
41591 +++ b/drivers/staging/iio/iio_hwmon.c
41592 @@ -72,7 +72,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st)
41593 static int iio_hwmon_probe(struct platform_device *pdev)
41594 {
41595 struct iio_hwmon_state *st;
41596 - struct sensor_device_attribute *a;
41597 + sensor_device_attribute_no_const *a;
41598 int ret, i;
41599 int in_i = 1, temp_i = 1, curr_i = 1;
41600 enum iio_chan_type type;
41601 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
41602 index 34afc16..ffe44dd 100644
41603 --- a/drivers/staging/octeon/ethernet-rx.c
41604 +++ b/drivers/staging/octeon/ethernet-rx.c
41605 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
41606 /* Increment RX stats for virtual ports */
41607 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
41608 #ifdef CONFIG_64BIT
41609 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
41610 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
41611 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
41612 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
41613 #else
41614 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
41615 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
41616 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
41617 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
41618 #endif
41619 }
41620 netif_receive_skb(skb);
41621 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
41622 dev->name);
41623 */
41624 #ifdef CONFIG_64BIT
41625 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
41626 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
41627 #else
41628 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
41629 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
41630 #endif
41631 dev_kfree_skb_irq(skb);
41632 }
41633 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
41634 index ef32dc1..a159d68 100644
41635 --- a/drivers/staging/octeon/ethernet.c
41636 +++ b/drivers/staging/octeon/ethernet.c
41637 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
41638 * since the RX tasklet also increments it.
41639 */
41640 #ifdef CONFIG_64BIT
41641 - atomic64_add(rx_status.dropped_packets,
41642 - (atomic64_t *)&priv->stats.rx_dropped);
41643 + atomic64_add_unchecked(rx_status.dropped_packets,
41644 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
41645 #else
41646 - atomic_add(rx_status.dropped_packets,
41647 - (atomic_t *)&priv->stats.rx_dropped);
41648 + atomic_add_unchecked(rx_status.dropped_packets,
41649 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
41650 #endif
41651 }
41652
41653 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
41654 index a2b7e03..aaf3630 100644
41655 --- a/drivers/staging/ramster/tmem.c
41656 +++ b/drivers/staging/ramster/tmem.c
41657 @@ -50,25 +50,25 @@
41658 * A tmem host implementation must use this function to register callbacks
41659 * for memory allocation.
41660 */
41661 -static struct tmem_hostops tmem_hostops;
41662 +static struct tmem_hostops *tmem_hostops;
41663
41664 static void tmem_objnode_tree_init(void);
41665
41666 void tmem_register_hostops(struct tmem_hostops *m)
41667 {
41668 tmem_objnode_tree_init();
41669 - tmem_hostops = *m;
41670 + tmem_hostops = m;
41671 }
41672
41673 /*
41674 * A tmem host implementation must use this function to register
41675 * callbacks for a page-accessible memory (PAM) implementation.
41676 */
41677 -static struct tmem_pamops tmem_pamops;
41678 +static struct tmem_pamops *tmem_pamops;
41679
41680 void tmem_register_pamops(struct tmem_pamops *m)
41681 {
41682 - tmem_pamops = *m;
41683 + tmem_pamops = m;
41684 }
41685
41686 /*
41687 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
41688 obj->pampd_count = 0;
41689 #ifdef CONFIG_RAMSTER
41690 if (tmem_pamops.new_obj != NULL)
41691 - (*tmem_pamops.new_obj)(obj);
41692 + (tmem_pamops->new_obj)(obj);
41693 #endif
41694 SET_SENTINEL(obj, OBJ);
41695
41696 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
41697 rbnode = rb_next(rbnode);
41698 tmem_pampd_destroy_all_in_obj(obj, true);
41699 tmem_obj_free(obj, hb);
41700 - (*tmem_hostops.obj_free)(obj, pool);
41701 + (tmem_hostops->obj_free)(obj, pool);
41702 }
41703 spin_unlock(&hb->lock);
41704 }
41705 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
41706 ASSERT_SENTINEL(obj, OBJ);
41707 BUG_ON(obj->pool == NULL);
41708 ASSERT_SENTINEL(obj->pool, POOL);
41709 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
41710 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
41711 if (unlikely(objnode == NULL))
41712 goto out;
41713 objnode->obj = obj;
41714 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
41715 ASSERT_SENTINEL(pool, POOL);
41716 objnode->obj->objnode_count--;
41717 objnode->obj = NULL;
41718 - (*tmem_hostops.objnode_free)(objnode, pool);
41719 + (tmem_hostops->objnode_free)(objnode, pool);
41720 }
41721
41722 /*
41723 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
41724 void *old_pampd = *(void **)slot;
41725 *(void **)slot = new_pampd;
41726 if (!no_free)
41727 - (*tmem_pamops.free)(old_pampd, obj->pool,
41728 + (tmem_pamops->free)(old_pampd, obj->pool,
41729 NULL, 0, false);
41730 ret = new_pampd;
41731 }
41732 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
41733 if (objnode->slots[i]) {
41734 if (ht == 1) {
41735 obj->pampd_count--;
41736 - (*tmem_pamops.free)(objnode->slots[i],
41737 + (tmem_pamops->free)(objnode->slots[i],
41738 obj->pool, NULL, 0, true);
41739 objnode->slots[i] = NULL;
41740 continue;
41741 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
41742 return;
41743 if (obj->objnode_tree_height == 0) {
41744 obj->pampd_count--;
41745 - (*tmem_pamops.free)(obj->objnode_tree_root,
41746 + (tmem_pamops->free)(obj->objnode_tree_root,
41747 obj->pool, NULL, 0, true);
41748 } else {
41749 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
41750 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
41751 obj->objnode_tree_root = NULL;
41752 #ifdef CONFIG_RAMSTER
41753 if (tmem_pamops.free_obj != NULL)
41754 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
41755 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
41756 #endif
41757 }
41758
41759 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41760 /* if found, is a dup put, flush the old one */
41761 pampd_del = tmem_pampd_delete_from_obj(obj, index);
41762 BUG_ON(pampd_del != pampd);
41763 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
41764 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
41765 if (obj->pampd_count == 0) {
41766 objnew = obj;
41767 objfound = NULL;
41768 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41769 pampd = NULL;
41770 }
41771 } else {
41772 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
41773 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
41774 if (unlikely(obj == NULL)) {
41775 ret = -ENOMEM;
41776 goto out;
41777 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41778 if (unlikely(ret == -ENOMEM))
41779 /* may have partially built objnode tree ("stump") */
41780 goto delete_and_free;
41781 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
41782 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
41783 goto out;
41784
41785 delete_and_free:
41786 (void)tmem_pampd_delete_from_obj(obj, index);
41787 if (pampd)
41788 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
41789 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
41790 if (objnew) {
41791 tmem_obj_free(objnew, hb);
41792 - (*tmem_hostops.obj_free)(objnew, pool);
41793 + (tmem_hostops->obj_free)(objnew, pool);
41794 }
41795 out:
41796 spin_unlock(&hb->lock);
41797 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
41798 if (pampd != NULL) {
41799 BUG_ON(obj == NULL);
41800 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
41801 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
41802 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
41803 } else if (delete) {
41804 BUG_ON(obj == NULL);
41805 (void)tmem_pampd_delete_from_obj(obj, index);
41806 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
41807 int ret = 0;
41808
41809 if (!is_ephemeral(pool))
41810 - new_pampd = (*tmem_pamops.repatriate_preload)(
41811 + new_pampd = (tmem_pamops->repatriate_preload)(
41812 old_pampd, pool, oidp, index, &intransit);
41813 if (intransit)
41814 ret = -EAGAIN;
41815 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
41816 /* must release the hb->lock else repatriate can't sleep */
41817 spin_unlock(&hb->lock);
41818 if (!intransit)
41819 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
41820 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
41821 oidp, index, free, data);
41822 if (ret == -EAGAIN) {
41823 /* rare I think, but should cond_resched()??? */
41824 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
41825 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
41826 /* if we bug here, pamops wasn't properly set up for ramster */
41827 BUG_ON(tmem_pamops.replace_in_obj == NULL);
41828 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
41829 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
41830 out:
41831 spin_unlock(&hb->lock);
41832 return ret;
41833 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41834 if (free) {
41835 if (obj->pampd_count == 0) {
41836 tmem_obj_free(obj, hb);
41837 - (*tmem_hostops.obj_free)(obj, pool);
41838 + (tmem_hostops->obj_free)(obj, pool);
41839 obj = NULL;
41840 }
41841 }
41842 if (free)
41843 - ret = (*tmem_pamops.get_data_and_free)(
41844 + ret = (tmem_pamops->get_data_and_free)(
41845 data, sizep, raw, pampd, pool, oidp, index);
41846 else
41847 - ret = (*tmem_pamops.get_data)(
41848 + ret = (tmem_pamops->get_data)(
41849 data, sizep, raw, pampd, pool, oidp, index);
41850 if (ret < 0)
41851 goto out;
41852 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
41853 pampd = tmem_pampd_delete_from_obj(obj, index);
41854 if (pampd == NULL)
41855 goto out;
41856 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
41857 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
41858 if (obj->pampd_count == 0) {
41859 tmem_obj_free(obj, hb);
41860 - (*tmem_hostops.obj_free)(obj, pool);
41861 + (tmem_hostops->obj_free)(obj, pool);
41862 }
41863 ret = 0;
41864
41865 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
41866 goto out;
41867 tmem_pampd_destroy_all_in_obj(obj, false);
41868 tmem_obj_free(obj, hb);
41869 - (*tmem_hostops.obj_free)(obj, pool);
41870 + (tmem_hostops->obj_free)(obj, pool);
41871 ret = 0;
41872
41873 out:
41874 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
41875 index dc23395..cf7e9b1 100644
41876 --- a/drivers/staging/rtl8712/rtl871x_io.h
41877 +++ b/drivers/staging/rtl8712/rtl871x_io.h
41878 @@ -108,7 +108,7 @@ struct _io_ops {
41879 u8 *pmem);
41880 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
41881 u8 *pmem);
41882 -};
41883 +} __no_const;
41884
41885 struct io_req {
41886 struct list_head list;
41887 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
41888 index 1f5088b..0e59820 100644
41889 --- a/drivers/staging/sbe-2t3e3/netdev.c
41890 +++ b/drivers/staging/sbe-2t3e3/netdev.c
41891 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41892 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
41893
41894 if (rlen)
41895 - if (copy_to_user(data, &resp, rlen))
41896 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
41897 return -EFAULT;
41898
41899 return 0;
41900 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
41901 index 5dddc4d..34fcb2f 100644
41902 --- a/drivers/staging/usbip/vhci.h
41903 +++ b/drivers/staging/usbip/vhci.h
41904 @@ -83,7 +83,7 @@ struct vhci_hcd {
41905 unsigned resuming:1;
41906 unsigned long re_timeout;
41907
41908 - atomic_t seqnum;
41909 + atomic_unchecked_t seqnum;
41910
41911 /*
41912 * NOTE:
41913 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
41914 index c3aa219..bf8b3de 100644
41915 --- a/drivers/staging/usbip/vhci_hcd.c
41916 +++ b/drivers/staging/usbip/vhci_hcd.c
41917 @@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
41918 return;
41919 }
41920
41921 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
41922 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
41923 if (priv->seqnum == 0xffff)
41924 dev_info(&urb->dev->dev, "seqnum max\n");
41925
41926 @@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
41927 return -ENOMEM;
41928 }
41929
41930 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
41931 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
41932 if (unlink->seqnum == 0xffff)
41933 pr_info("seqnum max\n");
41934
41935 @@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
41936 vdev->rhport = rhport;
41937 }
41938
41939 - atomic_set(&vhci->seqnum, 0);
41940 + atomic_set_unchecked(&vhci->seqnum, 0);
41941 spin_lock_init(&vhci->lock);
41942
41943 hcd->power_budget = 0; /* no limit */
41944 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
41945 index ba5f1c0..11d8122 100644
41946 --- a/drivers/staging/usbip/vhci_rx.c
41947 +++ b/drivers/staging/usbip/vhci_rx.c
41948 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
41949 if (!urb) {
41950 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
41951 pr_info("max seqnum %d\n",
41952 - atomic_read(&the_controller->seqnum));
41953 + atomic_read_unchecked(&the_controller->seqnum));
41954 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
41955 return;
41956 }
41957 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
41958 index 5f13890..36a044b 100644
41959 --- a/drivers/staging/vt6655/hostap.c
41960 +++ b/drivers/staging/vt6655/hostap.c
41961 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
41962 *
41963 */
41964
41965 +static net_device_ops_no_const apdev_netdev_ops;
41966 +
41967 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
41968 {
41969 PSDevice apdev_priv;
41970 struct net_device *dev = pDevice->dev;
41971 int ret;
41972 - const struct net_device_ops apdev_netdev_ops = {
41973 - .ndo_start_xmit = pDevice->tx_80211,
41974 - };
41975
41976 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
41977
41978 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
41979 *apdev_priv = *pDevice;
41980 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
41981
41982 + /* only half broken now */
41983 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
41984 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
41985
41986 pDevice->apdev->type = ARPHRD_IEEE80211;
41987 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
41988 index 26a7d0e..897b083 100644
41989 --- a/drivers/staging/vt6656/hostap.c
41990 +++ b/drivers/staging/vt6656/hostap.c
41991 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
41992 *
41993 */
41994
41995 +static net_device_ops_no_const apdev_netdev_ops;
41996 +
41997 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
41998 {
41999 PSDevice apdev_priv;
42000 struct net_device *dev = pDevice->dev;
42001 int ret;
42002 - const struct net_device_ops apdev_netdev_ops = {
42003 - .ndo_start_xmit = pDevice->tx_80211,
42004 - };
42005
42006 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42007
42008 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42009 *apdev_priv = *pDevice;
42010 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42011
42012 + /* only half broken now */
42013 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42014 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42015
42016 pDevice->apdev->type = ARPHRD_IEEE80211;
42017 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
42018 index 56c8e60..1920c63 100644
42019 --- a/drivers/staging/zcache/tmem.c
42020 +++ b/drivers/staging/zcache/tmem.c
42021 @@ -39,7 +39,7 @@
42022 * A tmem host implementation must use this function to register callbacks
42023 * for memory allocation.
42024 */
42025 -static struct tmem_hostops tmem_hostops;
42026 +static tmem_hostops_no_const tmem_hostops;
42027
42028 static void tmem_objnode_tree_init(void);
42029
42030 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
42031 * A tmem host implementation must use this function to register
42032 * callbacks for a page-accessible memory (PAM) implementation
42033 */
42034 -static struct tmem_pamops tmem_pamops;
42035 +static tmem_pamops_no_const tmem_pamops;
42036
42037 void tmem_register_pamops(struct tmem_pamops *m)
42038 {
42039 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
42040 index 0d4aa82..f7832d4 100644
42041 --- a/drivers/staging/zcache/tmem.h
42042 +++ b/drivers/staging/zcache/tmem.h
42043 @@ -180,6 +180,7 @@ struct tmem_pamops {
42044 void (*new_obj)(struct tmem_obj *);
42045 int (*replace_in_obj)(void *, struct tmem_obj *);
42046 };
42047 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
42048 extern void tmem_register_pamops(struct tmem_pamops *m);
42049
42050 /* memory allocation methods provided by the host implementation */
42051 @@ -189,6 +190,7 @@ struct tmem_hostops {
42052 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
42053 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
42054 };
42055 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
42056 extern void tmem_register_hostops(struct tmem_hostops *m);
42057
42058 /* core tmem accessor functions */
42059 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
42060 index 96f4981..4daaa7e 100644
42061 --- a/drivers/target/target_core_device.c
42062 +++ b/drivers/target/target_core_device.c
42063 @@ -1370,7 +1370,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
42064 spin_lock_init(&dev->se_port_lock);
42065 spin_lock_init(&dev->se_tmr_lock);
42066 spin_lock_init(&dev->qf_cmd_lock);
42067 - atomic_set(&dev->dev_ordered_id, 0);
42068 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
42069 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
42070 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
42071 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
42072 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
42073 index bd587b7..173daf3 100644
42074 --- a/drivers/target/target_core_transport.c
42075 +++ b/drivers/target/target_core_transport.c
42076 @@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
42077 * Used to determine when ORDERED commands should go from
42078 * Dormant to Active status.
42079 */
42080 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
42081 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
42082 smp_mb__after_atomic_inc();
42083 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
42084 cmd->se_ordered_id, cmd->sam_task_attr,
42085 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
42086 index b09c8d1f..c4225c0 100644
42087 --- a/drivers/tty/cyclades.c
42088 +++ b/drivers/tty/cyclades.c
42089 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
42090 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
42091 info->port.count);
42092 #endif
42093 - info->port.count++;
42094 + atomic_inc(&info->port.count);
42095 #ifdef CY_DEBUG_COUNT
42096 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
42097 - current->pid, info->port.count);
42098 + current->pid, atomic_read(&info->port.count));
42099 #endif
42100
42101 /*
42102 @@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
42103 for (j = 0; j < cy_card[i].nports; j++) {
42104 info = &cy_card[i].ports[j];
42105
42106 - if (info->port.count) {
42107 + if (atomic_read(&info->port.count)) {
42108 /* XXX is the ldisc num worth this? */
42109 struct tty_struct *tty;
42110 struct tty_ldisc *ld;
42111 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
42112 index 13ee53b..418d164 100644
42113 --- a/drivers/tty/hvc/hvc_console.c
42114 +++ b/drivers/tty/hvc/hvc_console.c
42115 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
42116
42117 spin_lock_irqsave(&hp->port.lock, flags);
42118 /* Check and then increment for fast path open. */
42119 - if (hp->port.count++ > 0) {
42120 + if (atomic_inc_return(&hp->port.count) > 1) {
42121 spin_unlock_irqrestore(&hp->port.lock, flags);
42122 hvc_kick();
42123 return 0;
42124 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42125
42126 spin_lock_irqsave(&hp->port.lock, flags);
42127
42128 - if (--hp->port.count == 0) {
42129 + if (atomic_dec_return(&hp->port.count) == 0) {
42130 spin_unlock_irqrestore(&hp->port.lock, flags);
42131 /* We are done with the tty pointer now. */
42132 tty_port_tty_set(&hp->port, NULL);
42133 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42134 */
42135 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
42136 } else {
42137 - if (hp->port.count < 0)
42138 + if (atomic_read(&hp->port.count) < 0)
42139 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
42140 - hp->vtermno, hp->port.count);
42141 + hp->vtermno, atomic_read(&hp->port.count));
42142 spin_unlock_irqrestore(&hp->port.lock, flags);
42143 }
42144 }
42145 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
42146 * open->hangup case this can be called after the final close so prevent
42147 * that from happening for now.
42148 */
42149 - if (hp->port.count <= 0) {
42150 + if (atomic_read(&hp->port.count) <= 0) {
42151 spin_unlock_irqrestore(&hp->port.lock, flags);
42152 return;
42153 }
42154
42155 - hp->port.count = 0;
42156 + atomic_set(&hp->port.count, 0);
42157 spin_unlock_irqrestore(&hp->port.lock, flags);
42158 tty_port_tty_set(&hp->port, NULL);
42159
42160 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
42161 return -EPIPE;
42162
42163 /* FIXME what's this (unprotected) check for? */
42164 - if (hp->port.count <= 0)
42165 + if (atomic_read(&hp->port.count) <= 0)
42166 return -EIO;
42167
42168 spin_lock_irqsave(&hp->lock, flags);
42169 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
42170 index 8776357..b2d4afd 100644
42171 --- a/drivers/tty/hvc/hvcs.c
42172 +++ b/drivers/tty/hvc/hvcs.c
42173 @@ -83,6 +83,7 @@
42174 #include <asm/hvcserver.h>
42175 #include <asm/uaccess.h>
42176 #include <asm/vio.h>
42177 +#include <asm/local.h>
42178
42179 /*
42180 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
42181 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
42182
42183 spin_lock_irqsave(&hvcsd->lock, flags);
42184
42185 - if (hvcsd->port.count > 0) {
42186 + if (atomic_read(&hvcsd->port.count) > 0) {
42187 spin_unlock_irqrestore(&hvcsd->lock, flags);
42188 printk(KERN_INFO "HVCS: vterm state unchanged. "
42189 "The hvcs device node is still in use.\n");
42190 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
42191 }
42192 }
42193
42194 - hvcsd->port.count = 0;
42195 + atomic_set(&hvcsd->port.count, 0);
42196 hvcsd->port.tty = tty;
42197 tty->driver_data = hvcsd;
42198
42199 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
42200 unsigned long flags;
42201
42202 spin_lock_irqsave(&hvcsd->lock, flags);
42203 - hvcsd->port.count++;
42204 + atomic_inc(&hvcsd->port.count);
42205 hvcsd->todo_mask |= HVCS_SCHED_READ;
42206 spin_unlock_irqrestore(&hvcsd->lock, flags);
42207
42208 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42209 hvcsd = tty->driver_data;
42210
42211 spin_lock_irqsave(&hvcsd->lock, flags);
42212 - if (--hvcsd->port.count == 0) {
42213 + if (atomic_dec_and_test(&hvcsd->port.count)) {
42214
42215 vio_disable_interrupts(hvcsd->vdev);
42216
42217 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42218
42219 free_irq(irq, hvcsd);
42220 return;
42221 - } else if (hvcsd->port.count < 0) {
42222 + } else if (atomic_read(&hvcsd->port.count) < 0) {
42223 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
42224 " is missmanaged.\n",
42225 - hvcsd->vdev->unit_address, hvcsd->port.count);
42226 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
42227 }
42228
42229 spin_unlock_irqrestore(&hvcsd->lock, flags);
42230 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42231
42232 spin_lock_irqsave(&hvcsd->lock, flags);
42233 /* Preserve this so that we know how many kref refs to put */
42234 - temp_open_count = hvcsd->port.count;
42235 + temp_open_count = atomic_read(&hvcsd->port.count);
42236
42237 /*
42238 * Don't kref put inside the spinlock because the destruction
42239 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42240 tty->driver_data = NULL;
42241 hvcsd->port.tty = NULL;
42242
42243 - hvcsd->port.count = 0;
42244 + atomic_set(&hvcsd->port.count, 0);
42245
42246 /* This will drop any buffered data on the floor which is OK in a hangup
42247 * scenario. */
42248 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
42249 * the middle of a write operation? This is a crummy place to do this
42250 * but we want to keep it all in the spinlock.
42251 */
42252 - if (hvcsd->port.count <= 0) {
42253 + if (atomic_read(&hvcsd->port.count) <= 0) {
42254 spin_unlock_irqrestore(&hvcsd->lock, flags);
42255 return -ENODEV;
42256 }
42257 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
42258 {
42259 struct hvcs_struct *hvcsd = tty->driver_data;
42260
42261 - if (!hvcsd || hvcsd->port.count <= 0)
42262 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
42263 return 0;
42264
42265 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
42266 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
42267 index 2cde13d..645d78f 100644
42268 --- a/drivers/tty/ipwireless/tty.c
42269 +++ b/drivers/tty/ipwireless/tty.c
42270 @@ -29,6 +29,7 @@
42271 #include <linux/tty_driver.h>
42272 #include <linux/tty_flip.h>
42273 #include <linux/uaccess.h>
42274 +#include <asm/local.h>
42275
42276 #include "tty.h"
42277 #include "network.h"
42278 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42279 mutex_unlock(&tty->ipw_tty_mutex);
42280 return -ENODEV;
42281 }
42282 - if (tty->port.count == 0)
42283 + if (atomic_read(&tty->port.count) == 0)
42284 tty->tx_bytes_queued = 0;
42285
42286 - tty->port.count++;
42287 + atomic_inc(&tty->port.count);
42288
42289 tty->port.tty = linux_tty;
42290 linux_tty->driver_data = tty;
42291 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42292
42293 static void do_ipw_close(struct ipw_tty *tty)
42294 {
42295 - tty->port.count--;
42296 -
42297 - if (tty->port.count == 0) {
42298 + if (atomic_dec_return(&tty->port.count) == 0) {
42299 struct tty_struct *linux_tty = tty->port.tty;
42300
42301 if (linux_tty != NULL) {
42302 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
42303 return;
42304
42305 mutex_lock(&tty->ipw_tty_mutex);
42306 - if (tty->port.count == 0) {
42307 + if (atomic_read(&tty->port.count) == 0) {
42308 mutex_unlock(&tty->ipw_tty_mutex);
42309 return;
42310 }
42311 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
42312 return;
42313 }
42314
42315 - if (!tty->port.count) {
42316 + if (!atomic_read(&tty->port.count)) {
42317 mutex_unlock(&tty->ipw_tty_mutex);
42318 return;
42319 }
42320 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
42321 return -ENODEV;
42322
42323 mutex_lock(&tty->ipw_tty_mutex);
42324 - if (!tty->port.count) {
42325 + if (!atomic_read(&tty->port.count)) {
42326 mutex_unlock(&tty->ipw_tty_mutex);
42327 return -EINVAL;
42328 }
42329 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
42330 if (!tty)
42331 return -ENODEV;
42332
42333 - if (!tty->port.count)
42334 + if (!atomic_read(&tty->port.count))
42335 return -EINVAL;
42336
42337 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
42338 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
42339 if (!tty)
42340 return 0;
42341
42342 - if (!tty->port.count)
42343 + if (!atomic_read(&tty->port.count))
42344 return 0;
42345
42346 return tty->tx_bytes_queued;
42347 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
42348 if (!tty)
42349 return -ENODEV;
42350
42351 - if (!tty->port.count)
42352 + if (!atomic_read(&tty->port.count))
42353 return -EINVAL;
42354
42355 return get_control_lines(tty);
42356 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
42357 if (!tty)
42358 return -ENODEV;
42359
42360 - if (!tty->port.count)
42361 + if (!atomic_read(&tty->port.count))
42362 return -EINVAL;
42363
42364 return set_control_lines(tty, set, clear);
42365 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
42366 if (!tty)
42367 return -ENODEV;
42368
42369 - if (!tty->port.count)
42370 + if (!atomic_read(&tty->port.count))
42371 return -EINVAL;
42372
42373 /* FIXME: Exactly how is the tty object locked here .. */
42374 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
42375 * are gone */
42376 mutex_lock(&ttyj->ipw_tty_mutex);
42377 }
42378 - while (ttyj->port.count)
42379 + while (atomic_read(&ttyj->port.count))
42380 do_ipw_close(ttyj);
42381 ipwireless_disassociate_network_ttys(network,
42382 ttyj->channel_idx);
42383 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
42384 index f9d2850..b006f04 100644
42385 --- a/drivers/tty/moxa.c
42386 +++ b/drivers/tty/moxa.c
42387 @@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
42388 }
42389
42390 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
42391 - ch->port.count++;
42392 + atomic_inc(&ch->port.count);
42393 tty->driver_data = ch;
42394 tty_port_tty_set(&ch->port, tty);
42395 mutex_lock(&ch->port.mutex);
42396 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
42397 index bfd6771..e0d93c4 100644
42398 --- a/drivers/tty/n_gsm.c
42399 +++ b/drivers/tty/n_gsm.c
42400 @@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
42401 spin_lock_init(&dlci->lock);
42402 mutex_init(&dlci->mutex);
42403 dlci->fifo = &dlci->_fifo;
42404 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
42405 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
42406 kfree(dlci);
42407 return NULL;
42408 }
42409 @@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
42410 struct gsm_dlci *dlci = tty->driver_data;
42411 struct tty_port *port = &dlci->port;
42412
42413 - port->count++;
42414 + atomic_inc(&port->count);
42415 dlci_get(dlci);
42416 dlci_get(dlci->gsm->dlci[0]);
42417 mux_get(dlci->gsm);
42418 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
42419 index 19083ef..6e34e97 100644
42420 --- a/drivers/tty/n_tty.c
42421 +++ b/drivers/tty/n_tty.c
42422 @@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
42423 {
42424 *ops = tty_ldisc_N_TTY;
42425 ops->owner = NULL;
42426 - ops->refcount = ops->flags = 0;
42427 + atomic_set(&ops->refcount, 0);
42428 + ops->flags = 0;
42429 }
42430 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
42431 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
42432 index 79ff3a5..1fe9399 100644
42433 --- a/drivers/tty/pty.c
42434 +++ b/drivers/tty/pty.c
42435 @@ -791,8 +791,10 @@ static void __init unix98_pty_init(void)
42436 panic("Couldn't register Unix98 pts driver");
42437
42438 /* Now create the /dev/ptmx special device */
42439 + pax_open_kernel();
42440 tty_default_fops(&ptmx_fops);
42441 - ptmx_fops.open = ptmx_open;
42442 + *(void **)&ptmx_fops.open = ptmx_open;
42443 + pax_close_kernel();
42444
42445 cdev_init(&ptmx_cdev, &ptmx_fops);
42446 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
42447 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
42448 index e42009a..566a036 100644
42449 --- a/drivers/tty/rocket.c
42450 +++ b/drivers/tty/rocket.c
42451 @@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42452 tty->driver_data = info;
42453 tty_port_tty_set(port, tty);
42454
42455 - if (port->count++ == 0) {
42456 + if (atomic_inc_return(&port->count) == 1) {
42457 atomic_inc(&rp_num_ports_open);
42458
42459 #ifdef ROCKET_DEBUG_OPEN
42460 @@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42461 #endif
42462 }
42463 #ifdef ROCKET_DEBUG_OPEN
42464 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
42465 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
42466 #endif
42467
42468 /*
42469 @@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
42470 spin_unlock_irqrestore(&info->port.lock, flags);
42471 return;
42472 }
42473 - if (info->port.count)
42474 + if (atomic_read(&info->port.count))
42475 atomic_dec(&rp_num_ports_open);
42476 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
42477 spin_unlock_irqrestore(&info->port.lock, flags);
42478 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
42479 index 1002054..dd644a8 100644
42480 --- a/drivers/tty/serial/kgdboc.c
42481 +++ b/drivers/tty/serial/kgdboc.c
42482 @@ -24,8 +24,9 @@
42483 #define MAX_CONFIG_LEN 40
42484
42485 static struct kgdb_io kgdboc_io_ops;
42486 +static struct kgdb_io kgdboc_io_ops_console;
42487
42488 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
42489 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
42490 static int configured = -1;
42491
42492 static char config[MAX_CONFIG_LEN];
42493 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
42494 kgdboc_unregister_kbd();
42495 if (configured == 1)
42496 kgdb_unregister_io_module(&kgdboc_io_ops);
42497 + else if (configured == 2)
42498 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
42499 }
42500
42501 static int configure_kgdboc(void)
42502 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
42503 int err;
42504 char *cptr = config;
42505 struct console *cons;
42506 + int is_console = 0;
42507
42508 err = kgdboc_option_setup(config);
42509 if (err || !strlen(config) || isspace(config[0]))
42510 goto noconfig;
42511
42512 err = -ENODEV;
42513 - kgdboc_io_ops.is_console = 0;
42514 kgdb_tty_driver = NULL;
42515
42516 kgdboc_use_kms = 0;
42517 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
42518 int idx;
42519 if (cons->device && cons->device(cons, &idx) == p &&
42520 idx == tty_line) {
42521 - kgdboc_io_ops.is_console = 1;
42522 + is_console = 1;
42523 break;
42524 }
42525 cons = cons->next;
42526 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
42527 kgdb_tty_line = tty_line;
42528
42529 do_register:
42530 - err = kgdb_register_io_module(&kgdboc_io_ops);
42531 + if (is_console) {
42532 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
42533 + configured = 2;
42534 + } else {
42535 + err = kgdb_register_io_module(&kgdboc_io_ops);
42536 + configured = 1;
42537 + }
42538 if (err)
42539 goto noconfig;
42540
42541 @@ -205,8 +214,6 @@ do_register:
42542 if (err)
42543 goto nmi_con_failed;
42544
42545 - configured = 1;
42546 -
42547 return 0;
42548
42549 nmi_con_failed:
42550 @@ -223,7 +230,7 @@ noconfig:
42551 static int __init init_kgdboc(void)
42552 {
42553 /* Already configured? */
42554 - if (configured == 1)
42555 + if (configured >= 1)
42556 return 0;
42557
42558 return configure_kgdboc();
42559 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
42560 if (config[len - 1] == '\n')
42561 config[len - 1] = '\0';
42562
42563 - if (configured == 1)
42564 + if (configured >= 1)
42565 cleanup_kgdboc();
42566
42567 /* Go and configure with the new params. */
42568 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
42569 .post_exception = kgdboc_post_exp_handler,
42570 };
42571
42572 +static struct kgdb_io kgdboc_io_ops_console = {
42573 + .name = "kgdboc",
42574 + .read_char = kgdboc_get_char,
42575 + .write_char = kgdboc_put_char,
42576 + .pre_exception = kgdboc_pre_exp_handler,
42577 + .post_exception = kgdboc_post_exp_handler,
42578 + .is_console = 1
42579 +};
42580 +
42581 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
42582 /* This is only available if kgdboc is a built in for early debugging */
42583 static int __init kgdboc_early_init(char *opt)
42584 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
42585 index e514b3a..c73d614 100644
42586 --- a/drivers/tty/serial/samsung.c
42587 +++ b/drivers/tty/serial/samsung.c
42588 @@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
42589 }
42590 }
42591
42592 +static int s3c64xx_serial_startup(struct uart_port *port);
42593 static int s3c24xx_serial_startup(struct uart_port *port)
42594 {
42595 struct s3c24xx_uart_port *ourport = to_ourport(port);
42596 int ret;
42597
42598 + /* Startup sequence is different for s3c64xx and higher SoC's */
42599 + if (s3c24xx_serial_has_interrupt_mask(port))
42600 + return s3c64xx_serial_startup(port);
42601 +
42602 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
42603 port->mapbase, port->membase);
42604
42605 @@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
42606 /* setup info for port */
42607 port->dev = &platdev->dev;
42608
42609 - /* Startup sequence is different for s3c64xx and higher SoC's */
42610 - if (s3c24xx_serial_has_interrupt_mask(port))
42611 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
42612 -
42613 port->uartclk = 1;
42614
42615 if (cfg->uart_flags & UPF_CONS_FLOW) {
42616 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
42617 index 2c7230a..2104f16 100644
42618 --- a/drivers/tty/serial/serial_core.c
42619 +++ b/drivers/tty/serial/serial_core.c
42620 @@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
42621 uart_flush_buffer(tty);
42622 uart_shutdown(tty, state);
42623 spin_lock_irqsave(&port->lock, flags);
42624 - port->count = 0;
42625 + atomic_set(&port->count, 0);
42626 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
42627 spin_unlock_irqrestore(&port->lock, flags);
42628 tty_port_tty_set(port, NULL);
42629 @@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
42630 goto end;
42631 }
42632
42633 - port->count++;
42634 + atomic_inc(&port->count);
42635 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
42636 retval = -ENXIO;
42637 goto err_dec_count;
42638 @@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
42639 /*
42640 * Make sure the device is in D0 state.
42641 */
42642 - if (port->count == 1)
42643 + if (atomic_read(&port->count) == 1)
42644 uart_change_pm(state, 0);
42645
42646 /*
42647 @@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
42648 end:
42649 return retval;
42650 err_dec_count:
42651 - port->count--;
42652 + atomic_inc(&port->count);
42653 mutex_unlock(&port->mutex);
42654 goto end;
42655 }
42656 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
42657 index 9e071f6..f30ae69 100644
42658 --- a/drivers/tty/synclink.c
42659 +++ b/drivers/tty/synclink.c
42660 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
42661
42662 if (debug_level >= DEBUG_LEVEL_INFO)
42663 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
42664 - __FILE__,__LINE__, info->device_name, info->port.count);
42665 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
42666
42667 if (tty_port_close_start(&info->port, tty, filp) == 0)
42668 goto cleanup;
42669 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
42670 cleanup:
42671 if (debug_level >= DEBUG_LEVEL_INFO)
42672 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
42673 - tty->driver->name, info->port.count);
42674 + tty->driver->name, atomic_read(&info->port.count));
42675
42676 } /* end of mgsl_close() */
42677
42678 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
42679
42680 mgsl_flush_buffer(tty);
42681 shutdown(info);
42682 -
42683 - info->port.count = 0;
42684 +
42685 + atomic_set(&info->port.count, 0);
42686 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
42687 info->port.tty = NULL;
42688
42689 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
42690
42691 if (debug_level >= DEBUG_LEVEL_INFO)
42692 printk("%s(%d):block_til_ready before block on %s count=%d\n",
42693 - __FILE__,__LINE__, tty->driver->name, port->count );
42694 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
42695
42696 spin_lock_irqsave(&info->irq_spinlock, flags);
42697 if (!tty_hung_up_p(filp)) {
42698 extra_count = true;
42699 - port->count--;
42700 + atomic_dec(&port->count);
42701 }
42702 spin_unlock_irqrestore(&info->irq_spinlock, flags);
42703 port->blocked_open++;
42704 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
42705
42706 if (debug_level >= DEBUG_LEVEL_INFO)
42707 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
42708 - __FILE__,__LINE__, tty->driver->name, port->count );
42709 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
42710
42711 tty_unlock(tty);
42712 schedule();
42713 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
42714
42715 /* FIXME: Racy on hangup during close wait */
42716 if (extra_count)
42717 - port->count++;
42718 + atomic_inc(&port->count);
42719 port->blocked_open--;
42720
42721 if (debug_level >= DEBUG_LEVEL_INFO)
42722 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
42723 - __FILE__,__LINE__, tty->driver->name, port->count );
42724 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
42725
42726 if (!retval)
42727 port->flags |= ASYNC_NORMAL_ACTIVE;
42728 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
42729
42730 if (debug_level >= DEBUG_LEVEL_INFO)
42731 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
42732 - __FILE__,__LINE__,tty->driver->name, info->port.count);
42733 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
42734
42735 /* If port is closing, signal caller to try again */
42736 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
42737 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
42738 spin_unlock_irqrestore(&info->netlock, flags);
42739 goto cleanup;
42740 }
42741 - info->port.count++;
42742 + atomic_inc(&info->port.count);
42743 spin_unlock_irqrestore(&info->netlock, flags);
42744
42745 - if (info->port.count == 1) {
42746 + if (atomic_read(&info->port.count) == 1) {
42747 /* 1st open on this device, init hardware */
42748 retval = startup(info);
42749 if (retval < 0)
42750 @@ -3451,8 +3451,8 @@ cleanup:
42751 if (retval) {
42752 if (tty->count == 1)
42753 info->port.tty = NULL; /* tty layer will release tty struct */
42754 - if(info->port.count)
42755 - info->port.count--;
42756 + if (atomic_read(&info->port.count))
42757 + atomic_dec(&info->port.count);
42758 }
42759
42760 return retval;
42761 @@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
42762 unsigned short new_crctype;
42763
42764 /* return error if TTY interface open */
42765 - if (info->port.count)
42766 + if (atomic_read(&info->port.count))
42767 return -EBUSY;
42768
42769 switch (encoding)
42770 @@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
42771
42772 /* arbitrate between network and tty opens */
42773 spin_lock_irqsave(&info->netlock, flags);
42774 - if (info->port.count != 0 || info->netcount != 0) {
42775 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
42776 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
42777 spin_unlock_irqrestore(&info->netlock, flags);
42778 return -EBUSY;
42779 @@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42780 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
42781
42782 /* return error if TTY interface open */
42783 - if (info->port.count)
42784 + if (atomic_read(&info->port.count))
42785 return -EBUSY;
42786
42787 if (cmd != SIOCWANDEV)
42788 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
42789 index aba1e59..877ac33 100644
42790 --- a/drivers/tty/synclink_gt.c
42791 +++ b/drivers/tty/synclink_gt.c
42792 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
42793 tty->driver_data = info;
42794 info->port.tty = tty;
42795
42796 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
42797 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
42798
42799 /* If port is closing, signal caller to try again */
42800 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
42801 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
42802 mutex_unlock(&info->port.mutex);
42803 goto cleanup;
42804 }
42805 - info->port.count++;
42806 + atomic_inc(&info->port.count);
42807 spin_unlock_irqrestore(&info->netlock, flags);
42808
42809 - if (info->port.count == 1) {
42810 + if (atomic_read(&info->port.count) == 1) {
42811 /* 1st open on this device, init hardware */
42812 retval = startup(info);
42813 if (retval < 0) {
42814 @@ -716,8 +716,8 @@ cleanup:
42815 if (retval) {
42816 if (tty->count == 1)
42817 info->port.tty = NULL; /* tty layer will release tty struct */
42818 - if(info->port.count)
42819 - info->port.count--;
42820 + if(atomic_read(&info->port.count))
42821 + atomic_dec(&info->port.count);
42822 }
42823
42824 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
42825 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
42826
42827 if (sanity_check(info, tty->name, "close"))
42828 return;
42829 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
42830 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
42831
42832 if (tty_port_close_start(&info->port, tty, filp) == 0)
42833 goto cleanup;
42834 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
42835 tty_port_close_end(&info->port, tty);
42836 info->port.tty = NULL;
42837 cleanup:
42838 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
42839 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
42840 }
42841
42842 static void hangup(struct tty_struct *tty)
42843 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
42844 shutdown(info);
42845
42846 spin_lock_irqsave(&info->port.lock, flags);
42847 - info->port.count = 0;
42848 + atomic_set(&info->port.count, 0);
42849 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
42850 info->port.tty = NULL;
42851 spin_unlock_irqrestore(&info->port.lock, flags);
42852 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
42853 unsigned short new_crctype;
42854
42855 /* return error if TTY interface open */
42856 - if (info->port.count)
42857 + if (atomic_read(&info->port.count))
42858 return -EBUSY;
42859
42860 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
42861 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
42862
42863 /* arbitrate between network and tty opens */
42864 spin_lock_irqsave(&info->netlock, flags);
42865 - if (info->port.count != 0 || info->netcount != 0) {
42866 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
42867 DBGINFO(("%s hdlc_open busy\n", dev->name));
42868 spin_unlock_irqrestore(&info->netlock, flags);
42869 return -EBUSY;
42870 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42871 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
42872
42873 /* return error if TTY interface open */
42874 - if (info->port.count)
42875 + if (atomic_read(&info->port.count))
42876 return -EBUSY;
42877
42878 if (cmd != SIOCWANDEV)
42879 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
42880 if (port == NULL)
42881 continue;
42882 spin_lock(&port->lock);
42883 - if ((port->port.count || port->netcount) &&
42884 + if ((atomic_read(&port->port.count) || port->netcount) &&
42885 port->pending_bh && !port->bh_running &&
42886 !port->bh_requested) {
42887 DBGISR(("%s bh queued\n", port->device_name));
42888 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
42889 spin_lock_irqsave(&info->lock, flags);
42890 if (!tty_hung_up_p(filp)) {
42891 extra_count = true;
42892 - port->count--;
42893 + atomic_dec(&port->count);
42894 }
42895 spin_unlock_irqrestore(&info->lock, flags);
42896 port->blocked_open++;
42897 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
42898 remove_wait_queue(&port->open_wait, &wait);
42899
42900 if (extra_count)
42901 - port->count++;
42902 + atomic_inc(&port->count);
42903 port->blocked_open--;
42904
42905 if (!retval)
42906 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
42907 index fd43fb6..34704ad 100644
42908 --- a/drivers/tty/synclinkmp.c
42909 +++ b/drivers/tty/synclinkmp.c
42910 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
42911
42912 if (debug_level >= DEBUG_LEVEL_INFO)
42913 printk("%s(%d):%s open(), old ref count = %d\n",
42914 - __FILE__,__LINE__,tty->driver->name, info->port.count);
42915 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
42916
42917 /* If port is closing, signal caller to try again */
42918 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
42919 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
42920 spin_unlock_irqrestore(&info->netlock, flags);
42921 goto cleanup;
42922 }
42923 - info->port.count++;
42924 + atomic_inc(&info->port.count);
42925 spin_unlock_irqrestore(&info->netlock, flags);
42926
42927 - if (info->port.count == 1) {
42928 + if (atomic_read(&info->port.count) == 1) {
42929 /* 1st open on this device, init hardware */
42930 retval = startup(info);
42931 if (retval < 0)
42932 @@ -797,8 +797,8 @@ cleanup:
42933 if (retval) {
42934 if (tty->count == 1)
42935 info->port.tty = NULL; /* tty layer will release tty struct */
42936 - if(info->port.count)
42937 - info->port.count--;
42938 + if(atomic_read(&info->port.count))
42939 + atomic_dec(&info->port.count);
42940 }
42941
42942 return retval;
42943 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
42944
42945 if (debug_level >= DEBUG_LEVEL_INFO)
42946 printk("%s(%d):%s close() entry, count=%d\n",
42947 - __FILE__,__LINE__, info->device_name, info->port.count);
42948 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
42949
42950 if (tty_port_close_start(&info->port, tty, filp) == 0)
42951 goto cleanup;
42952 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
42953 cleanup:
42954 if (debug_level >= DEBUG_LEVEL_INFO)
42955 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
42956 - tty->driver->name, info->port.count);
42957 + tty->driver->name, atomic_read(&info->port.count));
42958 }
42959
42960 /* Called by tty_hangup() when a hangup is signaled.
42961 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
42962 shutdown(info);
42963
42964 spin_lock_irqsave(&info->port.lock, flags);
42965 - info->port.count = 0;
42966 + atomic_set(&info->port.count, 0);
42967 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
42968 info->port.tty = NULL;
42969 spin_unlock_irqrestore(&info->port.lock, flags);
42970 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
42971 unsigned short new_crctype;
42972
42973 /* return error if TTY interface open */
42974 - if (info->port.count)
42975 + if (atomic_read(&info->port.count))
42976 return -EBUSY;
42977
42978 switch (encoding)
42979 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
42980
42981 /* arbitrate between network and tty opens */
42982 spin_lock_irqsave(&info->netlock, flags);
42983 - if (info->port.count != 0 || info->netcount != 0) {
42984 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
42985 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
42986 spin_unlock_irqrestore(&info->netlock, flags);
42987 return -EBUSY;
42988 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42989 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
42990
42991 /* return error if TTY interface open */
42992 - if (info->port.count)
42993 + if (atomic_read(&info->port.count))
42994 return -EBUSY;
42995
42996 if (cmd != SIOCWANDEV)
42997 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
42998 * do not request bottom half processing if the
42999 * device is not open in a normal mode.
43000 */
43001 - if ( port && (port->port.count || port->netcount) &&
43002 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
43003 port->pending_bh && !port->bh_running &&
43004 !port->bh_requested ) {
43005 if ( debug_level >= DEBUG_LEVEL_ISR )
43006 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43007
43008 if (debug_level >= DEBUG_LEVEL_INFO)
43009 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
43010 - __FILE__,__LINE__, tty->driver->name, port->count );
43011 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43012
43013 spin_lock_irqsave(&info->lock, flags);
43014 if (!tty_hung_up_p(filp)) {
43015 extra_count = true;
43016 - port->count--;
43017 + atomic_dec(&port->count);
43018 }
43019 spin_unlock_irqrestore(&info->lock, flags);
43020 port->blocked_open++;
43021 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43022
43023 if (debug_level >= DEBUG_LEVEL_INFO)
43024 printk("%s(%d):%s block_til_ready() count=%d\n",
43025 - __FILE__,__LINE__, tty->driver->name, port->count );
43026 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43027
43028 tty_unlock(tty);
43029 schedule();
43030 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43031 remove_wait_queue(&port->open_wait, &wait);
43032
43033 if (extra_count)
43034 - port->count++;
43035 + atomic_inc(&port->count);
43036 port->blocked_open--;
43037
43038 if (debug_level >= DEBUG_LEVEL_INFO)
43039 printk("%s(%d):%s block_til_ready() after, count=%d\n",
43040 - __FILE__,__LINE__, tty->driver->name, port->count );
43041 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43042
43043 if (!retval)
43044 port->flags |= ASYNC_NORMAL_ACTIVE;
43045 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
43046 index b3c4a25..723916f 100644
43047 --- a/drivers/tty/sysrq.c
43048 +++ b/drivers/tty/sysrq.c
43049 @@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
43050 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
43051 size_t count, loff_t *ppos)
43052 {
43053 - if (count) {
43054 + if (count && capable(CAP_SYS_ADMIN)) {
43055 char c;
43056
43057 if (get_user(c, buf))
43058 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
43059 index da9fde8..c07975f 100644
43060 --- a/drivers/tty/tty_io.c
43061 +++ b/drivers/tty/tty_io.c
43062 @@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
43063
43064 void tty_default_fops(struct file_operations *fops)
43065 {
43066 - *fops = tty_fops;
43067 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
43068 }
43069
43070 /*
43071 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
43072 index c578229..45aa9ee 100644
43073 --- a/drivers/tty/tty_ldisc.c
43074 +++ b/drivers/tty/tty_ldisc.c
43075 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
43076 if (atomic_dec_and_test(&ld->users)) {
43077 struct tty_ldisc_ops *ldo = ld->ops;
43078
43079 - ldo->refcount--;
43080 + atomic_dec(&ldo->refcount);
43081 module_put(ldo->owner);
43082 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43083
43084 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
43085 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43086 tty_ldiscs[disc] = new_ldisc;
43087 new_ldisc->num = disc;
43088 - new_ldisc->refcount = 0;
43089 + atomic_set(&new_ldisc->refcount, 0);
43090 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43091
43092 return ret;
43093 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
43094 return -EINVAL;
43095
43096 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43097 - if (tty_ldiscs[disc]->refcount)
43098 + if (atomic_read(&tty_ldiscs[disc]->refcount))
43099 ret = -EBUSY;
43100 else
43101 tty_ldiscs[disc] = NULL;
43102 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
43103 if (ldops) {
43104 ret = ERR_PTR(-EAGAIN);
43105 if (try_module_get(ldops->owner)) {
43106 - ldops->refcount++;
43107 + atomic_inc(&ldops->refcount);
43108 ret = ldops;
43109 }
43110 }
43111 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
43112 unsigned long flags;
43113
43114 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43115 - ldops->refcount--;
43116 + atomic_dec(&ldops->refcount);
43117 module_put(ldops->owner);
43118 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43119 }
43120 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
43121 index b7ff59d..7c6105e 100644
43122 --- a/drivers/tty/tty_port.c
43123 +++ b/drivers/tty/tty_port.c
43124 @@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
43125 unsigned long flags;
43126
43127 spin_lock_irqsave(&port->lock, flags);
43128 - port->count = 0;
43129 + atomic_set(&port->count, 0);
43130 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43131 if (port->tty) {
43132 set_bit(TTY_IO_ERROR, &port->tty->flags);
43133 @@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43134 /* The port lock protects the port counts */
43135 spin_lock_irqsave(&port->lock, flags);
43136 if (!tty_hung_up_p(filp))
43137 - port->count--;
43138 + atomic_dec(&port->count);
43139 port->blocked_open++;
43140 spin_unlock_irqrestore(&port->lock, flags);
43141
43142 @@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43143 we must not mess that up further */
43144 spin_lock_irqsave(&port->lock, flags);
43145 if (!tty_hung_up_p(filp))
43146 - port->count++;
43147 + atomic_inc(&port->count);
43148 port->blocked_open--;
43149 if (retval == 0)
43150 port->flags |= ASYNC_NORMAL_ACTIVE;
43151 @@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
43152 return 0;
43153 }
43154
43155 - if (tty->count == 1 && port->count != 1) {
43156 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
43157 printk(KERN_WARNING
43158 "tty_port_close_start: tty->count = 1 port count = %d.\n",
43159 - port->count);
43160 - port->count = 1;
43161 + atomic_read(&port->count));
43162 + atomic_set(&port->count, 1);
43163 }
43164 - if (--port->count < 0) {
43165 + if (atomic_dec_return(&port->count) < 0) {
43166 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
43167 - port->count);
43168 - port->count = 0;
43169 + atomic_read(&port->count));
43170 + atomic_set(&port->count, 0);
43171 }
43172
43173 - if (port->count) {
43174 + if (atomic_read(&port->count)) {
43175 spin_unlock_irqrestore(&port->lock, flags);
43176 if (port->ops->drop)
43177 port->ops->drop(port);
43178 @@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
43179 {
43180 spin_lock_irq(&port->lock);
43181 if (!tty_hung_up_p(filp))
43182 - ++port->count;
43183 + atomic_inc(&port->count);
43184 spin_unlock_irq(&port->lock);
43185 tty_port_tty_set(port, tty);
43186
43187 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
43188 index 681765b..d3ccdf2 100644
43189 --- a/drivers/tty/vt/keyboard.c
43190 +++ b/drivers/tty/vt/keyboard.c
43191 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
43192 kbd->kbdmode == VC_OFF) &&
43193 value != KVAL(K_SAK))
43194 return; /* SAK is allowed even in raw mode */
43195 +
43196 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
43197 + {
43198 + void *func = fn_handler[value];
43199 + if (func == fn_show_state || func == fn_show_ptregs ||
43200 + func == fn_show_mem)
43201 + return;
43202 + }
43203 +#endif
43204 +
43205 fn_handler[value](vc);
43206 }
43207
43208 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43209 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
43210 return -EFAULT;
43211
43212 - if (!capable(CAP_SYS_TTY_CONFIG))
43213 - perm = 0;
43214 -
43215 switch (cmd) {
43216 case KDGKBENT:
43217 /* Ensure another thread doesn't free it under us */
43218 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43219 spin_unlock_irqrestore(&kbd_event_lock, flags);
43220 return put_user(val, &user_kbe->kb_value);
43221 case KDSKBENT:
43222 + if (!capable(CAP_SYS_TTY_CONFIG))
43223 + perm = 0;
43224 +
43225 if (!perm)
43226 return -EPERM;
43227 if (!i && v == K_NOSUCHMAP) {
43228 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43229 int i, j, k;
43230 int ret;
43231
43232 - if (!capable(CAP_SYS_TTY_CONFIG))
43233 - perm = 0;
43234 -
43235 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
43236 if (!kbs) {
43237 ret = -ENOMEM;
43238 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43239 kfree(kbs);
43240 return ((p && *p) ? -EOVERFLOW : 0);
43241 case KDSKBSENT:
43242 + if (!capable(CAP_SYS_TTY_CONFIG))
43243 + perm = 0;
43244 +
43245 if (!perm) {
43246 ret = -EPERM;
43247 goto reterr;
43248 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
43249 index 5110f36..8dc0a74 100644
43250 --- a/drivers/uio/uio.c
43251 +++ b/drivers/uio/uio.c
43252 @@ -25,6 +25,7 @@
43253 #include <linux/kobject.h>
43254 #include <linux/cdev.h>
43255 #include <linux/uio_driver.h>
43256 +#include <asm/local.h>
43257
43258 #define UIO_MAX_DEVICES (1U << MINORBITS)
43259
43260 @@ -32,10 +33,10 @@ struct uio_device {
43261 struct module *owner;
43262 struct device *dev;
43263 int minor;
43264 - atomic_t event;
43265 + atomic_unchecked_t event;
43266 struct fasync_struct *async_queue;
43267 wait_queue_head_t wait;
43268 - int vma_count;
43269 + local_t vma_count;
43270 struct uio_info *info;
43271 struct kobject *map_dir;
43272 struct kobject *portio_dir;
43273 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
43274 struct device_attribute *attr, char *buf)
43275 {
43276 struct uio_device *idev = dev_get_drvdata(dev);
43277 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
43278 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
43279 }
43280
43281 static struct device_attribute uio_class_attributes[] = {
43282 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
43283 {
43284 struct uio_device *idev = info->uio_dev;
43285
43286 - atomic_inc(&idev->event);
43287 + atomic_inc_unchecked(&idev->event);
43288 wake_up_interruptible(&idev->wait);
43289 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
43290 }
43291 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
43292 }
43293
43294 listener->dev = idev;
43295 - listener->event_count = atomic_read(&idev->event);
43296 + listener->event_count = atomic_read_unchecked(&idev->event);
43297 filep->private_data = listener;
43298
43299 if (idev->info->open) {
43300 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
43301 return -EIO;
43302
43303 poll_wait(filep, &idev->wait, wait);
43304 - if (listener->event_count != atomic_read(&idev->event))
43305 + if (listener->event_count != atomic_read_unchecked(&idev->event))
43306 return POLLIN | POLLRDNORM;
43307 return 0;
43308 }
43309 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
43310 do {
43311 set_current_state(TASK_INTERRUPTIBLE);
43312
43313 - event_count = atomic_read(&idev->event);
43314 + event_count = atomic_read_unchecked(&idev->event);
43315 if (event_count != listener->event_count) {
43316 if (copy_to_user(buf, &event_count, count))
43317 retval = -EFAULT;
43318 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
43319 static void uio_vma_open(struct vm_area_struct *vma)
43320 {
43321 struct uio_device *idev = vma->vm_private_data;
43322 - idev->vma_count++;
43323 + local_inc(&idev->vma_count);
43324 }
43325
43326 static void uio_vma_close(struct vm_area_struct *vma)
43327 {
43328 struct uio_device *idev = vma->vm_private_data;
43329 - idev->vma_count--;
43330 + local_dec(&idev->vma_count);
43331 }
43332
43333 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
43334 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
43335 idev->owner = owner;
43336 idev->info = info;
43337 init_waitqueue_head(&idev->wait);
43338 - atomic_set(&idev->event, 0);
43339 + atomic_set_unchecked(&idev->event, 0);
43340
43341 ret = uio_get_minor(idev);
43342 if (ret)
43343 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
43344 index b7eb86a..36d28af 100644
43345 --- a/drivers/usb/atm/cxacru.c
43346 +++ b/drivers/usb/atm/cxacru.c
43347 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
43348 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
43349 if (ret < 2)
43350 return -EINVAL;
43351 - if (index < 0 || index > 0x7f)
43352 + if (index > 0x7f)
43353 return -EINVAL;
43354 pos += tmp;
43355
43356 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
43357 index 35f10bf..6a38a0b 100644
43358 --- a/drivers/usb/atm/usbatm.c
43359 +++ b/drivers/usb/atm/usbatm.c
43360 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43361 if (printk_ratelimit())
43362 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
43363 __func__, vpi, vci);
43364 - atomic_inc(&vcc->stats->rx_err);
43365 + atomic_inc_unchecked(&vcc->stats->rx_err);
43366 return;
43367 }
43368
43369 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43370 if (length > ATM_MAX_AAL5_PDU) {
43371 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
43372 __func__, length, vcc);
43373 - atomic_inc(&vcc->stats->rx_err);
43374 + atomic_inc_unchecked(&vcc->stats->rx_err);
43375 goto out;
43376 }
43377
43378 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43379 if (sarb->len < pdu_length) {
43380 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
43381 __func__, pdu_length, sarb->len, vcc);
43382 - atomic_inc(&vcc->stats->rx_err);
43383 + atomic_inc_unchecked(&vcc->stats->rx_err);
43384 goto out;
43385 }
43386
43387 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
43388 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
43389 __func__, vcc);
43390 - atomic_inc(&vcc->stats->rx_err);
43391 + atomic_inc_unchecked(&vcc->stats->rx_err);
43392 goto out;
43393 }
43394
43395 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43396 if (printk_ratelimit())
43397 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
43398 __func__, length);
43399 - atomic_inc(&vcc->stats->rx_drop);
43400 + atomic_inc_unchecked(&vcc->stats->rx_drop);
43401 goto out;
43402 }
43403
43404 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43405
43406 vcc->push(vcc, skb);
43407
43408 - atomic_inc(&vcc->stats->rx);
43409 + atomic_inc_unchecked(&vcc->stats->rx);
43410 out:
43411 skb_trim(sarb, 0);
43412 }
43413 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
43414 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
43415
43416 usbatm_pop(vcc, skb);
43417 - atomic_inc(&vcc->stats->tx);
43418 + atomic_inc_unchecked(&vcc->stats->tx);
43419
43420 skb = skb_dequeue(&instance->sndqueue);
43421 }
43422 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
43423 if (!left--)
43424 return sprintf(page,
43425 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
43426 - atomic_read(&atm_dev->stats.aal5.tx),
43427 - atomic_read(&atm_dev->stats.aal5.tx_err),
43428 - atomic_read(&atm_dev->stats.aal5.rx),
43429 - atomic_read(&atm_dev->stats.aal5.rx_err),
43430 - atomic_read(&atm_dev->stats.aal5.rx_drop));
43431 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
43432 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
43433 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
43434 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
43435 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
43436
43437 if (!left--) {
43438 if (instance->disconnected)
43439 diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
43440 index 5f0cb41..122d056 100644
43441 --- a/drivers/usb/class/cdc-wdm.c
43442 +++ b/drivers/usb/class/cdc-wdm.c
43443 @@ -56,6 +56,7 @@ MODULE_DEVICE_TABLE (usb, wdm_ids);
43444 #define WDM_RESPONDING 7
43445 #define WDM_SUSPENDING 8
43446 #define WDM_RESETTING 9
43447 +#define WDM_OVERFLOW 10
43448
43449 #define WDM_MAX 16
43450
43451 @@ -155,6 +156,7 @@ static void wdm_in_callback(struct urb *urb)
43452 {
43453 struct wdm_device *desc = urb->context;
43454 int status = urb->status;
43455 + int length = urb->actual_length;
43456
43457 spin_lock(&desc->iuspin);
43458 clear_bit(WDM_RESPONDING, &desc->flags);
43459 @@ -185,9 +187,17 @@ static void wdm_in_callback(struct urb *urb)
43460 }
43461
43462 desc->rerr = status;
43463 - desc->reslength = urb->actual_length;
43464 - memmove(desc->ubuf + desc->length, desc->inbuf, desc->reslength);
43465 - desc->length += desc->reslength;
43466 + if (length + desc->length > desc->wMaxCommand) {
43467 + /* The buffer would overflow */
43468 + set_bit(WDM_OVERFLOW, &desc->flags);
43469 + } else {
43470 + /* we may already be in overflow */
43471 + if (!test_bit(WDM_OVERFLOW, &desc->flags)) {
43472 + memmove(desc->ubuf + desc->length, desc->inbuf, length);
43473 + desc->length += length;
43474 + desc->reslength = length;
43475 + }
43476 + }
43477 skip_error:
43478 wake_up(&desc->wait);
43479
43480 @@ -435,6 +445,11 @@ retry:
43481 rv = -ENODEV;
43482 goto err;
43483 }
43484 + if (test_bit(WDM_OVERFLOW, &desc->flags)) {
43485 + clear_bit(WDM_OVERFLOW, &desc->flags);
43486 + rv = -ENOBUFS;
43487 + goto err;
43488 + }
43489 i++;
43490 if (file->f_flags & O_NONBLOCK) {
43491 if (!test_bit(WDM_READ, &desc->flags)) {
43492 @@ -478,6 +493,7 @@ retry:
43493 spin_unlock_irq(&desc->iuspin);
43494 goto retry;
43495 }
43496 +
43497 if (!desc->reslength) { /* zero length read */
43498 dev_dbg(&desc->intf->dev, "%s: zero length - clearing WDM_READ\n", __func__);
43499 clear_bit(WDM_READ, &desc->flags);
43500 @@ -1004,6 +1020,7 @@ static int wdm_post_reset(struct usb_interface *intf)
43501 struct wdm_device *desc = wdm_find_device(intf);
43502 int rv;
43503
43504 + clear_bit(WDM_OVERFLOW, &desc->flags);
43505 clear_bit(WDM_RESETTING, &desc->flags);
43506 rv = recover_from_urb_loss(desc);
43507 mutex_unlock(&desc->wlock);
43508 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
43509 index cbacea9..246cccd 100644
43510 --- a/drivers/usb/core/devices.c
43511 +++ b/drivers/usb/core/devices.c
43512 @@ -126,7 +126,7 @@ static const char format_endpt[] =
43513 * time it gets called.
43514 */
43515 static struct device_connect_event {
43516 - atomic_t count;
43517 + atomic_unchecked_t count;
43518 wait_queue_head_t wait;
43519 } device_event = {
43520 .count = ATOMIC_INIT(1),
43521 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
43522
43523 void usbfs_conn_disc_event(void)
43524 {
43525 - atomic_add(2, &device_event.count);
43526 + atomic_add_unchecked(2, &device_event.count);
43527 wake_up(&device_event.wait);
43528 }
43529
43530 @@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
43531
43532 poll_wait(file, &device_event.wait, wait);
43533
43534 - event_count = atomic_read(&device_event.count);
43535 + event_count = atomic_read_unchecked(&device_event.count);
43536 if (file->f_version != event_count) {
43537 file->f_version = event_count;
43538 return POLLIN | POLLRDNORM;
43539 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
43540 index 8e64adf..9a33a3c 100644
43541 --- a/drivers/usb/core/hcd.c
43542 +++ b/drivers/usb/core/hcd.c
43543 @@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
43544 */
43545 usb_get_urb(urb);
43546 atomic_inc(&urb->use_count);
43547 - atomic_inc(&urb->dev->urbnum);
43548 + atomic_inc_unchecked(&urb->dev->urbnum);
43549 usbmon_urb_submit(&hcd->self, urb);
43550
43551 /* NOTE requirements on root-hub callers (usbfs and the hub
43552 @@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
43553 urb->hcpriv = NULL;
43554 INIT_LIST_HEAD(&urb->urb_list);
43555 atomic_dec(&urb->use_count);
43556 - atomic_dec(&urb->dev->urbnum);
43557 + atomic_dec_unchecked(&urb->dev->urbnum);
43558 if (atomic_read(&urb->reject))
43559 wake_up(&usb_kill_urb_queue);
43560 usb_put_urb(urb);
43561 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
43562 index 818e4a0..0fc9589 100644
43563 --- a/drivers/usb/core/sysfs.c
43564 +++ b/drivers/usb/core/sysfs.c
43565 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
43566 struct usb_device *udev;
43567
43568 udev = to_usb_device(dev);
43569 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
43570 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
43571 }
43572 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
43573
43574 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
43575 index f81b925..78d22ec 100644
43576 --- a/drivers/usb/core/usb.c
43577 +++ b/drivers/usb/core/usb.c
43578 @@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
43579 set_dev_node(&dev->dev, dev_to_node(bus->controller));
43580 dev->state = USB_STATE_ATTACHED;
43581 dev->lpm_disable_count = 1;
43582 - atomic_set(&dev->urbnum, 0);
43583 + atomic_set_unchecked(&dev->urbnum, 0);
43584
43585 INIT_LIST_HEAD(&dev->ep0.urb_list);
43586 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
43587 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
43588 index 5e29dde..eca992f 100644
43589 --- a/drivers/usb/early/ehci-dbgp.c
43590 +++ b/drivers/usb/early/ehci-dbgp.c
43591 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
43592
43593 #ifdef CONFIG_KGDB
43594 static struct kgdb_io kgdbdbgp_io_ops;
43595 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
43596 +static struct kgdb_io kgdbdbgp_io_ops_console;
43597 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
43598 #else
43599 #define dbgp_kgdb_mode (0)
43600 #endif
43601 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
43602 .write_char = kgdbdbgp_write_char,
43603 };
43604
43605 +static struct kgdb_io kgdbdbgp_io_ops_console = {
43606 + .name = "kgdbdbgp",
43607 + .read_char = kgdbdbgp_read_char,
43608 + .write_char = kgdbdbgp_write_char,
43609 + .is_console = 1
43610 +};
43611 +
43612 static int kgdbdbgp_wait_time;
43613
43614 static int __init kgdbdbgp_parse_config(char *str)
43615 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
43616 ptr++;
43617 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
43618 }
43619 - kgdb_register_io_module(&kgdbdbgp_io_ops);
43620 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
43621 + if (early_dbgp_console.index != -1)
43622 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
43623 + else
43624 + kgdb_register_io_module(&kgdbdbgp_io_ops);
43625
43626 return 0;
43627 }
43628 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
43629 index 598dcc1..032dd4f 100644
43630 --- a/drivers/usb/gadget/u_serial.c
43631 +++ b/drivers/usb/gadget/u_serial.c
43632 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
43633 spin_lock_irq(&port->port_lock);
43634
43635 /* already open? Great. */
43636 - if (port->port.count) {
43637 + if (atomic_read(&port->port.count)) {
43638 status = 0;
43639 - port->port.count++;
43640 + atomic_inc(&port->port.count);
43641
43642 /* currently opening/closing? wait ... */
43643 } else if (port->openclose) {
43644 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
43645 tty->driver_data = port;
43646 port->port.tty = tty;
43647
43648 - port->port.count = 1;
43649 + atomic_set(&port->port.count, 1);
43650 port->openclose = false;
43651
43652 /* if connected, start the I/O stream */
43653 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
43654
43655 spin_lock_irq(&port->port_lock);
43656
43657 - if (port->port.count != 1) {
43658 - if (port->port.count == 0)
43659 + if (atomic_read(&port->port.count) != 1) {
43660 + if (atomic_read(&port->port.count) == 0)
43661 WARN_ON(1);
43662 else
43663 - --port->port.count;
43664 + atomic_dec(&port->port.count);
43665 goto exit;
43666 }
43667
43668 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
43669 * and sleep if necessary
43670 */
43671 port->openclose = true;
43672 - port->port.count = 0;
43673 + atomic_set(&port->port.count, 0);
43674
43675 gser = port->port_usb;
43676 if (gser && gser->disconnect)
43677 @@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
43678 int cond;
43679
43680 spin_lock_irq(&port->port_lock);
43681 - cond = (port->port.count == 0) && !port->openclose;
43682 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
43683 spin_unlock_irq(&port->port_lock);
43684 return cond;
43685 }
43686 @@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
43687 /* if it's already open, start I/O ... and notify the serial
43688 * protocol about open/close status (connect/disconnect).
43689 */
43690 - if (port->port.count) {
43691 + if (atomic_read(&port->port.count)) {
43692 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
43693 gs_start_io(port);
43694 if (gser->connect)
43695 @@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
43696
43697 port->port_usb = NULL;
43698 gser->ioport = NULL;
43699 - if (port->port.count > 0 || port->openclose) {
43700 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
43701 wake_up_interruptible(&port->drain_wait);
43702 if (port->port.tty)
43703 tty_hangup(port->port.tty);
43704 @@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
43705
43706 /* finally, free any unused/unusable I/O buffers */
43707 spin_lock_irqsave(&port->port_lock, flags);
43708 - if (port->port.count == 0 && !port->openclose)
43709 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
43710 gs_buf_free(&port->port_write_buf);
43711 gs_free_requests(gser->out, &port->read_pool, NULL);
43712 gs_free_requests(gser->out, &port->read_queue, NULL);
43713 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
43714 index 5f3bcd3..bfca43f 100644
43715 --- a/drivers/usb/serial/console.c
43716 +++ b/drivers/usb/serial/console.c
43717 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
43718
43719 info->port = port;
43720
43721 - ++port->port.count;
43722 + atomic_inc(&port->port.count);
43723 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
43724 if (serial->type->set_termios) {
43725 /*
43726 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
43727 }
43728 /* Now that any required fake tty operations are completed restore
43729 * the tty port count */
43730 - --port->port.count;
43731 + atomic_dec(&port->port.count);
43732 /* The console is special in terms of closing the device so
43733 * indicate this port is now acting as a system console. */
43734 port->port.console = 1;
43735 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
43736 free_tty:
43737 kfree(tty);
43738 reset_open_count:
43739 - port->port.count = 0;
43740 + atomic_set(&port->port.count, 0);
43741 usb_autopm_put_interface(serial->interface);
43742 error_get_interface:
43743 usb_serial_put(serial);
43744 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
43745 index 75f70f0..d467e1a 100644
43746 --- a/drivers/usb/storage/usb.h
43747 +++ b/drivers/usb/storage/usb.h
43748 @@ -63,7 +63,7 @@ struct us_unusual_dev {
43749 __u8 useProtocol;
43750 __u8 useTransport;
43751 int (*initFunction)(struct us_data *);
43752 -};
43753 +} __do_const;
43754
43755
43756 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
43757 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
43758 index d6bea3e..60b250e 100644
43759 --- a/drivers/usb/wusbcore/wa-hc.h
43760 +++ b/drivers/usb/wusbcore/wa-hc.h
43761 @@ -192,7 +192,7 @@ struct wahc {
43762 struct list_head xfer_delayed_list;
43763 spinlock_t xfer_list_lock;
43764 struct work_struct xfer_work;
43765 - atomic_t xfer_id_count;
43766 + atomic_unchecked_t xfer_id_count;
43767 };
43768
43769
43770 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
43771 INIT_LIST_HEAD(&wa->xfer_delayed_list);
43772 spin_lock_init(&wa->xfer_list_lock);
43773 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
43774 - atomic_set(&wa->xfer_id_count, 1);
43775 + atomic_set_unchecked(&wa->xfer_id_count, 1);
43776 }
43777
43778 /**
43779 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
43780 index 57c01ab..8a05959 100644
43781 --- a/drivers/usb/wusbcore/wa-xfer.c
43782 +++ b/drivers/usb/wusbcore/wa-xfer.c
43783 @@ -296,7 +296,7 @@ out:
43784 */
43785 static void wa_xfer_id_init(struct wa_xfer *xfer)
43786 {
43787 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
43788 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
43789 }
43790
43791 /*
43792 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
43793 index 8c55011..eed4ae1a 100644
43794 --- a/drivers/video/aty/aty128fb.c
43795 +++ b/drivers/video/aty/aty128fb.c
43796 @@ -149,7 +149,7 @@ enum {
43797 };
43798
43799 /* Must match above enum */
43800 -static char * const r128_family[] = {
43801 +static const char * const r128_family[] = {
43802 "AGP",
43803 "PCI",
43804 "PRO AGP",
43805 diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
43806 index 4f27fdc..d3537e6 100644
43807 --- a/drivers/video/aty/atyfb_base.c
43808 +++ b/drivers/video/aty/atyfb_base.c
43809 @@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
43810 par->accel_flags = var->accel_flags; /* hack */
43811
43812 if (var->accel_flags) {
43813 - info->fbops->fb_sync = atyfb_sync;
43814 + pax_open_kernel();
43815 + *(void **)&info->fbops->fb_sync = atyfb_sync;
43816 + pax_close_kernel();
43817 info->flags &= ~FBINFO_HWACCEL_DISABLED;
43818 } else {
43819 - info->fbops->fb_sync = NULL;
43820 + pax_open_kernel();
43821 + *(void **)&info->fbops->fb_sync = NULL;
43822 + pax_close_kernel();
43823 info->flags |= FBINFO_HWACCEL_DISABLED;
43824 }
43825
43826 diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
43827 index 95ec042..e6affdd 100644
43828 --- a/drivers/video/aty/mach64_cursor.c
43829 +++ b/drivers/video/aty/mach64_cursor.c
43830 @@ -7,6 +7,7 @@
43831 #include <linux/string.h>
43832
43833 #include <asm/io.h>
43834 +#include <asm/pgtable.h>
43835
43836 #ifdef __sparc__
43837 #include <asm/fbio.h>
43838 @@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
43839 info->sprite.buf_align = 16; /* and 64 lines tall. */
43840 info->sprite.flags = FB_PIXMAP_IO;
43841
43842 - info->fbops->fb_cursor = atyfb_cursor;
43843 + pax_open_kernel();
43844 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
43845 + pax_close_kernel();
43846
43847 return 0;
43848 }
43849 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
43850 index 6c5ed6b..b727c88 100644
43851 --- a/drivers/video/backlight/kb3886_bl.c
43852 +++ b/drivers/video/backlight/kb3886_bl.c
43853 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
43854 static unsigned long kb3886bl_flags;
43855 #define KB3886BL_SUSPENDED 0x01
43856
43857 -static struct dmi_system_id __initdata kb3886bl_device_table[] = {
43858 +static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
43859 {
43860 .ident = "Sahara Touch-iT",
43861 .matches = {
43862 diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
43863 index 88cad6b..dd746c7 100644
43864 --- a/drivers/video/fb_defio.c
43865 +++ b/drivers/video/fb_defio.c
43866 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
43867
43868 BUG_ON(!fbdefio);
43869 mutex_init(&fbdefio->lock);
43870 - info->fbops->fb_mmap = fb_deferred_io_mmap;
43871 + pax_open_kernel();
43872 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
43873 + pax_close_kernel();
43874 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
43875 INIT_LIST_HEAD(&fbdefio->pagelist);
43876 if (fbdefio->delay == 0) /* set a default of 1 s */
43877 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
43878 page->mapping = NULL;
43879 }
43880
43881 - info->fbops->fb_mmap = NULL;
43882 + *(void **)&info->fbops->fb_mmap = NULL;
43883 mutex_destroy(&fbdefio->lock);
43884 }
43885 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
43886 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
43887 index 5c3960d..15cf8fc 100644
43888 --- a/drivers/video/fbcmap.c
43889 +++ b/drivers/video/fbcmap.c
43890 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
43891 rc = -ENODEV;
43892 goto out;
43893 }
43894 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
43895 - !info->fbops->fb_setcmap)) {
43896 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
43897 rc = -EINVAL;
43898 goto out1;
43899 }
43900 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
43901 index dc61c12..e29796e 100644
43902 --- a/drivers/video/fbmem.c
43903 +++ b/drivers/video/fbmem.c
43904 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
43905 image->dx += image->width + 8;
43906 }
43907 } else if (rotate == FB_ROTATE_UD) {
43908 - for (x = 0; x < num && image->dx >= 0; x++) {
43909 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
43910 info->fbops->fb_imageblit(info, image);
43911 image->dx -= image->width + 8;
43912 }
43913 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
43914 image->dy += image->height + 8;
43915 }
43916 } else if (rotate == FB_ROTATE_CCW) {
43917 - for (x = 0; x < num && image->dy >= 0; x++) {
43918 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
43919 info->fbops->fb_imageblit(info, image);
43920 image->dy -= image->height + 8;
43921 }
43922 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
43923 return -EFAULT;
43924 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
43925 return -EINVAL;
43926 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
43927 + if (con2fb.framebuffer >= FB_MAX)
43928 return -EINVAL;
43929 if (!registered_fb[con2fb.framebuffer])
43930 request_module("fb%d", con2fb.framebuffer);
43931 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
43932 index 7672d2e..b56437f 100644
43933 --- a/drivers/video/i810/i810_accel.c
43934 +++ b/drivers/video/i810/i810_accel.c
43935 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
43936 }
43937 }
43938 printk("ringbuffer lockup!!!\n");
43939 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
43940 i810_report_error(mmio);
43941 par->dev_flags |= LOCKUP;
43942 info->pixmap.scan_align = 1;
43943 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
43944 index 3c14e43..eafa544 100644
43945 --- a/drivers/video/logo/logo_linux_clut224.ppm
43946 +++ b/drivers/video/logo/logo_linux_clut224.ppm
43947 @@ -1,1604 +1,1123 @@
43948 P3
43949 -# Standard 224-color Linux logo
43950 80 80
43951 255
43952 - 0 0 0 0 0 0 0 0 0 0 0 0
43953 - 0 0 0 0 0 0 0 0 0 0 0 0
43954 - 0 0 0 0 0 0 0 0 0 0 0 0
43955 - 0 0 0 0 0 0 0 0 0 0 0 0
43956 - 0 0 0 0 0 0 0 0 0 0 0 0
43957 - 0 0 0 0 0 0 0 0 0 0 0 0
43958 - 0 0 0 0 0 0 0 0 0 0 0 0
43959 - 0 0 0 0 0 0 0 0 0 0 0 0
43960 - 0 0 0 0 0 0 0 0 0 0 0 0
43961 - 6 6 6 6 6 6 10 10 10 10 10 10
43962 - 10 10 10 6 6 6 6 6 6 6 6 6
43963 - 0 0 0 0 0 0 0 0 0 0 0 0
43964 - 0 0 0 0 0 0 0 0 0 0 0 0
43965 - 0 0 0 0 0 0 0 0 0 0 0 0
43966 - 0 0 0 0 0 0 0 0 0 0 0 0
43967 - 0 0 0 0 0 0 0 0 0 0 0 0
43968 - 0 0 0 0 0 0 0 0 0 0 0 0
43969 - 0 0 0 0 0 0 0 0 0 0 0 0
43970 - 0 0 0 0 0 0 0 0 0 0 0 0
43971 - 0 0 0 0 0 0 0 0 0 0 0 0
43972 - 0 0 0 0 0 0 0 0 0 0 0 0
43973 - 0 0 0 0 0 0 0 0 0 0 0 0
43974 - 0 0 0 0 0 0 0 0 0 0 0 0
43975 - 0 0 0 0 0 0 0 0 0 0 0 0
43976 - 0 0 0 0 0 0 0 0 0 0 0 0
43977 - 0 0 0 0 0 0 0 0 0 0 0 0
43978 - 0 0 0 0 0 0 0 0 0 0 0 0
43979 - 0 0 0 0 0 0 0 0 0 0 0 0
43980 - 0 0 0 6 6 6 10 10 10 14 14 14
43981 - 22 22 22 26 26 26 30 30 30 34 34 34
43982 - 30 30 30 30 30 30 26 26 26 18 18 18
43983 - 14 14 14 10 10 10 6 6 6 0 0 0
43984 - 0 0 0 0 0 0 0 0 0 0 0 0
43985 - 0 0 0 0 0 0 0 0 0 0 0 0
43986 - 0 0 0 0 0 0 0 0 0 0 0 0
43987 - 0 0 0 0 0 0 0 0 0 0 0 0
43988 - 0 0 0 0 0 0 0 0 0 0 0 0
43989 - 0 0 0 0 0 0 0 0 0 0 0 0
43990 - 0 0 0 0 0 0 0 0 0 0 0 0
43991 - 0 0 0 0 0 0 0 0 0 0 0 0
43992 - 0 0 0 0 0 0 0 0 0 0 0 0
43993 - 0 0 0 0 0 1 0 0 1 0 0 0
43994 - 0 0 0 0 0 0 0 0 0 0 0 0
43995 - 0 0 0 0 0 0 0 0 0 0 0 0
43996 - 0 0 0 0 0 0 0 0 0 0 0 0
43997 - 0 0 0 0 0 0 0 0 0 0 0 0
43998 - 0 0 0 0 0 0 0 0 0 0 0 0
43999 - 0 0 0 0 0 0 0 0 0 0 0 0
44000 - 6 6 6 14 14 14 26 26 26 42 42 42
44001 - 54 54 54 66 66 66 78 78 78 78 78 78
44002 - 78 78 78 74 74 74 66 66 66 54 54 54
44003 - 42 42 42 26 26 26 18 18 18 10 10 10
44004 - 6 6 6 0 0 0 0 0 0 0 0 0
44005 - 0 0 0 0 0 0 0 0 0 0 0 0
44006 - 0 0 0 0 0 0 0 0 0 0 0 0
44007 - 0 0 0 0 0 0 0 0 0 0 0 0
44008 - 0 0 0 0 0 0 0 0 0 0 0 0
44009 - 0 0 0 0 0 0 0 0 0 0 0 0
44010 - 0 0 0 0 0 0 0 0 0 0 0 0
44011 - 0 0 0 0 0 0 0 0 0 0 0 0
44012 - 0 0 0 0 0 0 0 0 0 0 0 0
44013 - 0 0 1 0 0 0 0 0 0 0 0 0
44014 - 0 0 0 0 0 0 0 0 0 0 0 0
44015 - 0 0 0 0 0 0 0 0 0 0 0 0
44016 - 0 0 0 0 0 0 0 0 0 0 0 0
44017 - 0 0 0 0 0 0 0 0 0 0 0 0
44018 - 0 0 0 0 0 0 0 0 0 0 0 0
44019 - 0 0 0 0 0 0 0 0 0 10 10 10
44020 - 22 22 22 42 42 42 66 66 66 86 86 86
44021 - 66 66 66 38 38 38 38 38 38 22 22 22
44022 - 26 26 26 34 34 34 54 54 54 66 66 66
44023 - 86 86 86 70 70 70 46 46 46 26 26 26
44024 - 14 14 14 6 6 6 0 0 0 0 0 0
44025 - 0 0 0 0 0 0 0 0 0 0 0 0
44026 - 0 0 0 0 0 0 0 0 0 0 0 0
44027 - 0 0 0 0 0 0 0 0 0 0 0 0
44028 - 0 0 0 0 0 0 0 0 0 0 0 0
44029 - 0 0 0 0 0 0 0 0 0 0 0 0
44030 - 0 0 0 0 0 0 0 0 0 0 0 0
44031 - 0 0 0 0 0 0 0 0 0 0 0 0
44032 - 0 0 0 0 0 0 0 0 0 0 0 0
44033 - 0 0 1 0 0 1 0 0 1 0 0 0
44034 - 0 0 0 0 0 0 0 0 0 0 0 0
44035 - 0 0 0 0 0 0 0 0 0 0 0 0
44036 - 0 0 0 0 0 0 0 0 0 0 0 0
44037 - 0 0 0 0 0 0 0 0 0 0 0 0
44038 - 0 0 0 0 0 0 0 0 0 0 0 0
44039 - 0 0 0 0 0 0 10 10 10 26 26 26
44040 - 50 50 50 82 82 82 58 58 58 6 6 6
44041 - 2 2 6 2 2 6 2 2 6 2 2 6
44042 - 2 2 6 2 2 6 2 2 6 2 2 6
44043 - 6 6 6 54 54 54 86 86 86 66 66 66
44044 - 38 38 38 18 18 18 6 6 6 0 0 0
44045 - 0 0 0 0 0 0 0 0 0 0 0 0
44046 - 0 0 0 0 0 0 0 0 0 0 0 0
44047 - 0 0 0 0 0 0 0 0 0 0 0 0
44048 - 0 0 0 0 0 0 0 0 0 0 0 0
44049 - 0 0 0 0 0 0 0 0 0 0 0 0
44050 - 0 0 0 0 0 0 0 0 0 0 0 0
44051 - 0 0 0 0 0 0 0 0 0 0 0 0
44052 - 0 0 0 0 0 0 0 0 0 0 0 0
44053 - 0 0 0 0 0 0 0 0 0 0 0 0
44054 - 0 0 0 0 0 0 0 0 0 0 0 0
44055 - 0 0 0 0 0 0 0 0 0 0 0 0
44056 - 0 0 0 0 0 0 0 0 0 0 0 0
44057 - 0 0 0 0 0 0 0 0 0 0 0 0
44058 - 0 0 0 0 0 0 0 0 0 0 0 0
44059 - 0 0 0 6 6 6 22 22 22 50 50 50
44060 - 78 78 78 34 34 34 2 2 6 2 2 6
44061 - 2 2 6 2 2 6 2 2 6 2 2 6
44062 - 2 2 6 2 2 6 2 2 6 2 2 6
44063 - 2 2 6 2 2 6 6 6 6 70 70 70
44064 - 78 78 78 46 46 46 22 22 22 6 6 6
44065 - 0 0 0 0 0 0 0 0 0 0 0 0
44066 - 0 0 0 0 0 0 0 0 0 0 0 0
44067 - 0 0 0 0 0 0 0 0 0 0 0 0
44068 - 0 0 0 0 0 0 0 0 0 0 0 0
44069 - 0 0 0 0 0 0 0 0 0 0 0 0
44070 - 0 0 0 0 0 0 0 0 0 0 0 0
44071 - 0 0 0 0 0 0 0 0 0 0 0 0
44072 - 0 0 0 0 0 0 0 0 0 0 0 0
44073 - 0 0 1 0 0 1 0 0 1 0 0 0
44074 - 0 0 0 0 0 0 0 0 0 0 0 0
44075 - 0 0 0 0 0 0 0 0 0 0 0 0
44076 - 0 0 0 0 0 0 0 0 0 0 0 0
44077 - 0 0 0 0 0 0 0 0 0 0 0 0
44078 - 0 0 0 0 0 0 0 0 0 0 0 0
44079 - 6 6 6 18 18 18 42 42 42 82 82 82
44080 - 26 26 26 2 2 6 2 2 6 2 2 6
44081 - 2 2 6 2 2 6 2 2 6 2 2 6
44082 - 2 2 6 2 2 6 2 2 6 14 14 14
44083 - 46 46 46 34 34 34 6 6 6 2 2 6
44084 - 42 42 42 78 78 78 42 42 42 18 18 18
44085 - 6 6 6 0 0 0 0 0 0 0 0 0
44086 - 0 0 0 0 0 0 0 0 0 0 0 0
44087 - 0 0 0 0 0 0 0 0 0 0 0 0
44088 - 0 0 0 0 0 0 0 0 0 0 0 0
44089 - 0 0 0 0 0 0 0 0 0 0 0 0
44090 - 0 0 0 0 0 0 0 0 0 0 0 0
44091 - 0 0 0 0 0 0 0 0 0 0 0 0
44092 - 0 0 0 0 0 0 0 0 0 0 0 0
44093 - 0 0 1 0 0 0 0 0 1 0 0 0
44094 - 0 0 0 0 0 0 0 0 0 0 0 0
44095 - 0 0 0 0 0 0 0 0 0 0 0 0
44096 - 0 0 0 0 0 0 0 0 0 0 0 0
44097 - 0 0 0 0 0 0 0 0 0 0 0 0
44098 - 0 0 0 0 0 0 0 0 0 0 0 0
44099 - 10 10 10 30 30 30 66 66 66 58 58 58
44100 - 2 2 6 2 2 6 2 2 6 2 2 6
44101 - 2 2 6 2 2 6 2 2 6 2 2 6
44102 - 2 2 6 2 2 6 2 2 6 26 26 26
44103 - 86 86 86 101 101 101 46 46 46 10 10 10
44104 - 2 2 6 58 58 58 70 70 70 34 34 34
44105 - 10 10 10 0 0 0 0 0 0 0 0 0
44106 - 0 0 0 0 0 0 0 0 0 0 0 0
44107 - 0 0 0 0 0 0 0 0 0 0 0 0
44108 - 0 0 0 0 0 0 0 0 0 0 0 0
44109 - 0 0 0 0 0 0 0 0 0 0 0 0
44110 - 0 0 0 0 0 0 0 0 0 0 0 0
44111 - 0 0 0 0 0 0 0 0 0 0 0 0
44112 - 0 0 0 0 0 0 0 0 0 0 0 0
44113 - 0 0 1 0 0 1 0 0 1 0 0 0
44114 - 0 0 0 0 0 0 0 0 0 0 0 0
44115 - 0 0 0 0 0 0 0 0 0 0 0 0
44116 - 0 0 0 0 0 0 0 0 0 0 0 0
44117 - 0 0 0 0 0 0 0 0 0 0 0 0
44118 - 0 0 0 0 0 0 0 0 0 0 0 0
44119 - 14 14 14 42 42 42 86 86 86 10 10 10
44120 - 2 2 6 2 2 6 2 2 6 2 2 6
44121 - 2 2 6 2 2 6 2 2 6 2 2 6
44122 - 2 2 6 2 2 6 2 2 6 30 30 30
44123 - 94 94 94 94 94 94 58 58 58 26 26 26
44124 - 2 2 6 6 6 6 78 78 78 54 54 54
44125 - 22 22 22 6 6 6 0 0 0 0 0 0
44126 - 0 0 0 0 0 0 0 0 0 0 0 0
44127 - 0 0 0 0 0 0 0 0 0 0 0 0
44128 - 0 0 0 0 0 0 0 0 0 0 0 0
44129 - 0 0 0 0 0 0 0 0 0 0 0 0
44130 - 0 0 0 0 0 0 0 0 0 0 0 0
44131 - 0 0 0 0 0 0 0 0 0 0 0 0
44132 - 0 0 0 0 0 0 0 0 0 0 0 0
44133 - 0 0 0 0 0 0 0 0 0 0 0 0
44134 - 0 0 0 0 0 0 0 0 0 0 0 0
44135 - 0 0 0 0 0 0 0 0 0 0 0 0
44136 - 0 0 0 0 0 0 0 0 0 0 0 0
44137 - 0 0 0 0 0 0 0 0 0 0 0 0
44138 - 0 0 0 0 0 0 0 0 0 6 6 6
44139 - 22 22 22 62 62 62 62 62 62 2 2 6
44140 - 2 2 6 2 2 6 2 2 6 2 2 6
44141 - 2 2 6 2 2 6 2 2 6 2 2 6
44142 - 2 2 6 2 2 6 2 2 6 26 26 26
44143 - 54 54 54 38 38 38 18 18 18 10 10 10
44144 - 2 2 6 2 2 6 34 34 34 82 82 82
44145 - 38 38 38 14 14 14 0 0 0 0 0 0
44146 - 0 0 0 0 0 0 0 0 0 0 0 0
44147 - 0 0 0 0 0 0 0 0 0 0 0 0
44148 - 0 0 0 0 0 0 0 0 0 0 0 0
44149 - 0 0 0 0 0 0 0 0 0 0 0 0
44150 - 0 0 0 0 0 0 0 0 0 0 0 0
44151 - 0 0 0 0 0 0 0 0 0 0 0 0
44152 - 0 0 0 0 0 0 0 0 0 0 0 0
44153 - 0 0 0 0 0 1 0 0 1 0 0 0
44154 - 0 0 0 0 0 0 0 0 0 0 0 0
44155 - 0 0 0 0 0 0 0 0 0 0 0 0
44156 - 0 0 0 0 0 0 0 0 0 0 0 0
44157 - 0 0 0 0 0 0 0 0 0 0 0 0
44158 - 0 0 0 0 0 0 0 0 0 6 6 6
44159 - 30 30 30 78 78 78 30 30 30 2 2 6
44160 - 2 2 6 2 2 6 2 2 6 2 2 6
44161 - 2 2 6 2 2 6 2 2 6 2 2 6
44162 - 2 2 6 2 2 6 2 2 6 10 10 10
44163 - 10 10 10 2 2 6 2 2 6 2 2 6
44164 - 2 2 6 2 2 6 2 2 6 78 78 78
44165 - 50 50 50 18 18 18 6 6 6 0 0 0
44166 - 0 0 0 0 0 0 0 0 0 0 0 0
44167 - 0 0 0 0 0 0 0 0 0 0 0 0
44168 - 0 0 0 0 0 0 0 0 0 0 0 0
44169 - 0 0 0 0 0 0 0 0 0 0 0 0
44170 - 0 0 0 0 0 0 0 0 0 0 0 0
44171 - 0 0 0 0 0 0 0 0 0 0 0 0
44172 - 0 0 0 0 0 0 0 0 0 0 0 0
44173 - 0 0 1 0 0 0 0 0 0 0 0 0
44174 - 0 0 0 0 0 0 0 0 0 0 0 0
44175 - 0 0 0 0 0 0 0 0 0 0 0 0
44176 - 0 0 0 0 0 0 0 0 0 0 0 0
44177 - 0 0 0 0 0 0 0 0 0 0 0 0
44178 - 0 0 0 0 0 0 0 0 0 10 10 10
44179 - 38 38 38 86 86 86 14 14 14 2 2 6
44180 - 2 2 6 2 2 6 2 2 6 2 2 6
44181 - 2 2 6 2 2 6 2 2 6 2 2 6
44182 - 2 2 6 2 2 6 2 2 6 2 2 6
44183 - 2 2 6 2 2 6 2 2 6 2 2 6
44184 - 2 2 6 2 2 6 2 2 6 54 54 54
44185 - 66 66 66 26 26 26 6 6 6 0 0 0
44186 - 0 0 0 0 0 0 0 0 0 0 0 0
44187 - 0 0 0 0 0 0 0 0 0 0 0 0
44188 - 0 0 0 0 0 0 0 0 0 0 0 0
44189 - 0 0 0 0 0 0 0 0 0 0 0 0
44190 - 0 0 0 0 0 0 0 0 0 0 0 0
44191 - 0 0 0 0 0 0 0 0 0 0 0 0
44192 - 0 0 0 0 0 0 0 0 0 0 0 0
44193 - 0 0 0 0 0 1 0 0 1 0 0 0
44194 - 0 0 0 0 0 0 0 0 0 0 0 0
44195 - 0 0 0 0 0 0 0 0 0 0 0 0
44196 - 0 0 0 0 0 0 0 0 0 0 0 0
44197 - 0 0 0 0 0 0 0 0 0 0 0 0
44198 - 0 0 0 0 0 0 0 0 0 14 14 14
44199 - 42 42 42 82 82 82 2 2 6 2 2 6
44200 - 2 2 6 6 6 6 10 10 10 2 2 6
44201 - 2 2 6 2 2 6 2 2 6 2 2 6
44202 - 2 2 6 2 2 6 2 2 6 6 6 6
44203 - 14 14 14 10 10 10 2 2 6 2 2 6
44204 - 2 2 6 2 2 6 2 2 6 18 18 18
44205 - 82 82 82 34 34 34 10 10 10 0 0 0
44206 - 0 0 0 0 0 0 0 0 0 0 0 0
44207 - 0 0 0 0 0 0 0 0 0 0 0 0
44208 - 0 0 0 0 0 0 0 0 0 0 0 0
44209 - 0 0 0 0 0 0 0 0 0 0 0 0
44210 - 0 0 0 0 0 0 0 0 0 0 0 0
44211 - 0 0 0 0 0 0 0 0 0 0 0 0
44212 - 0 0 0 0 0 0 0 0 0 0 0 0
44213 - 0 0 1 0 0 0 0 0 0 0 0 0
44214 - 0 0 0 0 0 0 0 0 0 0 0 0
44215 - 0 0 0 0 0 0 0 0 0 0 0 0
44216 - 0 0 0 0 0 0 0 0 0 0 0 0
44217 - 0 0 0 0 0 0 0 0 0 0 0 0
44218 - 0 0 0 0 0 0 0 0 0 14 14 14
44219 - 46 46 46 86 86 86 2 2 6 2 2 6
44220 - 6 6 6 6 6 6 22 22 22 34 34 34
44221 - 6 6 6 2 2 6 2 2 6 2 2 6
44222 - 2 2 6 2 2 6 18 18 18 34 34 34
44223 - 10 10 10 50 50 50 22 22 22 2 2 6
44224 - 2 2 6 2 2 6 2 2 6 10 10 10
44225 - 86 86 86 42 42 42 14 14 14 0 0 0
44226 - 0 0 0 0 0 0 0 0 0 0 0 0
44227 - 0 0 0 0 0 0 0 0 0 0 0 0
44228 - 0 0 0 0 0 0 0 0 0 0 0 0
44229 - 0 0 0 0 0 0 0 0 0 0 0 0
44230 - 0 0 0 0 0 0 0 0 0 0 0 0
44231 - 0 0 0 0 0 0 0 0 0 0 0 0
44232 - 0 0 0 0 0 0 0 0 0 0 0 0
44233 - 0 0 1 0 0 1 0 0 1 0 0 0
44234 - 0 0 0 0 0 0 0 0 0 0 0 0
44235 - 0 0 0 0 0 0 0 0 0 0 0 0
44236 - 0 0 0 0 0 0 0 0 0 0 0 0
44237 - 0 0 0 0 0 0 0 0 0 0 0 0
44238 - 0 0 0 0 0 0 0 0 0 14 14 14
44239 - 46 46 46 86 86 86 2 2 6 2 2 6
44240 - 38 38 38 116 116 116 94 94 94 22 22 22
44241 - 22 22 22 2 2 6 2 2 6 2 2 6
44242 - 14 14 14 86 86 86 138 138 138 162 162 162
44243 -154 154 154 38 38 38 26 26 26 6 6 6
44244 - 2 2 6 2 2 6 2 2 6 2 2 6
44245 - 86 86 86 46 46 46 14 14 14 0 0 0
44246 - 0 0 0 0 0 0 0 0 0 0 0 0
44247 - 0 0 0 0 0 0 0 0 0 0 0 0
44248 - 0 0 0 0 0 0 0 0 0 0 0 0
44249 - 0 0 0 0 0 0 0 0 0 0 0 0
44250 - 0 0 0 0 0 0 0 0 0 0 0 0
44251 - 0 0 0 0 0 0 0 0 0 0 0 0
44252 - 0 0 0 0 0 0 0 0 0 0 0 0
44253 - 0 0 0 0 0 0 0 0 0 0 0 0
44254 - 0 0 0 0 0 0 0 0 0 0 0 0
44255 - 0 0 0 0 0 0 0 0 0 0 0 0
44256 - 0 0 0 0 0 0 0 0 0 0 0 0
44257 - 0 0 0 0 0 0 0 0 0 0 0 0
44258 - 0 0 0 0 0 0 0 0 0 14 14 14
44259 - 46 46 46 86 86 86 2 2 6 14 14 14
44260 -134 134 134 198 198 198 195 195 195 116 116 116
44261 - 10 10 10 2 2 6 2 2 6 6 6 6
44262 -101 98 89 187 187 187 210 210 210 218 218 218
44263 -214 214 214 134 134 134 14 14 14 6 6 6
44264 - 2 2 6 2 2 6 2 2 6 2 2 6
44265 - 86 86 86 50 50 50 18 18 18 6 6 6
44266 - 0 0 0 0 0 0 0 0 0 0 0 0
44267 - 0 0 0 0 0 0 0 0 0 0 0 0
44268 - 0 0 0 0 0 0 0 0 0 0 0 0
44269 - 0 0 0 0 0 0 0 0 0 0 0 0
44270 - 0 0 0 0 0 0 0 0 0 0 0 0
44271 - 0 0 0 0 0 0 0 0 0 0 0 0
44272 - 0 0 0 0 0 0 0 0 1 0 0 0
44273 - 0 0 1 0 0 1 0 0 1 0 0 0
44274 - 0 0 0 0 0 0 0 0 0 0 0 0
44275 - 0 0 0 0 0 0 0 0 0 0 0 0
44276 - 0 0 0 0 0 0 0 0 0 0 0 0
44277 - 0 0 0 0 0 0 0 0 0 0 0 0
44278 - 0 0 0 0 0 0 0 0 0 14 14 14
44279 - 46 46 46 86 86 86 2 2 6 54 54 54
44280 -218 218 218 195 195 195 226 226 226 246 246 246
44281 - 58 58 58 2 2 6 2 2 6 30 30 30
44282 -210 210 210 253 253 253 174 174 174 123 123 123
44283 -221 221 221 234 234 234 74 74 74 2 2 6
44284 - 2 2 6 2 2 6 2 2 6 2 2 6
44285 - 70 70 70 58 58 58 22 22 22 6 6 6
44286 - 0 0 0 0 0 0 0 0 0 0 0 0
44287 - 0 0 0 0 0 0 0 0 0 0 0 0
44288 - 0 0 0 0 0 0 0 0 0 0 0 0
44289 - 0 0 0 0 0 0 0 0 0 0 0 0
44290 - 0 0 0 0 0 0 0 0 0 0 0 0
44291 - 0 0 0 0 0 0 0 0 0 0 0 0
44292 - 0 0 0 0 0 0 0 0 0 0 0 0
44293 - 0 0 0 0 0 0 0 0 0 0 0 0
44294 - 0 0 0 0 0 0 0 0 0 0 0 0
44295 - 0 0 0 0 0 0 0 0 0 0 0 0
44296 - 0 0 0 0 0 0 0 0 0 0 0 0
44297 - 0 0 0 0 0 0 0 0 0 0 0 0
44298 - 0 0 0 0 0 0 0 0 0 14 14 14
44299 - 46 46 46 82 82 82 2 2 6 106 106 106
44300 -170 170 170 26 26 26 86 86 86 226 226 226
44301 -123 123 123 10 10 10 14 14 14 46 46 46
44302 -231 231 231 190 190 190 6 6 6 70 70 70
44303 - 90 90 90 238 238 238 158 158 158 2 2 6
44304 - 2 2 6 2 2 6 2 2 6 2 2 6
44305 - 70 70 70 58 58 58 22 22 22 6 6 6
44306 - 0 0 0 0 0 0 0 0 0 0 0 0
44307 - 0 0 0 0 0 0 0 0 0 0 0 0
44308 - 0 0 0 0 0 0 0 0 0 0 0 0
44309 - 0 0 0 0 0 0 0 0 0 0 0 0
44310 - 0 0 0 0 0 0 0 0 0 0 0 0
44311 - 0 0 0 0 0 0 0 0 0 0 0 0
44312 - 0 0 0 0 0 0 0 0 1 0 0 0
44313 - 0 0 1 0 0 1 0 0 1 0 0 0
44314 - 0 0 0 0 0 0 0 0 0 0 0 0
44315 - 0 0 0 0 0 0 0 0 0 0 0 0
44316 - 0 0 0 0 0 0 0 0 0 0 0 0
44317 - 0 0 0 0 0 0 0 0 0 0 0 0
44318 - 0 0 0 0 0 0 0 0 0 14 14 14
44319 - 42 42 42 86 86 86 6 6 6 116 116 116
44320 -106 106 106 6 6 6 70 70 70 149 149 149
44321 -128 128 128 18 18 18 38 38 38 54 54 54
44322 -221 221 221 106 106 106 2 2 6 14 14 14
44323 - 46 46 46 190 190 190 198 198 198 2 2 6
44324 - 2 2 6 2 2 6 2 2 6 2 2 6
44325 - 74 74 74 62 62 62 22 22 22 6 6 6
44326 - 0 0 0 0 0 0 0 0 0 0 0 0
44327 - 0 0 0 0 0 0 0 0 0 0 0 0
44328 - 0 0 0 0 0 0 0 0 0 0 0 0
44329 - 0 0 0 0 0 0 0 0 0 0 0 0
44330 - 0 0 0 0 0 0 0 0 0 0 0 0
44331 - 0 0 0 0 0 0 0 0 0 0 0 0
44332 - 0 0 0 0 0 0 0 0 1 0 0 0
44333 - 0 0 1 0 0 0 0 0 1 0 0 0
44334 - 0 0 0 0 0 0 0 0 0 0 0 0
44335 - 0 0 0 0 0 0 0 0 0 0 0 0
44336 - 0 0 0 0 0 0 0 0 0 0 0 0
44337 - 0 0 0 0 0 0 0 0 0 0 0 0
44338 - 0 0 0 0 0 0 0 0 0 14 14 14
44339 - 42 42 42 94 94 94 14 14 14 101 101 101
44340 -128 128 128 2 2 6 18 18 18 116 116 116
44341 -118 98 46 121 92 8 121 92 8 98 78 10
44342 -162 162 162 106 106 106 2 2 6 2 2 6
44343 - 2 2 6 195 195 195 195 195 195 6 6 6
44344 - 2 2 6 2 2 6 2 2 6 2 2 6
44345 - 74 74 74 62 62 62 22 22 22 6 6 6
44346 - 0 0 0 0 0 0 0 0 0 0 0 0
44347 - 0 0 0 0 0 0 0 0 0 0 0 0
44348 - 0 0 0 0 0 0 0 0 0 0 0 0
44349 - 0 0 0 0 0 0 0 0 0 0 0 0
44350 - 0 0 0 0 0 0 0 0 0 0 0 0
44351 - 0 0 0 0 0 0 0 0 0 0 0 0
44352 - 0 0 0 0 0 0 0 0 1 0 0 1
44353 - 0 0 1 0 0 0 0 0 1 0 0 0
44354 - 0 0 0 0 0 0 0 0 0 0 0 0
44355 - 0 0 0 0 0 0 0 0 0 0 0 0
44356 - 0 0 0 0 0 0 0 0 0 0 0 0
44357 - 0 0 0 0 0 0 0 0 0 0 0 0
44358 - 0 0 0 0 0 0 0 0 0 10 10 10
44359 - 38 38 38 90 90 90 14 14 14 58 58 58
44360 -210 210 210 26 26 26 54 38 6 154 114 10
44361 -226 170 11 236 186 11 225 175 15 184 144 12
44362 -215 174 15 175 146 61 37 26 9 2 2 6
44363 - 70 70 70 246 246 246 138 138 138 2 2 6
44364 - 2 2 6 2 2 6 2 2 6 2 2 6
44365 - 70 70 70 66 66 66 26 26 26 6 6 6
44366 - 0 0 0 0 0 0 0 0 0 0 0 0
44367 - 0 0 0 0 0 0 0 0 0 0 0 0
44368 - 0 0 0 0 0 0 0 0 0 0 0 0
44369 - 0 0 0 0 0 0 0 0 0 0 0 0
44370 - 0 0 0 0 0 0 0 0 0 0 0 0
44371 - 0 0 0 0 0 0 0 0 0 0 0 0
44372 - 0 0 0 0 0 0 0 0 0 0 0 0
44373 - 0 0 0 0 0 0 0 0 0 0 0 0
44374 - 0 0 0 0 0 0 0 0 0 0 0 0
44375 - 0 0 0 0 0 0 0 0 0 0 0 0
44376 - 0 0 0 0 0 0 0 0 0 0 0 0
44377 - 0 0 0 0 0 0 0 0 0 0 0 0
44378 - 0 0 0 0 0 0 0 0 0 10 10 10
44379 - 38 38 38 86 86 86 14 14 14 10 10 10
44380 -195 195 195 188 164 115 192 133 9 225 175 15
44381 -239 182 13 234 190 10 232 195 16 232 200 30
44382 -245 207 45 241 208 19 232 195 16 184 144 12
44383 -218 194 134 211 206 186 42 42 42 2 2 6
44384 - 2 2 6 2 2 6 2 2 6 2 2 6
44385 - 50 50 50 74 74 74 30 30 30 6 6 6
44386 - 0 0 0 0 0 0 0 0 0 0 0 0
44387 - 0 0 0 0 0 0 0 0 0 0 0 0
44388 - 0 0 0 0 0 0 0 0 0 0 0 0
44389 - 0 0 0 0 0 0 0 0 0 0 0 0
44390 - 0 0 0 0 0 0 0 0 0 0 0 0
44391 - 0 0 0 0 0 0 0 0 0 0 0 0
44392 - 0 0 0 0 0 0 0 0 0 0 0 0
44393 - 0 0 0 0 0 0 0 0 0 0 0 0
44394 - 0 0 0 0 0 0 0 0 0 0 0 0
44395 - 0 0 0 0 0 0 0 0 0 0 0 0
44396 - 0 0 0 0 0 0 0 0 0 0 0 0
44397 - 0 0 0 0 0 0 0 0 0 0 0 0
44398 - 0 0 0 0 0 0 0 0 0 10 10 10
44399 - 34 34 34 86 86 86 14 14 14 2 2 6
44400 -121 87 25 192 133 9 219 162 10 239 182 13
44401 -236 186 11 232 195 16 241 208 19 244 214 54
44402 -246 218 60 246 218 38 246 215 20 241 208 19
44403 -241 208 19 226 184 13 121 87 25 2 2 6
44404 - 2 2 6 2 2 6 2 2 6 2 2 6
44405 - 50 50 50 82 82 82 34 34 34 10 10 10
44406 - 0 0 0 0 0 0 0 0 0 0 0 0
44407 - 0 0 0 0 0 0 0 0 0 0 0 0
44408 - 0 0 0 0 0 0 0 0 0 0 0 0
44409 - 0 0 0 0 0 0 0 0 0 0 0 0
44410 - 0 0 0 0 0 0 0 0 0 0 0 0
44411 - 0 0 0 0 0 0 0 0 0 0 0 0
44412 - 0 0 0 0 0 0 0 0 0 0 0 0
44413 - 0 0 0 0 0 0 0 0 0 0 0 0
44414 - 0 0 0 0 0 0 0 0 0 0 0 0
44415 - 0 0 0 0 0 0 0 0 0 0 0 0
44416 - 0 0 0 0 0 0 0 0 0 0 0 0
44417 - 0 0 0 0 0 0 0 0 0 0 0 0
44418 - 0 0 0 0 0 0 0 0 0 10 10 10
44419 - 34 34 34 82 82 82 30 30 30 61 42 6
44420 -180 123 7 206 145 10 230 174 11 239 182 13
44421 -234 190 10 238 202 15 241 208 19 246 218 74
44422 -246 218 38 246 215 20 246 215 20 246 215 20
44423 -226 184 13 215 174 15 184 144 12 6 6 6
44424 - 2 2 6 2 2 6 2 2 6 2 2 6
44425 - 26 26 26 94 94 94 42 42 42 14 14 14
44426 - 0 0 0 0 0 0 0 0 0 0 0 0
44427 - 0 0 0 0 0 0 0 0 0 0 0 0
44428 - 0 0 0 0 0 0 0 0 0 0 0 0
44429 - 0 0 0 0 0 0 0 0 0 0 0 0
44430 - 0 0 0 0 0 0 0 0 0 0 0 0
44431 - 0 0 0 0 0 0 0 0 0 0 0 0
44432 - 0 0 0 0 0 0 0 0 0 0 0 0
44433 - 0 0 0 0 0 0 0 0 0 0 0 0
44434 - 0 0 0 0 0 0 0 0 0 0 0 0
44435 - 0 0 0 0 0 0 0 0 0 0 0 0
44436 - 0 0 0 0 0 0 0 0 0 0 0 0
44437 - 0 0 0 0 0 0 0 0 0 0 0 0
44438 - 0 0 0 0 0 0 0 0 0 10 10 10
44439 - 30 30 30 78 78 78 50 50 50 104 69 6
44440 -192 133 9 216 158 10 236 178 12 236 186 11
44441 -232 195 16 241 208 19 244 214 54 245 215 43
44442 -246 215 20 246 215 20 241 208 19 198 155 10
44443 -200 144 11 216 158 10 156 118 10 2 2 6
44444 - 2 2 6 2 2 6 2 2 6 2 2 6
44445 - 6 6 6 90 90 90 54 54 54 18 18 18
44446 - 6 6 6 0 0 0 0 0 0 0 0 0
44447 - 0 0 0 0 0 0 0 0 0 0 0 0
44448 - 0 0 0 0 0 0 0 0 0 0 0 0
44449 - 0 0 0 0 0 0 0 0 0 0 0 0
44450 - 0 0 0 0 0 0 0 0 0 0 0 0
44451 - 0 0 0 0 0 0 0 0 0 0 0 0
44452 - 0 0 0 0 0 0 0 0 0 0 0 0
44453 - 0 0 0 0 0 0 0 0 0 0 0 0
44454 - 0 0 0 0 0 0 0 0 0 0 0 0
44455 - 0 0 0 0 0 0 0 0 0 0 0 0
44456 - 0 0 0 0 0 0 0 0 0 0 0 0
44457 - 0 0 0 0 0 0 0 0 0 0 0 0
44458 - 0 0 0 0 0 0 0 0 0 10 10 10
44459 - 30 30 30 78 78 78 46 46 46 22 22 22
44460 -137 92 6 210 162 10 239 182 13 238 190 10
44461 -238 202 15 241 208 19 246 215 20 246 215 20
44462 -241 208 19 203 166 17 185 133 11 210 150 10
44463 -216 158 10 210 150 10 102 78 10 2 2 6
44464 - 6 6 6 54 54 54 14 14 14 2 2 6
44465 - 2 2 6 62 62 62 74 74 74 30 30 30
44466 - 10 10 10 0 0 0 0 0 0 0 0 0
44467 - 0 0 0 0 0 0 0 0 0 0 0 0
44468 - 0 0 0 0 0 0 0 0 0 0 0 0
44469 - 0 0 0 0 0 0 0 0 0 0 0 0
44470 - 0 0 0 0 0 0 0 0 0 0 0 0
44471 - 0 0 0 0 0 0 0 0 0 0 0 0
44472 - 0 0 0 0 0 0 0 0 0 0 0 0
44473 - 0 0 0 0 0 0 0 0 0 0 0 0
44474 - 0 0 0 0 0 0 0 0 0 0 0 0
44475 - 0 0 0 0 0 0 0 0 0 0 0 0
44476 - 0 0 0 0 0 0 0 0 0 0 0 0
44477 - 0 0 0 0 0 0 0 0 0 0 0 0
44478 - 0 0 0 0 0 0 0 0 0 10 10 10
44479 - 34 34 34 78 78 78 50 50 50 6 6 6
44480 - 94 70 30 139 102 15 190 146 13 226 184 13
44481 -232 200 30 232 195 16 215 174 15 190 146 13
44482 -168 122 10 192 133 9 210 150 10 213 154 11
44483 -202 150 34 182 157 106 101 98 89 2 2 6
44484 - 2 2 6 78 78 78 116 116 116 58 58 58
44485 - 2 2 6 22 22 22 90 90 90 46 46 46
44486 - 18 18 18 6 6 6 0 0 0 0 0 0
44487 - 0 0 0 0 0 0 0 0 0 0 0 0
44488 - 0 0 0 0 0 0 0 0 0 0 0 0
44489 - 0 0 0 0 0 0 0 0 0 0 0 0
44490 - 0 0 0 0 0 0 0 0 0 0 0 0
44491 - 0 0 0 0 0 0 0 0 0 0 0 0
44492 - 0 0 0 0 0 0 0 0 0 0 0 0
44493 - 0 0 0 0 0 0 0 0 0 0 0 0
44494 - 0 0 0 0 0 0 0 0 0 0 0 0
44495 - 0 0 0 0 0 0 0 0 0 0 0 0
44496 - 0 0 0 0 0 0 0 0 0 0 0 0
44497 - 0 0 0 0 0 0 0 0 0 0 0 0
44498 - 0 0 0 0 0 0 0 0 0 10 10 10
44499 - 38 38 38 86 86 86 50 50 50 6 6 6
44500 -128 128 128 174 154 114 156 107 11 168 122 10
44501 -198 155 10 184 144 12 197 138 11 200 144 11
44502 -206 145 10 206 145 10 197 138 11 188 164 115
44503 -195 195 195 198 198 198 174 174 174 14 14 14
44504 - 2 2 6 22 22 22 116 116 116 116 116 116
44505 - 22 22 22 2 2 6 74 74 74 70 70 70
44506 - 30 30 30 10 10 10 0 0 0 0 0 0
44507 - 0 0 0 0 0 0 0 0 0 0 0 0
44508 - 0 0 0 0 0 0 0 0 0 0 0 0
44509 - 0 0 0 0 0 0 0 0 0 0 0 0
44510 - 0 0 0 0 0 0 0 0 0 0 0 0
44511 - 0 0 0 0 0 0 0 0 0 0 0 0
44512 - 0 0 0 0 0 0 0 0 0 0 0 0
44513 - 0 0 0 0 0 0 0 0 0 0 0 0
44514 - 0 0 0 0 0 0 0 0 0 0 0 0
44515 - 0 0 0 0 0 0 0 0 0 0 0 0
44516 - 0 0 0 0 0 0 0 0 0 0 0 0
44517 - 0 0 0 0 0 0 0 0 0 0 0 0
44518 - 0 0 0 0 0 0 6 6 6 18 18 18
44519 - 50 50 50 101 101 101 26 26 26 10 10 10
44520 -138 138 138 190 190 190 174 154 114 156 107 11
44521 -197 138 11 200 144 11 197 138 11 192 133 9
44522 -180 123 7 190 142 34 190 178 144 187 187 187
44523 -202 202 202 221 221 221 214 214 214 66 66 66
44524 - 2 2 6 2 2 6 50 50 50 62 62 62
44525 - 6 6 6 2 2 6 10 10 10 90 90 90
44526 - 50 50 50 18 18 18 6 6 6 0 0 0
44527 - 0 0 0 0 0 0 0 0 0 0 0 0
44528 - 0 0 0 0 0 0 0 0 0 0 0 0
44529 - 0 0 0 0 0 0 0 0 0 0 0 0
44530 - 0 0 0 0 0 0 0 0 0 0 0 0
44531 - 0 0 0 0 0 0 0 0 0 0 0 0
44532 - 0 0 0 0 0 0 0 0 0 0 0 0
44533 - 0 0 0 0 0 0 0 0 0 0 0 0
44534 - 0 0 0 0 0 0 0 0 0 0 0 0
44535 - 0 0 0 0 0 0 0 0 0 0 0 0
44536 - 0 0 0 0 0 0 0 0 0 0 0 0
44537 - 0 0 0 0 0 0 0 0 0 0 0 0
44538 - 0 0 0 0 0 0 10 10 10 34 34 34
44539 - 74 74 74 74 74 74 2 2 6 6 6 6
44540 -144 144 144 198 198 198 190 190 190 178 166 146
44541 -154 121 60 156 107 11 156 107 11 168 124 44
44542 -174 154 114 187 187 187 190 190 190 210 210 210
44543 -246 246 246 253 253 253 253 253 253 182 182 182
44544 - 6 6 6 2 2 6 2 2 6 2 2 6
44545 - 2 2 6 2 2 6 2 2 6 62 62 62
44546 - 74 74 74 34 34 34 14 14 14 0 0 0
44547 - 0 0 0 0 0 0 0 0 0 0 0 0
44548 - 0 0 0 0 0 0 0 0 0 0 0 0
44549 - 0 0 0 0 0 0 0 0 0 0 0 0
44550 - 0 0 0 0 0 0 0 0 0 0 0 0
44551 - 0 0 0 0 0 0 0 0 0 0 0 0
44552 - 0 0 0 0 0 0 0 0 0 0 0 0
44553 - 0 0 0 0 0 0 0 0 0 0 0 0
44554 - 0 0 0 0 0 0 0 0 0 0 0 0
44555 - 0 0 0 0 0 0 0 0 0 0 0 0
44556 - 0 0 0 0 0 0 0 0 0 0 0 0
44557 - 0 0 0 0 0 0 0 0 0 0 0 0
44558 - 0 0 0 10 10 10 22 22 22 54 54 54
44559 - 94 94 94 18 18 18 2 2 6 46 46 46
44560 -234 234 234 221 221 221 190 190 190 190 190 190
44561 -190 190 190 187 187 187 187 187 187 190 190 190
44562 -190 190 190 195 195 195 214 214 214 242 242 242
44563 -253 253 253 253 253 253 253 253 253 253 253 253
44564 - 82 82 82 2 2 6 2 2 6 2 2 6
44565 - 2 2 6 2 2 6 2 2 6 14 14 14
44566 - 86 86 86 54 54 54 22 22 22 6 6 6
44567 - 0 0 0 0 0 0 0 0 0 0 0 0
44568 - 0 0 0 0 0 0 0 0 0 0 0 0
44569 - 0 0 0 0 0 0 0 0 0 0 0 0
44570 - 0 0 0 0 0 0 0 0 0 0 0 0
44571 - 0 0 0 0 0 0 0 0 0 0 0 0
44572 - 0 0 0 0 0 0 0 0 0 0 0 0
44573 - 0 0 0 0 0 0 0 0 0 0 0 0
44574 - 0 0 0 0 0 0 0 0 0 0 0 0
44575 - 0 0 0 0 0 0 0 0 0 0 0 0
44576 - 0 0 0 0 0 0 0 0 0 0 0 0
44577 - 0 0 0 0 0 0 0 0 0 0 0 0
44578 - 6 6 6 18 18 18 46 46 46 90 90 90
44579 - 46 46 46 18 18 18 6 6 6 182 182 182
44580 -253 253 253 246 246 246 206 206 206 190 190 190
44581 -190 190 190 190 190 190 190 190 190 190 190 190
44582 -206 206 206 231 231 231 250 250 250 253 253 253
44583 -253 253 253 253 253 253 253 253 253 253 253 253
44584 -202 202 202 14 14 14 2 2 6 2 2 6
44585 - 2 2 6 2 2 6 2 2 6 2 2 6
44586 - 42 42 42 86 86 86 42 42 42 18 18 18
44587 - 6 6 6 0 0 0 0 0 0 0 0 0
44588 - 0 0 0 0 0 0 0 0 0 0 0 0
44589 - 0 0 0 0 0 0 0 0 0 0 0 0
44590 - 0 0 0 0 0 0 0 0 0 0 0 0
44591 - 0 0 0 0 0 0 0 0 0 0 0 0
44592 - 0 0 0 0 0 0 0 0 0 0 0 0
44593 - 0 0 0 0 0 0 0 0 0 0 0 0
44594 - 0 0 0 0 0 0 0 0 0 0 0 0
44595 - 0 0 0 0 0 0 0 0 0 0 0 0
44596 - 0 0 0 0 0 0 0 0 0 0 0 0
44597 - 0 0 0 0 0 0 0 0 0 6 6 6
44598 - 14 14 14 38 38 38 74 74 74 66 66 66
44599 - 2 2 6 6 6 6 90 90 90 250 250 250
44600 -253 253 253 253 253 253 238 238 238 198 198 198
44601 -190 190 190 190 190 190 195 195 195 221 221 221
44602 -246 246 246 253 253 253 253 253 253 253 253 253
44603 -253 253 253 253 253 253 253 253 253 253 253 253
44604 -253 253 253 82 82 82 2 2 6 2 2 6
44605 - 2 2 6 2 2 6 2 2 6 2 2 6
44606 - 2 2 6 78 78 78 70 70 70 34 34 34
44607 - 14 14 14 6 6 6 0 0 0 0 0 0
44608 - 0 0 0 0 0 0 0 0 0 0 0 0
44609 - 0 0 0 0 0 0 0 0 0 0 0 0
44610 - 0 0 0 0 0 0 0 0 0 0 0 0
44611 - 0 0 0 0 0 0 0 0 0 0 0 0
44612 - 0 0 0 0 0 0 0 0 0 0 0 0
44613 - 0 0 0 0 0 0 0 0 0 0 0 0
44614 - 0 0 0 0 0 0 0 0 0 0 0 0
44615 - 0 0 0 0 0 0 0 0 0 0 0 0
44616 - 0 0 0 0 0 0 0 0 0 0 0 0
44617 - 0 0 0 0 0 0 0 0 0 14 14 14
44618 - 34 34 34 66 66 66 78 78 78 6 6 6
44619 - 2 2 6 18 18 18 218 218 218 253 253 253
44620 -253 253 253 253 253 253 253 253 253 246 246 246
44621 -226 226 226 231 231 231 246 246 246 253 253 253
44622 -253 253 253 253 253 253 253 253 253 253 253 253
44623 -253 253 253 253 253 253 253 253 253 253 253 253
44624 -253 253 253 178 178 178 2 2 6 2 2 6
44625 - 2 2 6 2 2 6 2 2 6 2 2 6
44626 - 2 2 6 18 18 18 90 90 90 62 62 62
44627 - 30 30 30 10 10 10 0 0 0 0 0 0
44628 - 0 0 0 0 0 0 0 0 0 0 0 0
44629 - 0 0 0 0 0 0 0 0 0 0 0 0
44630 - 0 0 0 0 0 0 0 0 0 0 0 0
44631 - 0 0 0 0 0 0 0 0 0 0 0 0
44632 - 0 0 0 0 0 0 0 0 0 0 0 0
44633 - 0 0 0 0 0 0 0 0 0 0 0 0
44634 - 0 0 0 0 0 0 0 0 0 0 0 0
44635 - 0 0 0 0 0 0 0 0 0 0 0 0
44636 - 0 0 0 0 0 0 0 0 0 0 0 0
44637 - 0 0 0 0 0 0 10 10 10 26 26 26
44638 - 58 58 58 90 90 90 18 18 18 2 2 6
44639 - 2 2 6 110 110 110 253 253 253 253 253 253
44640 -253 253 253 253 253 253 253 253 253 253 253 253
44641 -250 250 250 253 253 253 253 253 253 253 253 253
44642 -253 253 253 253 253 253 253 253 253 253 253 253
44643 -253 253 253 253 253 253 253 253 253 253 253 253
44644 -253 253 253 231 231 231 18 18 18 2 2 6
44645 - 2 2 6 2 2 6 2 2 6 2 2 6
44646 - 2 2 6 2 2 6 18 18 18 94 94 94
44647 - 54 54 54 26 26 26 10 10 10 0 0 0
44648 - 0 0 0 0 0 0 0 0 0 0 0 0
44649 - 0 0 0 0 0 0 0 0 0 0 0 0
44650 - 0 0 0 0 0 0 0 0 0 0 0 0
44651 - 0 0 0 0 0 0 0 0 0 0 0 0
44652 - 0 0 0 0 0 0 0 0 0 0 0 0
44653 - 0 0 0 0 0 0 0 0 0 0 0 0
44654 - 0 0 0 0 0 0 0 0 0 0 0 0
44655 - 0 0 0 0 0 0 0 0 0 0 0 0
44656 - 0 0 0 0 0 0 0 0 0 0 0 0
44657 - 0 0 0 6 6 6 22 22 22 50 50 50
44658 - 90 90 90 26 26 26 2 2 6 2 2 6
44659 - 14 14 14 195 195 195 250 250 250 253 253 253
44660 -253 253 253 253 253 253 253 253 253 253 253 253
44661 -253 253 253 253 253 253 253 253 253 253 253 253
44662 -253 253 253 253 253 253 253 253 253 253 253 253
44663 -253 253 253 253 253 253 253 253 253 253 253 253
44664 -250 250 250 242 242 242 54 54 54 2 2 6
44665 - 2 2 6 2 2 6 2 2 6 2 2 6
44666 - 2 2 6 2 2 6 2 2 6 38 38 38
44667 - 86 86 86 50 50 50 22 22 22 6 6 6
44668 - 0 0 0 0 0 0 0 0 0 0 0 0
44669 - 0 0 0 0 0 0 0 0 0 0 0 0
44670 - 0 0 0 0 0 0 0 0 0 0 0 0
44671 - 0 0 0 0 0 0 0 0 0 0 0 0
44672 - 0 0 0 0 0 0 0 0 0 0 0 0
44673 - 0 0 0 0 0 0 0 0 0 0 0 0
44674 - 0 0 0 0 0 0 0 0 0 0 0 0
44675 - 0 0 0 0 0 0 0 0 0 0 0 0
44676 - 0 0 0 0 0 0 0 0 0 0 0 0
44677 - 6 6 6 14 14 14 38 38 38 82 82 82
44678 - 34 34 34 2 2 6 2 2 6 2 2 6
44679 - 42 42 42 195 195 195 246 246 246 253 253 253
44680 -253 253 253 253 253 253 253 253 253 250 250 250
44681 -242 242 242 242 242 242 250 250 250 253 253 253
44682 -253 253 253 253 253 253 253 253 253 253 253 253
44683 -253 253 253 250 250 250 246 246 246 238 238 238
44684 -226 226 226 231 231 231 101 101 101 6 6 6
44685 - 2 2 6 2 2 6 2 2 6 2 2 6
44686 - 2 2 6 2 2 6 2 2 6 2 2 6
44687 - 38 38 38 82 82 82 42 42 42 14 14 14
44688 - 6 6 6 0 0 0 0 0 0 0 0 0
44689 - 0 0 0 0 0 0 0 0 0 0 0 0
44690 - 0 0 0 0 0 0 0 0 0 0 0 0
44691 - 0 0 0 0 0 0 0 0 0 0 0 0
44692 - 0 0 0 0 0 0 0 0 0 0 0 0
44693 - 0 0 0 0 0 0 0 0 0 0 0 0
44694 - 0 0 0 0 0 0 0 0 0 0 0 0
44695 - 0 0 0 0 0 0 0 0 0 0 0 0
44696 - 0 0 0 0 0 0 0 0 0 0 0 0
44697 - 10 10 10 26 26 26 62 62 62 66 66 66
44698 - 2 2 6 2 2 6 2 2 6 6 6 6
44699 - 70 70 70 170 170 170 206 206 206 234 234 234
44700 -246 246 246 250 250 250 250 250 250 238 238 238
44701 -226 226 226 231 231 231 238 238 238 250 250 250
44702 -250 250 250 250 250 250 246 246 246 231 231 231
44703 -214 214 214 206 206 206 202 202 202 202 202 202
44704 -198 198 198 202 202 202 182 182 182 18 18 18
44705 - 2 2 6 2 2 6 2 2 6 2 2 6
44706 - 2 2 6 2 2 6 2 2 6 2 2 6
44707 - 2 2 6 62 62 62 66 66 66 30 30 30
44708 - 10 10 10 0 0 0 0 0 0 0 0 0
44709 - 0 0 0 0 0 0 0 0 0 0 0 0
44710 - 0 0 0 0 0 0 0 0 0 0 0 0
44711 - 0 0 0 0 0 0 0 0 0 0 0 0
44712 - 0 0 0 0 0 0 0 0 0 0 0 0
44713 - 0 0 0 0 0 0 0 0 0 0 0 0
44714 - 0 0 0 0 0 0 0 0 0 0 0 0
44715 - 0 0 0 0 0 0 0 0 0 0 0 0
44716 - 0 0 0 0 0 0 0 0 0 0 0 0
44717 - 14 14 14 42 42 42 82 82 82 18 18 18
44718 - 2 2 6 2 2 6 2 2 6 10 10 10
44719 - 94 94 94 182 182 182 218 218 218 242 242 242
44720 -250 250 250 253 253 253 253 253 253 250 250 250
44721 -234 234 234 253 253 253 253 253 253 253 253 253
44722 -253 253 253 253 253 253 253 253 253 246 246 246
44723 -238 238 238 226 226 226 210 210 210 202 202 202
44724 -195 195 195 195 195 195 210 210 210 158 158 158
44725 - 6 6 6 14 14 14 50 50 50 14 14 14
44726 - 2 2 6 2 2 6 2 2 6 2 2 6
44727 - 2 2 6 6 6 6 86 86 86 46 46 46
44728 - 18 18 18 6 6 6 0 0 0 0 0 0
44729 - 0 0 0 0 0 0 0 0 0 0 0 0
44730 - 0 0 0 0 0 0 0 0 0 0 0 0
44731 - 0 0 0 0 0 0 0 0 0 0 0 0
44732 - 0 0 0 0 0 0 0 0 0 0 0 0
44733 - 0 0 0 0 0 0 0 0 0 0 0 0
44734 - 0 0 0 0 0 0 0 0 0 0 0 0
44735 - 0 0 0 0 0 0 0 0 0 0 0 0
44736 - 0 0 0 0 0 0 0 0 0 6 6 6
44737 - 22 22 22 54 54 54 70 70 70 2 2 6
44738 - 2 2 6 10 10 10 2 2 6 22 22 22
44739 -166 166 166 231 231 231 250 250 250 253 253 253
44740 -253 253 253 253 253 253 253 253 253 250 250 250
44741 -242 242 242 253 253 253 253 253 253 253 253 253
44742 -253 253 253 253 253 253 253 253 253 253 253 253
44743 -253 253 253 253 253 253 253 253 253 246 246 246
44744 -231 231 231 206 206 206 198 198 198 226 226 226
44745 - 94 94 94 2 2 6 6 6 6 38 38 38
44746 - 30 30 30 2 2 6 2 2 6 2 2 6
44747 - 2 2 6 2 2 6 62 62 62 66 66 66
44748 - 26 26 26 10 10 10 0 0 0 0 0 0
44749 - 0 0 0 0 0 0 0 0 0 0 0 0
44750 - 0 0 0 0 0 0 0 0 0 0 0 0
44751 - 0 0 0 0 0 0 0 0 0 0 0 0
44752 - 0 0 0 0 0 0 0 0 0 0 0 0
44753 - 0 0 0 0 0 0 0 0 0 0 0 0
44754 - 0 0 0 0 0 0 0 0 0 0 0 0
44755 - 0 0 0 0 0 0 0 0 0 0 0 0
44756 - 0 0 0 0 0 0 0 0 0 10 10 10
44757 - 30 30 30 74 74 74 50 50 50 2 2 6
44758 - 26 26 26 26 26 26 2 2 6 106 106 106
44759 -238 238 238 253 253 253 253 253 253 253 253 253
44760 -253 253 253 253 253 253 253 253 253 253 253 253
44761 -253 253 253 253 253 253 253 253 253 253 253 253
44762 -253 253 253 253 253 253 253 253 253 253 253 253
44763 -253 253 253 253 253 253 253 253 253 253 253 253
44764 -253 253 253 246 246 246 218 218 218 202 202 202
44765 -210 210 210 14 14 14 2 2 6 2 2 6
44766 - 30 30 30 22 22 22 2 2 6 2 2 6
44767 - 2 2 6 2 2 6 18 18 18 86 86 86
44768 - 42 42 42 14 14 14 0 0 0 0 0 0
44769 - 0 0 0 0 0 0 0 0 0 0 0 0
44770 - 0 0 0 0 0 0 0 0 0 0 0 0
44771 - 0 0 0 0 0 0 0 0 0 0 0 0
44772 - 0 0 0 0 0 0 0 0 0 0 0 0
44773 - 0 0 0 0 0 0 0 0 0 0 0 0
44774 - 0 0 0 0 0 0 0 0 0 0 0 0
44775 - 0 0 0 0 0 0 0 0 0 0 0 0
44776 - 0 0 0 0 0 0 0 0 0 14 14 14
44777 - 42 42 42 90 90 90 22 22 22 2 2 6
44778 - 42 42 42 2 2 6 18 18 18 218 218 218
44779 -253 253 253 253 253 253 253 253 253 253 253 253
44780 -253 253 253 253 253 253 253 253 253 253 253 253
44781 -253 253 253 253 253 253 253 253 253 253 253 253
44782 -253 253 253 253 253 253 253 253 253 253 253 253
44783 -253 253 253 253 253 253 253 253 253 253 253 253
44784 -253 253 253 253 253 253 250 250 250 221 221 221
44785 -218 218 218 101 101 101 2 2 6 14 14 14
44786 - 18 18 18 38 38 38 10 10 10 2 2 6
44787 - 2 2 6 2 2 6 2 2 6 78 78 78
44788 - 58 58 58 22 22 22 6 6 6 0 0 0
44789 - 0 0 0 0 0 0 0 0 0 0 0 0
44790 - 0 0 0 0 0 0 0 0 0 0 0 0
44791 - 0 0 0 0 0 0 0 0 0 0 0 0
44792 - 0 0 0 0 0 0 0 0 0 0 0 0
44793 - 0 0 0 0 0 0 0 0 0 0 0 0
44794 - 0 0 0 0 0 0 0 0 0 0 0 0
44795 - 0 0 0 0 0 0 0 0 0 0 0 0
44796 - 0 0 0 0 0 0 6 6 6 18 18 18
44797 - 54 54 54 82 82 82 2 2 6 26 26 26
44798 - 22 22 22 2 2 6 123 123 123 253 253 253
44799 -253 253 253 253 253 253 253 253 253 253 253 253
44800 -253 253 253 253 253 253 253 253 253 253 253 253
44801 -253 253 253 253 253 253 253 253 253 253 253 253
44802 -253 253 253 253 253 253 253 253 253 253 253 253
44803 -253 253 253 253 253 253 253 253 253 253 253 253
44804 -253 253 253 253 253 253 253 253 253 250 250 250
44805 -238 238 238 198 198 198 6 6 6 38 38 38
44806 - 58 58 58 26 26 26 38 38 38 2 2 6
44807 - 2 2 6 2 2 6 2 2 6 46 46 46
44808 - 78 78 78 30 30 30 10 10 10 0 0 0
44809 - 0 0 0 0 0 0 0 0 0 0 0 0
44810 - 0 0 0 0 0 0 0 0 0 0 0 0
44811 - 0 0 0 0 0 0 0 0 0 0 0 0
44812 - 0 0 0 0 0 0 0 0 0 0 0 0
44813 - 0 0 0 0 0 0 0 0 0 0 0 0
44814 - 0 0 0 0 0 0 0 0 0 0 0 0
44815 - 0 0 0 0 0 0 0 0 0 0 0 0
44816 - 0 0 0 0 0 0 10 10 10 30 30 30
44817 - 74 74 74 58 58 58 2 2 6 42 42 42
44818 - 2 2 6 22 22 22 231 231 231 253 253 253
44819 -253 253 253 253 253 253 253 253 253 253 253 253
44820 -253 253 253 253 253 253 253 253 253 250 250 250
44821 -253 253 253 253 253 253 253 253 253 253 253 253
44822 -253 253 253 253 253 253 253 253 253 253 253 253
44823 -253 253 253 253 253 253 253 253 253 253 253 253
44824 -253 253 253 253 253 253 253 253 253 253 253 253
44825 -253 253 253 246 246 246 46 46 46 38 38 38
44826 - 42 42 42 14 14 14 38 38 38 14 14 14
44827 - 2 2 6 2 2 6 2 2 6 6 6 6
44828 - 86 86 86 46 46 46 14 14 14 0 0 0
44829 - 0 0 0 0 0 0 0 0 0 0 0 0
44830 - 0 0 0 0 0 0 0 0 0 0 0 0
44831 - 0 0 0 0 0 0 0 0 0 0 0 0
44832 - 0 0 0 0 0 0 0 0 0 0 0 0
44833 - 0 0 0 0 0 0 0 0 0 0 0 0
44834 - 0 0 0 0 0 0 0 0 0 0 0 0
44835 - 0 0 0 0 0 0 0 0 0 0 0 0
44836 - 0 0 0 6 6 6 14 14 14 42 42 42
44837 - 90 90 90 18 18 18 18 18 18 26 26 26
44838 - 2 2 6 116 116 116 253 253 253 253 253 253
44839 -253 253 253 253 253 253 253 253 253 253 253 253
44840 -253 253 253 253 253 253 250 250 250 238 238 238
44841 -253 253 253 253 253 253 253 253 253 253 253 253
44842 -253 253 253 253 253 253 253 253 253 253 253 253
44843 -253 253 253 253 253 253 253 253 253 253 253 253
44844 -253 253 253 253 253 253 253 253 253 253 253 253
44845 -253 253 253 253 253 253 94 94 94 6 6 6
44846 - 2 2 6 2 2 6 10 10 10 34 34 34
44847 - 2 2 6 2 2 6 2 2 6 2 2 6
44848 - 74 74 74 58 58 58 22 22 22 6 6 6
44849 - 0 0 0 0 0 0 0 0 0 0 0 0
44850 - 0 0 0 0 0 0 0 0 0 0 0 0
44851 - 0 0 0 0 0 0 0 0 0 0 0 0
44852 - 0 0 0 0 0 0 0 0 0 0 0 0
44853 - 0 0 0 0 0 0 0 0 0 0 0 0
44854 - 0 0 0 0 0 0 0 0 0 0 0 0
44855 - 0 0 0 0 0 0 0 0 0 0 0 0
44856 - 0 0 0 10 10 10 26 26 26 66 66 66
44857 - 82 82 82 2 2 6 38 38 38 6 6 6
44858 - 14 14 14 210 210 210 253 253 253 253 253 253
44859 -253 253 253 253 253 253 253 253 253 253 253 253
44860 -253 253 253 253 253 253 246 246 246 242 242 242
44861 -253 253 253 253 253 253 253 253 253 253 253 253
44862 -253 253 253 253 253 253 253 253 253 253 253 253
44863 -253 253 253 253 253 253 253 253 253 253 253 253
44864 -253 253 253 253 253 253 253 253 253 253 253 253
44865 -253 253 253 253 253 253 144 144 144 2 2 6
44866 - 2 2 6 2 2 6 2 2 6 46 46 46
44867 - 2 2 6 2 2 6 2 2 6 2 2 6
44868 - 42 42 42 74 74 74 30 30 30 10 10 10
44869 - 0 0 0 0 0 0 0 0 0 0 0 0
44870 - 0 0 0 0 0 0 0 0 0 0 0 0
44871 - 0 0 0 0 0 0 0 0 0 0 0 0
44872 - 0 0 0 0 0 0 0 0 0 0 0 0
44873 - 0 0 0 0 0 0 0 0 0 0 0 0
44874 - 0 0 0 0 0 0 0 0 0 0 0 0
44875 - 0 0 0 0 0 0 0 0 0 0 0 0
44876 - 6 6 6 14 14 14 42 42 42 90 90 90
44877 - 26 26 26 6 6 6 42 42 42 2 2 6
44878 - 74 74 74 250 250 250 253 253 253 253 253 253
44879 -253 253 253 253 253 253 253 253 253 253 253 253
44880 -253 253 253 253 253 253 242 242 242 242 242 242
44881 -253 253 253 253 253 253 253 253 253 253 253 253
44882 -253 253 253 253 253 253 253 253 253 253 253 253
44883 -253 253 253 253 253 253 253 253 253 253 253 253
44884 -253 253 253 253 253 253 253 253 253 253 253 253
44885 -253 253 253 253 253 253 182 182 182 2 2 6
44886 - 2 2 6 2 2 6 2 2 6 46 46 46
44887 - 2 2 6 2 2 6 2 2 6 2 2 6
44888 - 10 10 10 86 86 86 38 38 38 10 10 10
44889 - 0 0 0 0 0 0 0 0 0 0 0 0
44890 - 0 0 0 0 0 0 0 0 0 0 0 0
44891 - 0 0 0 0 0 0 0 0 0 0 0 0
44892 - 0 0 0 0 0 0 0 0 0 0 0 0
44893 - 0 0 0 0 0 0 0 0 0 0 0 0
44894 - 0 0 0 0 0 0 0 0 0 0 0 0
44895 - 0 0 0 0 0 0 0 0 0 0 0 0
44896 - 10 10 10 26 26 26 66 66 66 82 82 82
44897 - 2 2 6 22 22 22 18 18 18 2 2 6
44898 -149 149 149 253 253 253 253 253 253 253 253 253
44899 -253 253 253 253 253 253 253 253 253 253 253 253
44900 -253 253 253 253 253 253 234 234 234 242 242 242
44901 -253 253 253 253 253 253 253 253 253 253 253 253
44902 -253 253 253 253 253 253 253 253 253 253 253 253
44903 -253 253 253 253 253 253 253 253 253 253 253 253
44904 -253 253 253 253 253 253 253 253 253 253 253 253
44905 -253 253 253 253 253 253 206 206 206 2 2 6
44906 - 2 2 6 2 2 6 2 2 6 38 38 38
44907 - 2 2 6 2 2 6 2 2 6 2 2 6
44908 - 6 6 6 86 86 86 46 46 46 14 14 14
44909 - 0 0 0 0 0 0 0 0 0 0 0 0
44910 - 0 0 0 0 0 0 0 0 0 0 0 0
44911 - 0 0 0 0 0 0 0 0 0 0 0 0
44912 - 0 0 0 0 0 0 0 0 0 0 0 0
44913 - 0 0 0 0 0 0 0 0 0 0 0 0
44914 - 0 0 0 0 0 0 0 0 0 0 0 0
44915 - 0 0 0 0 0 0 0 0 0 6 6 6
44916 - 18 18 18 46 46 46 86 86 86 18 18 18
44917 - 2 2 6 34 34 34 10 10 10 6 6 6
44918 -210 210 210 253 253 253 253 253 253 253 253 253
44919 -253 253 253 253 253 253 253 253 253 253 253 253
44920 -253 253 253 253 253 253 234 234 234 242 242 242
44921 -253 253 253 253 253 253 253 253 253 253 253 253
44922 -253 253 253 253 253 253 253 253 253 253 253 253
44923 -253 253 253 253 253 253 253 253 253 253 253 253
44924 -253 253 253 253 253 253 253 253 253 253 253 253
44925 -253 253 253 253 253 253 221 221 221 6 6 6
44926 - 2 2 6 2 2 6 6 6 6 30 30 30
44927 - 2 2 6 2 2 6 2 2 6 2 2 6
44928 - 2 2 6 82 82 82 54 54 54 18 18 18
44929 - 6 6 6 0 0 0 0 0 0 0 0 0
44930 - 0 0 0 0 0 0 0 0 0 0 0 0
44931 - 0 0 0 0 0 0 0 0 0 0 0 0
44932 - 0 0 0 0 0 0 0 0 0 0 0 0
44933 - 0 0 0 0 0 0 0 0 0 0 0 0
44934 - 0 0 0 0 0 0 0 0 0 0 0 0
44935 - 0 0 0 0 0 0 0 0 0 10 10 10
44936 - 26 26 26 66 66 66 62 62 62 2 2 6
44937 - 2 2 6 38 38 38 10 10 10 26 26 26
44938 -238 238 238 253 253 253 253 253 253 253 253 253
44939 -253 253 253 253 253 253 253 253 253 253 253 253
44940 -253 253 253 253 253 253 231 231 231 238 238 238
44941 -253 253 253 253 253 253 253 253 253 253 253 253
44942 -253 253 253 253 253 253 253 253 253 253 253 253
44943 -253 253 253 253 253 253 253 253 253 253 253 253
44944 -253 253 253 253 253 253 253 253 253 253 253 253
44945 -253 253 253 253 253 253 231 231 231 6 6 6
44946 - 2 2 6 2 2 6 10 10 10 30 30 30
44947 - 2 2 6 2 2 6 2 2 6 2 2 6
44948 - 2 2 6 66 66 66 58 58 58 22 22 22
44949 - 6 6 6 0 0 0 0 0 0 0 0 0
44950 - 0 0 0 0 0 0 0 0 0 0 0 0
44951 - 0 0 0 0 0 0 0 0 0 0 0 0
44952 - 0 0 0 0 0 0 0 0 0 0 0 0
44953 - 0 0 0 0 0 0 0 0 0 0 0 0
44954 - 0 0 0 0 0 0 0 0 0 0 0 0
44955 - 0 0 0 0 0 0 0 0 0 10 10 10
44956 - 38 38 38 78 78 78 6 6 6 2 2 6
44957 - 2 2 6 46 46 46 14 14 14 42 42 42
44958 -246 246 246 253 253 253 253 253 253 253 253 253
44959 -253 253 253 253 253 253 253 253 253 253 253 253
44960 -253 253 253 253 253 253 231 231 231 242 242 242
44961 -253 253 253 253 253 253 253 253 253 253 253 253
44962 -253 253 253 253 253 253 253 253 253 253 253 253
44963 -253 253 253 253 253 253 253 253 253 253 253 253
44964 -253 253 253 253 253 253 253 253 253 253 253 253
44965 -253 253 253 253 253 253 234 234 234 10 10 10
44966 - 2 2 6 2 2 6 22 22 22 14 14 14
44967 - 2 2 6 2 2 6 2 2 6 2 2 6
44968 - 2 2 6 66 66 66 62 62 62 22 22 22
44969 - 6 6 6 0 0 0 0 0 0 0 0 0
44970 - 0 0 0 0 0 0 0 0 0 0 0 0
44971 - 0 0 0 0 0 0 0 0 0 0 0 0
44972 - 0 0 0 0 0 0 0 0 0 0 0 0
44973 - 0 0 0 0 0 0 0 0 0 0 0 0
44974 - 0 0 0 0 0 0 0 0 0 0 0 0
44975 - 0 0 0 0 0 0 6 6 6 18 18 18
44976 - 50 50 50 74 74 74 2 2 6 2 2 6
44977 - 14 14 14 70 70 70 34 34 34 62 62 62
44978 -250 250 250 253 253 253 253 253 253 253 253 253
44979 -253 253 253 253 253 253 253 253 253 253 253 253
44980 -253 253 253 253 253 253 231 231 231 246 246 246
44981 -253 253 253 253 253 253 253 253 253 253 253 253
44982 -253 253 253 253 253 253 253 253 253 253 253 253
44983 -253 253 253 253 253 253 253 253 253 253 253 253
44984 -253 253 253 253 253 253 253 253 253 253 253 253
44985 -253 253 253 253 253 253 234 234 234 14 14 14
44986 - 2 2 6 2 2 6 30 30 30 2 2 6
44987 - 2 2 6 2 2 6 2 2 6 2 2 6
44988 - 2 2 6 66 66 66 62 62 62 22 22 22
44989 - 6 6 6 0 0 0 0 0 0 0 0 0
44990 - 0 0 0 0 0 0 0 0 0 0 0 0
44991 - 0 0 0 0 0 0 0 0 0 0 0 0
44992 - 0 0 0 0 0 0 0 0 0 0 0 0
44993 - 0 0 0 0 0 0 0 0 0 0 0 0
44994 - 0 0 0 0 0 0 0 0 0 0 0 0
44995 - 0 0 0 0 0 0 6 6 6 18 18 18
44996 - 54 54 54 62 62 62 2 2 6 2 2 6
44997 - 2 2 6 30 30 30 46 46 46 70 70 70
44998 -250 250 250 253 253 253 253 253 253 253 253 253
44999 -253 253 253 253 253 253 253 253 253 253 253 253
45000 -253 253 253 253 253 253 231 231 231 246 246 246
45001 -253 253 253 253 253 253 253 253 253 253 253 253
45002 -253 253 253 253 253 253 253 253 253 253 253 253
45003 -253 253 253 253 253 253 253 253 253 253 253 253
45004 -253 253 253 253 253 253 253 253 253 253 253 253
45005 -253 253 253 253 253 253 226 226 226 10 10 10
45006 - 2 2 6 6 6 6 30 30 30 2 2 6
45007 - 2 2 6 2 2 6 2 2 6 2 2 6
45008 - 2 2 6 66 66 66 58 58 58 22 22 22
45009 - 6 6 6 0 0 0 0 0 0 0 0 0
45010 - 0 0 0 0 0 0 0 0 0 0 0 0
45011 - 0 0 0 0 0 0 0 0 0 0 0 0
45012 - 0 0 0 0 0 0 0 0 0 0 0 0
45013 - 0 0 0 0 0 0 0 0 0 0 0 0
45014 - 0 0 0 0 0 0 0 0 0 0 0 0
45015 - 0 0 0 0 0 0 6 6 6 22 22 22
45016 - 58 58 58 62 62 62 2 2 6 2 2 6
45017 - 2 2 6 2 2 6 30 30 30 78 78 78
45018 -250 250 250 253 253 253 253 253 253 253 253 253
45019 -253 253 253 253 253 253 253 253 253 253 253 253
45020 -253 253 253 253 253 253 231 231 231 246 246 246
45021 -253 253 253 253 253 253 253 253 253 253 253 253
45022 -253 253 253 253 253 253 253 253 253 253 253 253
45023 -253 253 253 253 253 253 253 253 253 253 253 253
45024 -253 253 253 253 253 253 253 253 253 253 253 253
45025 -253 253 253 253 253 253 206 206 206 2 2 6
45026 - 22 22 22 34 34 34 18 14 6 22 22 22
45027 - 26 26 26 18 18 18 6 6 6 2 2 6
45028 - 2 2 6 82 82 82 54 54 54 18 18 18
45029 - 6 6 6 0 0 0 0 0 0 0 0 0
45030 - 0 0 0 0 0 0 0 0 0 0 0 0
45031 - 0 0 0 0 0 0 0 0 0 0 0 0
45032 - 0 0 0 0 0 0 0 0 0 0 0 0
45033 - 0 0 0 0 0 0 0 0 0 0 0 0
45034 - 0 0 0 0 0 0 0 0 0 0 0 0
45035 - 0 0 0 0 0 0 6 6 6 26 26 26
45036 - 62 62 62 106 106 106 74 54 14 185 133 11
45037 -210 162 10 121 92 8 6 6 6 62 62 62
45038 -238 238 238 253 253 253 253 253 253 253 253 253
45039 -253 253 253 253 253 253 253 253 253 253 253 253
45040 -253 253 253 253 253 253 231 231 231 246 246 246
45041 -253 253 253 253 253 253 253 253 253 253 253 253
45042 -253 253 253 253 253 253 253 253 253 253 253 253
45043 -253 253 253 253 253 253 253 253 253 253 253 253
45044 -253 253 253 253 253 253 253 253 253 253 253 253
45045 -253 253 253 253 253 253 158 158 158 18 18 18
45046 - 14 14 14 2 2 6 2 2 6 2 2 6
45047 - 6 6 6 18 18 18 66 66 66 38 38 38
45048 - 6 6 6 94 94 94 50 50 50 18 18 18
45049 - 6 6 6 0 0 0 0 0 0 0 0 0
45050 - 0 0 0 0 0 0 0 0 0 0 0 0
45051 - 0 0 0 0 0 0 0 0 0 0 0 0
45052 - 0 0 0 0 0 0 0 0 0 0 0 0
45053 - 0 0 0 0 0 0 0 0 0 0 0 0
45054 - 0 0 0 0 0 0 0 0 0 6 6 6
45055 - 10 10 10 10 10 10 18 18 18 38 38 38
45056 - 78 78 78 142 134 106 216 158 10 242 186 14
45057 -246 190 14 246 190 14 156 118 10 10 10 10
45058 - 90 90 90 238 238 238 253 253 253 253 253 253
45059 -253 253 253 253 253 253 253 253 253 253 253 253
45060 -253 253 253 253 253 253 231 231 231 250 250 250
45061 -253 253 253 253 253 253 253 253 253 253 253 253
45062 -253 253 253 253 253 253 253 253 253 253 253 253
45063 -253 253 253 253 253 253 253 253 253 253 253 253
45064 -253 253 253 253 253 253 253 253 253 246 230 190
45065 -238 204 91 238 204 91 181 142 44 37 26 9
45066 - 2 2 6 2 2 6 2 2 6 2 2 6
45067 - 2 2 6 2 2 6 38 38 38 46 46 46
45068 - 26 26 26 106 106 106 54 54 54 18 18 18
45069 - 6 6 6 0 0 0 0 0 0 0 0 0
45070 - 0 0 0 0 0 0 0 0 0 0 0 0
45071 - 0 0 0 0 0 0 0 0 0 0 0 0
45072 - 0 0 0 0 0 0 0 0 0 0 0 0
45073 - 0 0 0 0 0 0 0 0 0 0 0 0
45074 - 0 0 0 6 6 6 14 14 14 22 22 22
45075 - 30 30 30 38 38 38 50 50 50 70 70 70
45076 -106 106 106 190 142 34 226 170 11 242 186 14
45077 -246 190 14 246 190 14 246 190 14 154 114 10
45078 - 6 6 6 74 74 74 226 226 226 253 253 253
45079 -253 253 253 253 253 253 253 253 253 253 253 253
45080 -253 253 253 253 253 253 231 231 231 250 250 250
45081 -253 253 253 253 253 253 253 253 253 253 253 253
45082 -253 253 253 253 253 253 253 253 253 253 253 253
45083 -253 253 253 253 253 253 253 253 253 253 253 253
45084 -253 253 253 253 253 253 253 253 253 228 184 62
45085 -241 196 14 241 208 19 232 195 16 38 30 10
45086 - 2 2 6 2 2 6 2 2 6 2 2 6
45087 - 2 2 6 6 6 6 30 30 30 26 26 26
45088 -203 166 17 154 142 90 66 66 66 26 26 26
45089 - 6 6 6 0 0 0 0 0 0 0 0 0
45090 - 0 0 0 0 0 0 0 0 0 0 0 0
45091 - 0 0 0 0 0 0 0 0 0 0 0 0
45092 - 0 0 0 0 0 0 0 0 0 0 0 0
45093 - 0 0 0 0 0 0 0 0 0 0 0 0
45094 - 6 6 6 18 18 18 38 38 38 58 58 58
45095 - 78 78 78 86 86 86 101 101 101 123 123 123
45096 -175 146 61 210 150 10 234 174 13 246 186 14
45097 -246 190 14 246 190 14 246 190 14 238 190 10
45098 -102 78 10 2 2 6 46 46 46 198 198 198
45099 -253 253 253 253 253 253 253 253 253 253 253 253
45100 -253 253 253 253 253 253 234 234 234 242 242 242
45101 -253 253 253 253 253 253 253 253 253 253 253 253
45102 -253 253 253 253 253 253 253 253 253 253 253 253
45103 -253 253 253 253 253 253 253 253 253 253 253 253
45104 -253 253 253 253 253 253 253 253 253 224 178 62
45105 -242 186 14 241 196 14 210 166 10 22 18 6
45106 - 2 2 6 2 2 6 2 2 6 2 2 6
45107 - 2 2 6 2 2 6 6 6 6 121 92 8
45108 -238 202 15 232 195 16 82 82 82 34 34 34
45109 - 10 10 10 0 0 0 0 0 0 0 0 0
45110 - 0 0 0 0 0 0 0 0 0 0 0 0
45111 - 0 0 0 0 0 0 0 0 0 0 0 0
45112 - 0 0 0 0 0 0 0 0 0 0 0 0
45113 - 0 0 0 0 0 0 0 0 0 0 0 0
45114 - 14 14 14 38 38 38 70 70 70 154 122 46
45115 -190 142 34 200 144 11 197 138 11 197 138 11
45116 -213 154 11 226 170 11 242 186 14 246 190 14
45117 -246 190 14 246 190 14 246 190 14 246 190 14
45118 -225 175 15 46 32 6 2 2 6 22 22 22
45119 -158 158 158 250 250 250 253 253 253 253 253 253
45120 -253 253 253 253 253 253 253 253 253 253 253 253
45121 -253 253 253 253 253 253 253 253 253 253 253 253
45122 -253 253 253 253 253 253 253 253 253 253 253 253
45123 -253 253 253 253 253 253 253 253 253 253 253 253
45124 -253 253 253 250 250 250 242 242 242 224 178 62
45125 -239 182 13 236 186 11 213 154 11 46 32 6
45126 - 2 2 6 2 2 6 2 2 6 2 2 6
45127 - 2 2 6 2 2 6 61 42 6 225 175 15
45128 -238 190 10 236 186 11 112 100 78 42 42 42
45129 - 14 14 14 0 0 0 0 0 0 0 0 0
45130 - 0 0 0 0 0 0 0 0 0 0 0 0
45131 - 0 0 0 0 0 0 0 0 0 0 0 0
45132 - 0 0 0 0 0 0 0 0 0 0 0 0
45133 - 0 0 0 0 0 0 0 0 0 6 6 6
45134 - 22 22 22 54 54 54 154 122 46 213 154 11
45135 -226 170 11 230 174 11 226 170 11 226 170 11
45136 -236 178 12 242 186 14 246 190 14 246 190 14
45137 -246 190 14 246 190 14 246 190 14 246 190 14
45138 -241 196 14 184 144 12 10 10 10 2 2 6
45139 - 6 6 6 116 116 116 242 242 242 253 253 253
45140 -253 253 253 253 253 253 253 253 253 253 253 253
45141 -253 253 253 253 253 253 253 253 253 253 253 253
45142 -253 253 253 253 253 253 253 253 253 253 253 253
45143 -253 253 253 253 253 253 253 253 253 253 253 253
45144 -253 253 253 231 231 231 198 198 198 214 170 54
45145 -236 178 12 236 178 12 210 150 10 137 92 6
45146 - 18 14 6 2 2 6 2 2 6 2 2 6
45147 - 6 6 6 70 47 6 200 144 11 236 178 12
45148 -239 182 13 239 182 13 124 112 88 58 58 58
45149 - 22 22 22 6 6 6 0 0 0 0 0 0
45150 - 0 0 0 0 0 0 0 0 0 0 0 0
45151 - 0 0 0 0 0 0 0 0 0 0 0 0
45152 - 0 0 0 0 0 0 0 0 0 0 0 0
45153 - 0 0 0 0 0 0 0 0 0 10 10 10
45154 - 30 30 30 70 70 70 180 133 36 226 170 11
45155 -239 182 13 242 186 14 242 186 14 246 186 14
45156 -246 190 14 246 190 14 246 190 14 246 190 14
45157 -246 190 14 246 190 14 246 190 14 246 190 14
45158 -246 190 14 232 195 16 98 70 6 2 2 6
45159 - 2 2 6 2 2 6 66 66 66 221 221 221
45160 -253 253 253 253 253 253 253 253 253 253 253 253
45161 -253 253 253 253 253 253 253 253 253 253 253 253
45162 -253 253 253 253 253 253 253 253 253 253 253 253
45163 -253 253 253 253 253 253 253 253 253 253 253 253
45164 -253 253 253 206 206 206 198 198 198 214 166 58
45165 -230 174 11 230 174 11 216 158 10 192 133 9
45166 -163 110 8 116 81 8 102 78 10 116 81 8
45167 -167 114 7 197 138 11 226 170 11 239 182 13
45168 -242 186 14 242 186 14 162 146 94 78 78 78
45169 - 34 34 34 14 14 14 6 6 6 0 0 0
45170 - 0 0 0 0 0 0 0 0 0 0 0 0
45171 - 0 0 0 0 0 0 0 0 0 0 0 0
45172 - 0 0 0 0 0 0 0 0 0 0 0 0
45173 - 0 0 0 0 0 0 0 0 0 6 6 6
45174 - 30 30 30 78 78 78 190 142 34 226 170 11
45175 -239 182 13 246 190 14 246 190 14 246 190 14
45176 -246 190 14 246 190 14 246 190 14 246 190 14
45177 -246 190 14 246 190 14 246 190 14 246 190 14
45178 -246 190 14 241 196 14 203 166 17 22 18 6
45179 - 2 2 6 2 2 6 2 2 6 38 38 38
45180 -218 218 218 253 253 253 253 253 253 253 253 253
45181 -253 253 253 253 253 253 253 253 253 253 253 253
45182 -253 253 253 253 253 253 253 253 253 253 253 253
45183 -253 253 253 253 253 253 253 253 253 253 253 253
45184 -250 250 250 206 206 206 198 198 198 202 162 69
45185 -226 170 11 236 178 12 224 166 10 210 150 10
45186 -200 144 11 197 138 11 192 133 9 197 138 11
45187 -210 150 10 226 170 11 242 186 14 246 190 14
45188 -246 190 14 246 186 14 225 175 15 124 112 88
45189 - 62 62 62 30 30 30 14 14 14 6 6 6
45190 - 0 0 0 0 0 0 0 0 0 0 0 0
45191 - 0 0 0 0 0 0 0 0 0 0 0 0
45192 - 0 0 0 0 0 0 0 0 0 0 0 0
45193 - 0 0 0 0 0 0 0 0 0 10 10 10
45194 - 30 30 30 78 78 78 174 135 50 224 166 10
45195 -239 182 13 246 190 14 246 190 14 246 190 14
45196 -246 190 14 246 190 14 246 190 14 246 190 14
45197 -246 190 14 246 190 14 246 190 14 246 190 14
45198 -246 190 14 246 190 14 241 196 14 139 102 15
45199 - 2 2 6 2 2 6 2 2 6 2 2 6
45200 - 78 78 78 250 250 250 253 253 253 253 253 253
45201 -253 253 253 253 253 253 253 253 253 253 253 253
45202 -253 253 253 253 253 253 253 253 253 253 253 253
45203 -253 253 253 253 253 253 253 253 253 253 253 253
45204 -250 250 250 214 214 214 198 198 198 190 150 46
45205 -219 162 10 236 178 12 234 174 13 224 166 10
45206 -216 158 10 213 154 11 213 154 11 216 158 10
45207 -226 170 11 239 182 13 246 190 14 246 190 14
45208 -246 190 14 246 190 14 242 186 14 206 162 42
45209 -101 101 101 58 58 58 30 30 30 14 14 14
45210 - 6 6 6 0 0 0 0 0 0 0 0 0
45211 - 0 0 0 0 0 0 0 0 0 0 0 0
45212 - 0 0 0 0 0 0 0 0 0 0 0 0
45213 - 0 0 0 0 0 0 0 0 0 10 10 10
45214 - 30 30 30 74 74 74 174 135 50 216 158 10
45215 -236 178 12 246 190 14 246 190 14 246 190 14
45216 -246 190 14 246 190 14 246 190 14 246 190 14
45217 -246 190 14 246 190 14 246 190 14 246 190 14
45218 -246 190 14 246 190 14 241 196 14 226 184 13
45219 - 61 42 6 2 2 6 2 2 6 2 2 6
45220 - 22 22 22 238 238 238 253 253 253 253 253 253
45221 -253 253 253 253 253 253 253 253 253 253 253 253
45222 -253 253 253 253 253 253 253 253 253 253 253 253
45223 -253 253 253 253 253 253 253 253 253 253 253 253
45224 -253 253 253 226 226 226 187 187 187 180 133 36
45225 -216 158 10 236 178 12 239 182 13 236 178 12
45226 -230 174 11 226 170 11 226 170 11 230 174 11
45227 -236 178 12 242 186 14 246 190 14 246 190 14
45228 -246 190 14 246 190 14 246 186 14 239 182 13
45229 -206 162 42 106 106 106 66 66 66 34 34 34
45230 - 14 14 14 6 6 6 0 0 0 0 0 0
45231 - 0 0 0 0 0 0 0 0 0 0 0 0
45232 - 0 0 0 0 0 0 0 0 0 0 0 0
45233 - 0 0 0 0 0 0 0 0 0 6 6 6
45234 - 26 26 26 70 70 70 163 133 67 213 154 11
45235 -236 178 12 246 190 14 246 190 14 246 190 14
45236 -246 190 14 246 190 14 246 190 14 246 190 14
45237 -246 190 14 246 190 14 246 190 14 246 190 14
45238 -246 190 14 246 190 14 246 190 14 241 196 14
45239 -190 146 13 18 14 6 2 2 6 2 2 6
45240 - 46 46 46 246 246 246 253 253 253 253 253 253
45241 -253 253 253 253 253 253 253 253 253 253 253 253
45242 -253 253 253 253 253 253 253 253 253 253 253 253
45243 -253 253 253 253 253 253 253 253 253 253 253 253
45244 -253 253 253 221 221 221 86 86 86 156 107 11
45245 -216 158 10 236 178 12 242 186 14 246 186 14
45246 -242 186 14 239 182 13 239 182 13 242 186 14
45247 -242 186 14 246 186 14 246 190 14 246 190 14
45248 -246 190 14 246 190 14 246 190 14 246 190 14
45249 -242 186 14 225 175 15 142 122 72 66 66 66
45250 - 30 30 30 10 10 10 0 0 0 0 0 0
45251 - 0 0 0 0 0 0 0 0 0 0 0 0
45252 - 0 0 0 0 0 0 0 0 0 0 0 0
45253 - 0 0 0 0 0 0 0 0 0 6 6 6
45254 - 26 26 26 70 70 70 163 133 67 210 150 10
45255 -236 178 12 246 190 14 246 190 14 246 190 14
45256 -246 190 14 246 190 14 246 190 14 246 190 14
45257 -246 190 14 246 190 14 246 190 14 246 190 14
45258 -246 190 14 246 190 14 246 190 14 246 190 14
45259 -232 195 16 121 92 8 34 34 34 106 106 106
45260 -221 221 221 253 253 253 253 253 253 253 253 253
45261 -253 253 253 253 253 253 253 253 253 253 253 253
45262 -253 253 253 253 253 253 253 253 253 253 253 253
45263 -253 253 253 253 253 253 253 253 253 253 253 253
45264 -242 242 242 82 82 82 18 14 6 163 110 8
45265 -216 158 10 236 178 12 242 186 14 246 190 14
45266 -246 190 14 246 190 14 246 190 14 246 190 14
45267 -246 190 14 246 190 14 246 190 14 246 190 14
45268 -246 190 14 246 190 14 246 190 14 246 190 14
45269 -246 190 14 246 190 14 242 186 14 163 133 67
45270 - 46 46 46 18 18 18 6 6 6 0 0 0
45271 - 0 0 0 0 0 0 0 0 0 0 0 0
45272 - 0 0 0 0 0 0 0 0 0 0 0 0
45273 - 0 0 0 0 0 0 0 0 0 10 10 10
45274 - 30 30 30 78 78 78 163 133 67 210 150 10
45275 -236 178 12 246 186 14 246 190 14 246 190 14
45276 -246 190 14 246 190 14 246 190 14 246 190 14
45277 -246 190 14 246 190 14 246 190 14 246 190 14
45278 -246 190 14 246 190 14 246 190 14 246 190 14
45279 -241 196 14 215 174 15 190 178 144 253 253 253
45280 -253 253 253 253 253 253 253 253 253 253 253 253
45281 -253 253 253 253 253 253 253 253 253 253 253 253
45282 -253 253 253 253 253 253 253 253 253 253 253 253
45283 -253 253 253 253 253 253 253 253 253 218 218 218
45284 - 58 58 58 2 2 6 22 18 6 167 114 7
45285 -216 158 10 236 178 12 246 186 14 246 190 14
45286 -246 190 14 246 190 14 246 190 14 246 190 14
45287 -246 190 14 246 190 14 246 190 14 246 190 14
45288 -246 190 14 246 190 14 246 190 14 246 190 14
45289 -246 190 14 246 186 14 242 186 14 190 150 46
45290 - 54 54 54 22 22 22 6 6 6 0 0 0
45291 - 0 0 0 0 0 0 0 0 0 0 0 0
45292 - 0 0 0 0 0 0 0 0 0 0 0 0
45293 - 0 0 0 0 0 0 0 0 0 14 14 14
45294 - 38 38 38 86 86 86 180 133 36 213 154 11
45295 -236 178 12 246 186 14 246 190 14 246 190 14
45296 -246 190 14 246 190 14 246 190 14 246 190 14
45297 -246 190 14 246 190 14 246 190 14 246 190 14
45298 -246 190 14 246 190 14 246 190 14 246 190 14
45299 -246 190 14 232 195 16 190 146 13 214 214 214
45300 -253 253 253 253 253 253 253 253 253 253 253 253
45301 -253 253 253 253 253 253 253 253 253 253 253 253
45302 -253 253 253 253 253 253 253 253 253 253 253 253
45303 -253 253 253 250 250 250 170 170 170 26 26 26
45304 - 2 2 6 2 2 6 37 26 9 163 110 8
45305 -219 162 10 239 182 13 246 186 14 246 190 14
45306 -246 190 14 246 190 14 246 190 14 246 190 14
45307 -246 190 14 246 190 14 246 190 14 246 190 14
45308 -246 190 14 246 190 14 246 190 14 246 190 14
45309 -246 186 14 236 178 12 224 166 10 142 122 72
45310 - 46 46 46 18 18 18 6 6 6 0 0 0
45311 - 0 0 0 0 0 0 0 0 0 0 0 0
45312 - 0 0 0 0 0 0 0 0 0 0 0 0
45313 - 0 0 0 0 0 0 6 6 6 18 18 18
45314 - 50 50 50 109 106 95 192 133 9 224 166 10
45315 -242 186 14 246 190 14 246 190 14 246 190 14
45316 -246 190 14 246 190 14 246 190 14 246 190 14
45317 -246 190 14 246 190 14 246 190 14 246 190 14
45318 -246 190 14 246 190 14 246 190 14 246 190 14
45319 -242 186 14 226 184 13 210 162 10 142 110 46
45320 -226 226 226 253 253 253 253 253 253 253 253 253
45321 -253 253 253 253 253 253 253 253 253 253 253 253
45322 -253 253 253 253 253 253 253 253 253 253 253 253
45323 -198 198 198 66 66 66 2 2 6 2 2 6
45324 - 2 2 6 2 2 6 50 34 6 156 107 11
45325 -219 162 10 239 182 13 246 186 14 246 190 14
45326 -246 190 14 246 190 14 246 190 14 246 190 14
45327 -246 190 14 246 190 14 246 190 14 246 190 14
45328 -246 190 14 246 190 14 246 190 14 242 186 14
45329 -234 174 13 213 154 11 154 122 46 66 66 66
45330 - 30 30 30 10 10 10 0 0 0 0 0 0
45331 - 0 0 0 0 0 0 0 0 0 0 0 0
45332 - 0 0 0 0 0 0 0 0 0 0 0 0
45333 - 0 0 0 0 0 0 6 6 6 22 22 22
45334 - 58 58 58 154 121 60 206 145 10 234 174 13
45335 -242 186 14 246 186 14 246 190 14 246 190 14
45336 -246 190 14 246 190 14 246 190 14 246 190 14
45337 -246 190 14 246 190 14 246 190 14 246 190 14
45338 -246 190 14 246 190 14 246 190 14 246 190 14
45339 -246 186 14 236 178 12 210 162 10 163 110 8
45340 - 61 42 6 138 138 138 218 218 218 250 250 250
45341 -253 253 253 253 253 253 253 253 253 250 250 250
45342 -242 242 242 210 210 210 144 144 144 66 66 66
45343 - 6 6 6 2 2 6 2 2 6 2 2 6
45344 - 2 2 6 2 2 6 61 42 6 163 110 8
45345 -216 158 10 236 178 12 246 190 14 246 190 14
45346 -246 190 14 246 190 14 246 190 14 246 190 14
45347 -246 190 14 246 190 14 246 190 14 246 190 14
45348 -246 190 14 239 182 13 230 174 11 216 158 10
45349 -190 142 34 124 112 88 70 70 70 38 38 38
45350 - 18 18 18 6 6 6 0 0 0 0 0 0
45351 - 0 0 0 0 0 0 0 0 0 0 0 0
45352 - 0 0 0 0 0 0 0 0 0 0 0 0
45353 - 0 0 0 0 0 0 6 6 6 22 22 22
45354 - 62 62 62 168 124 44 206 145 10 224 166 10
45355 -236 178 12 239 182 13 242 186 14 242 186 14
45356 -246 186 14 246 190 14 246 190 14 246 190 14
45357 -246 190 14 246 190 14 246 190 14 246 190 14
45358 -246 190 14 246 190 14 246 190 14 246 190 14
45359 -246 190 14 236 178 12 216 158 10 175 118 6
45360 - 80 54 7 2 2 6 6 6 6 30 30 30
45361 - 54 54 54 62 62 62 50 50 50 38 38 38
45362 - 14 14 14 2 2 6 2 2 6 2 2 6
45363 - 2 2 6 2 2 6 2 2 6 2 2 6
45364 - 2 2 6 6 6 6 80 54 7 167 114 7
45365 -213 154 11 236 178 12 246 190 14 246 190 14
45366 -246 190 14 246 190 14 246 190 14 246 190 14
45367 -246 190 14 242 186 14 239 182 13 239 182 13
45368 -230 174 11 210 150 10 174 135 50 124 112 88
45369 - 82 82 82 54 54 54 34 34 34 18 18 18
45370 - 6 6 6 0 0 0 0 0 0 0 0 0
45371 - 0 0 0 0 0 0 0 0 0 0 0 0
45372 - 0 0 0 0 0 0 0 0 0 0 0 0
45373 - 0 0 0 0 0 0 6 6 6 18 18 18
45374 - 50 50 50 158 118 36 192 133 9 200 144 11
45375 -216 158 10 219 162 10 224 166 10 226 170 11
45376 -230 174 11 236 178 12 239 182 13 239 182 13
45377 -242 186 14 246 186 14 246 190 14 246 190 14
45378 -246 190 14 246 190 14 246 190 14 246 190 14
45379 -246 186 14 230 174 11 210 150 10 163 110 8
45380 -104 69 6 10 10 10 2 2 6 2 2 6
45381 - 2 2 6 2 2 6 2 2 6 2 2 6
45382 - 2 2 6 2 2 6 2 2 6 2 2 6
45383 - 2 2 6 2 2 6 2 2 6 2 2 6
45384 - 2 2 6 6 6 6 91 60 6 167 114 7
45385 -206 145 10 230 174 11 242 186 14 246 190 14
45386 -246 190 14 246 190 14 246 186 14 242 186 14
45387 -239 182 13 230 174 11 224 166 10 213 154 11
45388 -180 133 36 124 112 88 86 86 86 58 58 58
45389 - 38 38 38 22 22 22 10 10 10 6 6 6
45390 - 0 0 0 0 0 0 0 0 0 0 0 0
45391 - 0 0 0 0 0 0 0 0 0 0 0 0
45392 - 0 0 0 0 0 0 0 0 0 0 0 0
45393 - 0 0 0 0 0 0 0 0 0 14 14 14
45394 - 34 34 34 70 70 70 138 110 50 158 118 36
45395 -167 114 7 180 123 7 192 133 9 197 138 11
45396 -200 144 11 206 145 10 213 154 11 219 162 10
45397 -224 166 10 230 174 11 239 182 13 242 186 14
45398 -246 186 14 246 186 14 246 186 14 246 186 14
45399 -239 182 13 216 158 10 185 133 11 152 99 6
45400 -104 69 6 18 14 6 2 2 6 2 2 6
45401 - 2 2 6 2 2 6 2 2 6 2 2 6
45402 - 2 2 6 2 2 6 2 2 6 2 2 6
45403 - 2 2 6 2 2 6 2 2 6 2 2 6
45404 - 2 2 6 6 6 6 80 54 7 152 99 6
45405 -192 133 9 219 162 10 236 178 12 239 182 13
45406 -246 186 14 242 186 14 239 182 13 236 178 12
45407 -224 166 10 206 145 10 192 133 9 154 121 60
45408 - 94 94 94 62 62 62 42 42 42 22 22 22
45409 - 14 14 14 6 6 6 0 0 0 0 0 0
45410 - 0 0 0 0 0 0 0 0 0 0 0 0
45411 - 0 0 0 0 0 0 0 0 0 0 0 0
45412 - 0 0 0 0 0 0 0 0 0 0 0 0
45413 - 0 0 0 0 0 0 0 0 0 6 6 6
45414 - 18 18 18 34 34 34 58 58 58 78 78 78
45415 -101 98 89 124 112 88 142 110 46 156 107 11
45416 -163 110 8 167 114 7 175 118 6 180 123 7
45417 -185 133 11 197 138 11 210 150 10 219 162 10
45418 -226 170 11 236 178 12 236 178 12 234 174 13
45419 -219 162 10 197 138 11 163 110 8 130 83 6
45420 - 91 60 6 10 10 10 2 2 6 2 2 6
45421 - 18 18 18 38 38 38 38 38 38 38 38 38
45422 - 38 38 38 38 38 38 38 38 38 38 38 38
45423 - 38 38 38 38 38 38 26 26 26 2 2 6
45424 - 2 2 6 6 6 6 70 47 6 137 92 6
45425 -175 118 6 200 144 11 219 162 10 230 174 11
45426 -234 174 13 230 174 11 219 162 10 210 150 10
45427 -192 133 9 163 110 8 124 112 88 82 82 82
45428 - 50 50 50 30 30 30 14 14 14 6 6 6
45429 - 0 0 0 0 0 0 0 0 0 0 0 0
45430 - 0 0 0 0 0 0 0 0 0 0 0 0
45431 - 0 0 0 0 0 0 0 0 0 0 0 0
45432 - 0 0 0 0 0 0 0 0 0 0 0 0
45433 - 0 0 0 0 0 0 0 0 0 0 0 0
45434 - 6 6 6 14 14 14 22 22 22 34 34 34
45435 - 42 42 42 58 58 58 74 74 74 86 86 86
45436 -101 98 89 122 102 70 130 98 46 121 87 25
45437 -137 92 6 152 99 6 163 110 8 180 123 7
45438 -185 133 11 197 138 11 206 145 10 200 144 11
45439 -180 123 7 156 107 11 130 83 6 104 69 6
45440 - 50 34 6 54 54 54 110 110 110 101 98 89
45441 - 86 86 86 82 82 82 78 78 78 78 78 78
45442 - 78 78 78 78 78 78 78 78 78 78 78 78
45443 - 78 78 78 82 82 82 86 86 86 94 94 94
45444 -106 106 106 101 101 101 86 66 34 124 80 6
45445 -156 107 11 180 123 7 192 133 9 200 144 11
45446 -206 145 10 200 144 11 192 133 9 175 118 6
45447 -139 102 15 109 106 95 70 70 70 42 42 42
45448 - 22 22 22 10 10 10 0 0 0 0 0 0
45449 - 0 0 0 0 0 0 0 0 0 0 0 0
45450 - 0 0 0 0 0 0 0 0 0 0 0 0
45451 - 0 0 0 0 0 0 0 0 0 0 0 0
45452 - 0 0 0 0 0 0 0 0 0 0 0 0
45453 - 0 0 0 0 0 0 0 0 0 0 0 0
45454 - 0 0 0 0 0 0 6 6 6 10 10 10
45455 - 14 14 14 22 22 22 30 30 30 38 38 38
45456 - 50 50 50 62 62 62 74 74 74 90 90 90
45457 -101 98 89 112 100 78 121 87 25 124 80 6
45458 -137 92 6 152 99 6 152 99 6 152 99 6
45459 -138 86 6 124 80 6 98 70 6 86 66 30
45460 -101 98 89 82 82 82 58 58 58 46 46 46
45461 - 38 38 38 34 34 34 34 34 34 34 34 34
45462 - 34 34 34 34 34 34 34 34 34 34 34 34
45463 - 34 34 34 34 34 34 38 38 38 42 42 42
45464 - 54 54 54 82 82 82 94 86 76 91 60 6
45465 -134 86 6 156 107 11 167 114 7 175 118 6
45466 -175 118 6 167 114 7 152 99 6 121 87 25
45467 -101 98 89 62 62 62 34 34 34 18 18 18
45468 - 6 6 6 0 0 0 0 0 0 0 0 0
45469 - 0 0 0 0 0 0 0 0 0 0 0 0
45470 - 0 0 0 0 0 0 0 0 0 0 0 0
45471 - 0 0 0 0 0 0 0 0 0 0 0 0
45472 - 0 0 0 0 0 0 0 0 0 0 0 0
45473 - 0 0 0 0 0 0 0 0 0 0 0 0
45474 - 0 0 0 0 0 0 0 0 0 0 0 0
45475 - 0 0 0 6 6 6 6 6 6 10 10 10
45476 - 18 18 18 22 22 22 30 30 30 42 42 42
45477 - 50 50 50 66 66 66 86 86 86 101 98 89
45478 -106 86 58 98 70 6 104 69 6 104 69 6
45479 -104 69 6 91 60 6 82 62 34 90 90 90
45480 - 62 62 62 38 38 38 22 22 22 14 14 14
45481 - 10 10 10 10 10 10 10 10 10 10 10 10
45482 - 10 10 10 10 10 10 6 6 6 10 10 10
45483 - 10 10 10 10 10 10 10 10 10 14 14 14
45484 - 22 22 22 42 42 42 70 70 70 89 81 66
45485 - 80 54 7 104 69 6 124 80 6 137 92 6
45486 -134 86 6 116 81 8 100 82 52 86 86 86
45487 - 58 58 58 30 30 30 14 14 14 6 6 6
45488 - 0 0 0 0 0 0 0 0 0 0 0 0
45489 - 0 0 0 0 0 0 0 0 0 0 0 0
45490 - 0 0 0 0 0 0 0 0 0 0 0 0
45491 - 0 0 0 0 0 0 0 0 0 0 0 0
45492 - 0 0 0 0 0 0 0 0 0 0 0 0
45493 - 0 0 0 0 0 0 0 0 0 0 0 0
45494 - 0 0 0 0 0 0 0 0 0 0 0 0
45495 - 0 0 0 0 0 0 0 0 0 0 0 0
45496 - 0 0 0 6 6 6 10 10 10 14 14 14
45497 - 18 18 18 26 26 26 38 38 38 54 54 54
45498 - 70 70 70 86 86 86 94 86 76 89 81 66
45499 - 89 81 66 86 86 86 74 74 74 50 50 50
45500 - 30 30 30 14 14 14 6 6 6 0 0 0
45501 - 0 0 0 0 0 0 0 0 0 0 0 0
45502 - 0 0 0 0 0 0 0 0 0 0 0 0
45503 - 0 0 0 0 0 0 0 0 0 0 0 0
45504 - 6 6 6 18 18 18 34 34 34 58 58 58
45505 - 82 82 82 89 81 66 89 81 66 89 81 66
45506 - 94 86 66 94 86 76 74 74 74 50 50 50
45507 - 26 26 26 14 14 14 6 6 6 0 0 0
45508 - 0 0 0 0 0 0 0 0 0 0 0 0
45509 - 0 0 0 0 0 0 0 0 0 0 0 0
45510 - 0 0 0 0 0 0 0 0 0 0 0 0
45511 - 0 0 0 0 0 0 0 0 0 0 0 0
45512 - 0 0 0 0 0 0 0 0 0 0 0 0
45513 - 0 0 0 0 0 0 0 0 0 0 0 0
45514 - 0 0 0 0 0 0 0 0 0 0 0 0
45515 - 0 0 0 0 0 0 0 0 0 0 0 0
45516 - 0 0 0 0 0 0 0 0 0 0 0 0
45517 - 6 6 6 6 6 6 14 14 14 18 18 18
45518 - 30 30 30 38 38 38 46 46 46 54 54 54
45519 - 50 50 50 42 42 42 30 30 30 18 18 18
45520 - 10 10 10 0 0 0 0 0 0 0 0 0
45521 - 0 0 0 0 0 0 0 0 0 0 0 0
45522 - 0 0 0 0 0 0 0 0 0 0 0 0
45523 - 0 0 0 0 0 0 0 0 0 0 0 0
45524 - 0 0 0 6 6 6 14 14 14 26 26 26
45525 - 38 38 38 50 50 50 58 58 58 58 58 58
45526 - 54 54 54 42 42 42 30 30 30 18 18 18
45527 - 10 10 10 0 0 0 0 0 0 0 0 0
45528 - 0 0 0 0 0 0 0 0 0 0 0 0
45529 - 0 0 0 0 0 0 0 0 0 0 0 0
45530 - 0 0 0 0 0 0 0 0 0 0 0 0
45531 - 0 0 0 0 0 0 0 0 0 0 0 0
45532 - 0 0 0 0 0 0 0 0 0 0 0 0
45533 - 0 0 0 0 0 0 0 0 0 0 0 0
45534 - 0 0 0 0 0 0 0 0 0 0 0 0
45535 - 0 0 0 0 0 0 0 0 0 0 0 0
45536 - 0 0 0 0 0 0 0 0 0 0 0 0
45537 - 0 0 0 0 0 0 0 0 0 6 6 6
45538 - 6 6 6 10 10 10 14 14 14 18 18 18
45539 - 18 18 18 14 14 14 10 10 10 6 6 6
45540 - 0 0 0 0 0 0 0 0 0 0 0 0
45541 - 0 0 0 0 0 0 0 0 0 0 0 0
45542 - 0 0 0 0 0 0 0 0 0 0 0 0
45543 - 0 0 0 0 0 0 0 0 0 0 0 0
45544 - 0 0 0 0 0 0 0 0 0 6 6 6
45545 - 14 14 14 18 18 18 22 22 22 22 22 22
45546 - 18 18 18 14 14 14 10 10 10 6 6 6
45547 - 0 0 0 0 0 0 0 0 0 0 0 0
45548 - 0 0 0 0 0 0 0 0 0 0 0 0
45549 - 0 0 0 0 0 0 0 0 0 0 0 0
45550 - 0 0 0 0 0 0 0 0 0 0 0 0
45551 - 0 0 0 0 0 0 0 0 0 0 0 0
45552 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45553 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45554 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45555 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45565 +4 4 4 4 4 4
45566 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45579 +4 4 4 4 4 4
45580 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45593 +4 4 4 4 4 4
45594 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45607 +4 4 4 4 4 4
45608 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45621 +4 4 4 4 4 4
45622 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45635 +4 4 4 4 4 4
45636 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45640 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
45641 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
45642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45645 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
45646 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
45647 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
45648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45649 +4 4 4 4 4 4
45650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45654 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
45655 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
45656 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45659 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
45660 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
45661 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
45662 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45663 +4 4 4 4 4 4
45664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45668 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
45669 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
45670 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
45671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45673 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
45674 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
45675 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
45676 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
45677 +4 4 4 4 4 4
45678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45681 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
45682 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
45683 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
45684 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
45685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45686 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
45687 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
45688 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
45689 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
45690 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
45691 +4 4 4 4 4 4
45692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45695 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
45696 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
45697 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
45698 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
45699 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45700 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
45701 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
45702 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
45703 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
45704 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
45705 +4 4 4 4 4 4
45706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45709 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
45710 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
45711 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
45712 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
45713 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
45714 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
45715 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
45716 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
45717 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
45718 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
45719 +4 4 4 4 4 4
45720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45722 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
45723 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
45724 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
45725 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
45726 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
45727 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
45728 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
45729 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
45730 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
45731 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
45732 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
45733 +4 4 4 4 4 4
45734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45736 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
45737 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
45738 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
45739 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
45740 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
45741 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
45742 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
45743 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
45744 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
45745 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
45746 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
45747 +4 4 4 4 4 4
45748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45750 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
45751 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
45752 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
45753 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
45754 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
45755 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
45756 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
45757 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
45758 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
45759 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
45760 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
45761 +4 4 4 4 4 4
45762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45764 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
45765 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
45766 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
45767 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
45768 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
45769 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
45770 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
45771 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
45772 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
45773 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
45774 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
45775 +4 4 4 4 4 4
45776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45777 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
45778 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
45779 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
45780 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
45781 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
45782 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
45783 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
45784 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
45785 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
45786 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
45787 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
45788 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
45789 +4 4 4 4 4 4
45790 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45791 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
45792 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
45793 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
45794 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
45795 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
45796 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
45797 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
45798 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
45799 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
45800 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
45801 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
45802 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
45803 +0 0 0 4 4 4
45804 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
45805 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
45806 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
45807 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
45808 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
45809 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
45810 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
45811 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
45812 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
45813 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
45814 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
45815 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
45816 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
45817 +2 0 0 0 0 0
45818 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
45819 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
45820 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
45821 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
45822 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
45823 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
45824 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
45825 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
45826 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
45827 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
45828 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
45829 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
45830 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
45831 +37 38 37 0 0 0
45832 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
45833 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
45834 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
45835 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
45836 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
45837 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
45838 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
45839 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
45840 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
45841 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
45842 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
45843 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
45844 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
45845 +85 115 134 4 0 0
45846 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
45847 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
45848 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
45849 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
45850 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
45851 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
45852 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
45853 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
45854 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
45855 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
45856 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
45857 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
45858 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
45859 +60 73 81 4 0 0
45860 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
45861 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
45862 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
45863 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
45864 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
45865 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
45866 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
45867 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
45868 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
45869 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
45870 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
45871 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
45872 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
45873 +16 19 21 4 0 0
45874 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
45875 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
45876 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
45877 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
45878 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
45879 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
45880 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
45881 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
45882 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
45883 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
45884 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
45885 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
45886 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
45887 +4 0 0 4 3 3
45888 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
45889 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
45890 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
45891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
45892 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
45893 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
45894 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
45895 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
45896 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
45897 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
45898 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
45899 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
45900 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
45901 +3 2 2 4 4 4
45902 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
45903 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
45904 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
45905 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
45906 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
45907 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
45908 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
45909 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
45910 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
45911 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
45912 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
45913 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
45914 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
45915 +4 4 4 4 4 4
45916 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
45917 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
45918 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
45919 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
45920 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
45921 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
45922 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
45923 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
45924 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
45925 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
45926 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
45927 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
45928 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
45929 +4 4 4 4 4 4
45930 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
45931 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
45932 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
45933 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
45934 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
45935 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
45936 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
45937 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
45938 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
45939 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
45940 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
45941 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
45942 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
45943 +5 5 5 5 5 5
45944 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
45945 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
45946 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
45947 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
45948 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
45949 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45950 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
45951 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
45952 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
45953 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
45954 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
45955 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
45956 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
45957 +5 5 5 4 4 4
45958 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
45959 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
45960 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
45961 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
45962 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45963 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
45964 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
45965 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
45966 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
45967 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
45968 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
45969 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
45970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45971 +4 4 4 4 4 4
45972 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
45973 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
45974 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
45975 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
45976 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
45977 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45978 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45979 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
45980 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
45981 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
45982 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
45983 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
45984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45985 +4 4 4 4 4 4
45986 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
45987 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
45988 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
45989 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
45990 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45991 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
45992 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
45993 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
45994 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
45995 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
45996 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
45997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45999 +4 4 4 4 4 4
46000 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
46001 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
46002 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
46003 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
46004 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46005 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46006 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46007 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
46008 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
46009 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
46010 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
46011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46013 +4 4 4 4 4 4
46014 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
46015 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
46016 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
46017 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
46018 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46019 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
46020 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46021 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
46022 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
46023 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
46024 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46027 +4 4 4 4 4 4
46028 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
46029 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
46030 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
46031 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
46032 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46033 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
46034 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
46035 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
46036 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
46037 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
46038 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
46039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46041 +4 4 4 4 4 4
46042 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
46043 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
46044 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
46045 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
46046 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46047 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
46048 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
46049 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
46050 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
46051 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
46052 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
46053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46055 +4 4 4 4 4 4
46056 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
46057 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
46058 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
46059 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46060 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
46061 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
46062 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
46063 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
46064 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
46065 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
46066 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46069 +4 4 4 4 4 4
46070 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
46071 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
46072 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
46073 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46074 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46075 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
46076 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
46077 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
46078 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
46079 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
46080 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46083 +4 4 4 4 4 4
46084 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
46085 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
46086 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46087 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46088 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46089 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
46090 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
46091 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
46092 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
46093 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
46094 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46097 +4 4 4 4 4 4
46098 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
46099 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
46100 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46101 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46102 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46103 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
46104 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
46105 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
46106 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46107 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46108 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46111 +4 4 4 4 4 4
46112 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46113 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
46114 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46115 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
46116 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
46117 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
46118 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
46119 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
46120 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46121 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46122 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46125 +4 4 4 4 4 4
46126 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46127 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
46128 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46129 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
46130 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46131 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
46132 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
46133 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
46134 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46135 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46136 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46139 +4 4 4 4 4 4
46140 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
46141 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
46142 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46143 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
46144 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
46145 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
46146 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
46147 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
46148 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46149 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46150 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46153 +4 4 4 4 4 4
46154 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
46155 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
46156 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46157 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
46158 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
46159 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
46160 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
46161 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
46162 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46163 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46164 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46167 +4 4 4 4 4 4
46168 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46169 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
46170 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46171 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
46172 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
46173 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
46174 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
46175 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
46176 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46177 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46178 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46181 +4 4 4 4 4 4
46182 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
46183 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
46184 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46185 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
46186 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
46187 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
46188 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
46189 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
46190 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
46191 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46192 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46195 +4 4 4 4 4 4
46196 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46197 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
46198 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
46199 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
46200 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
46201 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
46202 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
46203 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
46204 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46205 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46206 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46209 +4 4 4 4 4 4
46210 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46211 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
46212 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46213 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
46214 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
46215 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
46216 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
46217 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
46218 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46219 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46220 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46223 +4 4 4 4 4 4
46224 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46225 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
46226 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
46227 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
46228 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
46229 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
46230 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46231 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
46232 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46233 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46234 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46237 +4 4 4 4 4 4
46238 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46239 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
46240 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
46241 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46242 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
46243 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
46244 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46245 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
46246 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46247 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46248 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46251 +4 4 4 4 4 4
46252 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46253 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
46254 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
46255 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
46256 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
46257 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
46258 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
46259 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
46260 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
46261 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46262 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46265 +4 4 4 4 4 4
46266 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46267 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
46268 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
46269 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
46270 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
46271 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
46272 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
46273 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
46274 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
46275 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46276 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46279 +4 4 4 4 4 4
46280 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
46281 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
46282 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
46283 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
46284 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46285 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
46286 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
46287 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
46288 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
46289 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46290 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46293 +4 4 4 4 4 4
46294 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46295 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
46296 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
46297 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
46298 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
46299 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
46300 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
46301 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
46302 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
46303 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46304 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46307 +4 4 4 4 4 4
46308 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
46309 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
46310 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
46311 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
46312 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
46313 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
46314 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
46315 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
46316 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
46317 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
46318 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46321 +4 4 4 4 4 4
46322 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
46323 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46324 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
46325 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
46326 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
46327 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
46328 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
46329 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
46330 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
46331 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
46332 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46335 +4 4 4 4 4 4
46336 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
46337 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46338 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
46339 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
46340 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
46341 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
46342 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46343 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
46344 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
46345 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
46346 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46349 +4 4 4 4 4 4
46350 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
46351 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
46352 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
46353 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
46354 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
46355 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
46356 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
46357 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
46358 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
46359 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
46360 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46363 +4 4 4 4 4 4
46364 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
46365 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
46366 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46367 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
46368 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
46369 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
46370 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
46371 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
46372 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
46373 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
46374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46377 +4 4 4 4 4 4
46378 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46379 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
46380 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
46381 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
46382 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
46383 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
46384 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
46385 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
46386 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
46387 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46391 +4 4 4 4 4 4
46392 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
46393 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
46394 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
46395 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
46396 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
46397 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
46398 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
46399 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
46400 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
46401 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
46402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46405 +4 4 4 4 4 4
46406 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
46407 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
46408 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
46409 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
46410 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
46411 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
46412 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
46413 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
46414 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46415 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46419 +4 4 4 4 4 4
46420 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
46421 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46422 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
46423 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46424 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
46425 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
46426 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
46427 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
46428 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
46429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46433 +4 4 4 4 4 4
46434 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
46435 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
46436 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
46437 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
46438 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
46439 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
46440 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
46441 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
46442 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
46443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46447 +4 4 4 4 4 4
46448 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
46449 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
46450 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
46451 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
46452 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
46453 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
46454 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
46455 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
46456 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46461 +4 4 4 4 4 4
46462 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
46463 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
46464 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
46465 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
46466 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
46467 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
46468 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
46469 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
46470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46475 +4 4 4 4 4 4
46476 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
46477 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
46478 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
46479 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
46480 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
46481 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
46482 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
46483 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46489 +4 4 4 4 4 4
46490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46491 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
46492 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46493 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
46494 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
46495 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
46496 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
46497 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
46498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46503 +4 4 4 4 4 4
46504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46505 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
46506 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
46507 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
46508 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
46509 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
46510 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
46511 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
46512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46517 +4 4 4 4 4 4
46518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46519 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
46520 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
46521 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
46522 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
46523 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
46524 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
46525 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46526 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46531 +4 4 4 4 4 4
46532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46534 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
46535 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
46536 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
46537 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
46538 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
46539 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46540 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46541 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46545 +4 4 4 4 4 4
46546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46547 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46549 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46550 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
46551 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
46552 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
46553 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46554 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46555 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46559 +4 4 4 4 4 4
46560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46563 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
46564 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
46565 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
46566 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
46567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46573 +4 4 4 4 4 4
46574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46577 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
46578 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46579 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
46580 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
46581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46587 +4 4 4 4 4 4
46588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46591 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
46592 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
46593 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
46594 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
46595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46601 +4 4 4 4 4 4
46602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46606 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
46607 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46608 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46615 +4 4 4 4 4 4
46616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46620 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
46621 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
46622 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46629 +4 4 4 4 4 4
46630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46634 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
46635 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
46636 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46643 +4 4 4 4 4 4
46644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46648 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
46649 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
46650 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46657 +4 4 4 4 4 4
46658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46662 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
46663 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
46664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46671 +4 4 4 4 4 4
46672 diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
46673 index fe92eed..106e085 100644
46674 --- a/drivers/video/mb862xx/mb862xxfb_accel.c
46675 +++ b/drivers/video/mb862xx/mb862xxfb_accel.c
46676 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
46677 struct mb862xxfb_par *par = info->par;
46678
46679 if (info->var.bits_per_pixel == 32) {
46680 - info->fbops->fb_fillrect = cfb_fillrect;
46681 - info->fbops->fb_copyarea = cfb_copyarea;
46682 - info->fbops->fb_imageblit = cfb_imageblit;
46683 + pax_open_kernel();
46684 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
46685 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
46686 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
46687 + pax_close_kernel();
46688 } else {
46689 outreg(disp, GC_L0EM, 3);
46690 - info->fbops->fb_fillrect = mb86290fb_fillrect;
46691 - info->fbops->fb_copyarea = mb86290fb_copyarea;
46692 - info->fbops->fb_imageblit = mb86290fb_imageblit;
46693 + pax_open_kernel();
46694 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
46695 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
46696 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
46697 + pax_close_kernel();
46698 }
46699 outreg(draw, GDC_REG_DRAW_BASE, 0);
46700 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
46701 diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
46702 index ff22871..b129bed 100644
46703 --- a/drivers/video/nvidia/nvidia.c
46704 +++ b/drivers/video/nvidia/nvidia.c
46705 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
46706 info->fix.line_length = (info->var.xres_virtual *
46707 info->var.bits_per_pixel) >> 3;
46708 if (info->var.accel_flags) {
46709 - info->fbops->fb_imageblit = nvidiafb_imageblit;
46710 - info->fbops->fb_fillrect = nvidiafb_fillrect;
46711 - info->fbops->fb_copyarea = nvidiafb_copyarea;
46712 - info->fbops->fb_sync = nvidiafb_sync;
46713 + pax_open_kernel();
46714 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
46715 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
46716 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
46717 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
46718 + pax_close_kernel();
46719 info->pixmap.scan_align = 4;
46720 info->flags &= ~FBINFO_HWACCEL_DISABLED;
46721 info->flags |= FBINFO_READS_FAST;
46722 NVResetGraphics(info);
46723 } else {
46724 - info->fbops->fb_imageblit = cfb_imageblit;
46725 - info->fbops->fb_fillrect = cfb_fillrect;
46726 - info->fbops->fb_copyarea = cfb_copyarea;
46727 - info->fbops->fb_sync = NULL;
46728 + pax_open_kernel();
46729 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
46730 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
46731 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
46732 + *(void **)&info->fbops->fb_sync = NULL;
46733 + pax_close_kernel();
46734 info->pixmap.scan_align = 1;
46735 info->flags |= FBINFO_HWACCEL_DISABLED;
46736 info->flags &= ~FBINFO_READS_FAST;
46737 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
46738 info->pixmap.size = 8 * 1024;
46739 info->pixmap.flags = FB_PIXMAP_SYSTEM;
46740
46741 - if (!hwcur)
46742 - info->fbops->fb_cursor = NULL;
46743 + if (!hwcur) {
46744 + pax_open_kernel();
46745 + *(void **)&info->fbops->fb_cursor = NULL;
46746 + pax_close_kernel();
46747 + }
46748
46749 info->var.accel_flags = (!noaccel);
46750
46751 diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
46752 index 76d9053..dec2bfd 100644
46753 --- a/drivers/video/s1d13xxxfb.c
46754 +++ b/drivers/video/s1d13xxxfb.c
46755 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
46756
46757 switch(prod_id) {
46758 case S1D13506_PROD_ID: /* activate acceleration */
46759 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
46760 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
46761 + pax_open_kernel();
46762 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
46763 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
46764 + pax_close_kernel();
46765 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
46766 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
46767 break;
46768 diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
46769 index 97bd662..39fab85 100644
46770 --- a/drivers/video/smscufx.c
46771 +++ b/drivers/video/smscufx.c
46772 @@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
46773 fb_deferred_io_cleanup(info);
46774 kfree(info->fbdefio);
46775 info->fbdefio = NULL;
46776 - info->fbops->fb_mmap = ufx_ops_mmap;
46777 + pax_open_kernel();
46778 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
46779 + pax_close_kernel();
46780 }
46781
46782 pr_debug("released /dev/fb%d user=%d count=%d",
46783 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
46784 index 86d449e..8e04dc5 100644
46785 --- a/drivers/video/udlfb.c
46786 +++ b/drivers/video/udlfb.c
46787 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
46788 dlfb_urb_completion(urb);
46789
46790 error:
46791 - atomic_add(bytes_sent, &dev->bytes_sent);
46792 - atomic_add(bytes_identical, &dev->bytes_identical);
46793 - atomic_add(width*height*2, &dev->bytes_rendered);
46794 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
46795 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
46796 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
46797 end_cycles = get_cycles();
46798 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
46799 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
46800 >> 10)), /* Kcycles */
46801 &dev->cpu_kcycles_used);
46802
46803 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
46804 dlfb_urb_completion(urb);
46805
46806 error:
46807 - atomic_add(bytes_sent, &dev->bytes_sent);
46808 - atomic_add(bytes_identical, &dev->bytes_identical);
46809 - atomic_add(bytes_rendered, &dev->bytes_rendered);
46810 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
46811 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
46812 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
46813 end_cycles = get_cycles();
46814 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
46815 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
46816 >> 10)), /* Kcycles */
46817 &dev->cpu_kcycles_used);
46818 }
46819 @@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
46820 fb_deferred_io_cleanup(info);
46821 kfree(info->fbdefio);
46822 info->fbdefio = NULL;
46823 - info->fbops->fb_mmap = dlfb_ops_mmap;
46824 + pax_open_kernel();
46825 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
46826 + pax_close_kernel();
46827 }
46828
46829 pr_warn("released /dev/fb%d user=%d count=%d\n",
46830 @@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
46831 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46832 struct dlfb_data *dev = fb_info->par;
46833 return snprintf(buf, PAGE_SIZE, "%u\n",
46834 - atomic_read(&dev->bytes_rendered));
46835 + atomic_read_unchecked(&dev->bytes_rendered));
46836 }
46837
46838 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
46839 @@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
46840 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46841 struct dlfb_data *dev = fb_info->par;
46842 return snprintf(buf, PAGE_SIZE, "%u\n",
46843 - atomic_read(&dev->bytes_identical));
46844 + atomic_read_unchecked(&dev->bytes_identical));
46845 }
46846
46847 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
46848 @@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
46849 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46850 struct dlfb_data *dev = fb_info->par;
46851 return snprintf(buf, PAGE_SIZE, "%u\n",
46852 - atomic_read(&dev->bytes_sent));
46853 + atomic_read_unchecked(&dev->bytes_sent));
46854 }
46855
46856 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
46857 @@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
46858 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46859 struct dlfb_data *dev = fb_info->par;
46860 return snprintf(buf, PAGE_SIZE, "%u\n",
46861 - atomic_read(&dev->cpu_kcycles_used));
46862 + atomic_read_unchecked(&dev->cpu_kcycles_used));
46863 }
46864
46865 static ssize_t edid_show(
46866 @@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
46867 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46868 struct dlfb_data *dev = fb_info->par;
46869
46870 - atomic_set(&dev->bytes_rendered, 0);
46871 - atomic_set(&dev->bytes_identical, 0);
46872 - atomic_set(&dev->bytes_sent, 0);
46873 - atomic_set(&dev->cpu_kcycles_used, 0);
46874 + atomic_set_unchecked(&dev->bytes_rendered, 0);
46875 + atomic_set_unchecked(&dev->bytes_identical, 0);
46876 + atomic_set_unchecked(&dev->bytes_sent, 0);
46877 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
46878
46879 return count;
46880 }
46881 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
46882 index b75db01..ad2f34a 100644
46883 --- a/drivers/video/uvesafb.c
46884 +++ b/drivers/video/uvesafb.c
46885 @@ -19,6 +19,7 @@
46886 #include <linux/io.h>
46887 #include <linux/mutex.h>
46888 #include <linux/slab.h>
46889 +#include <linux/moduleloader.h>
46890 #include <video/edid.h>
46891 #include <video/uvesafb.h>
46892 #ifdef CONFIG_X86
46893 @@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
46894 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
46895 par->pmi_setpal = par->ypan = 0;
46896 } else {
46897 +
46898 +#ifdef CONFIG_PAX_KERNEXEC
46899 +#ifdef CONFIG_MODULES
46900 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
46901 +#endif
46902 + if (!par->pmi_code) {
46903 + par->pmi_setpal = par->ypan = 0;
46904 + return 0;
46905 + }
46906 +#endif
46907 +
46908 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
46909 + task->t.regs.edi);
46910 +
46911 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46912 + pax_open_kernel();
46913 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
46914 + pax_close_kernel();
46915 +
46916 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
46917 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
46918 +#else
46919 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
46920 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
46921 +#endif
46922 +
46923 printk(KERN_INFO "uvesafb: protected mode interface info at "
46924 "%04x:%04x\n",
46925 (u16)task->t.regs.es, (u16)task->t.regs.edi);
46926 @@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
46927 par->ypan = ypan;
46928
46929 if (par->pmi_setpal || par->ypan) {
46930 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
46931 if (__supported_pte_mask & _PAGE_NX) {
46932 par->pmi_setpal = par->ypan = 0;
46933 printk(KERN_WARNING "uvesafb: NX protection is actively."
46934 "We have better not to use the PMI.\n");
46935 - } else {
46936 + } else
46937 +#endif
46938 uvesafb_vbe_getpmi(task, par);
46939 - }
46940 }
46941 #else
46942 /* The protected mode interface is not available on non-x86. */
46943 @@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
46944 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
46945
46946 /* Disable blanking if the user requested so. */
46947 - if (!blank)
46948 - info->fbops->fb_blank = NULL;
46949 + if (!blank) {
46950 + pax_open_kernel();
46951 + *(void **)&info->fbops->fb_blank = NULL;
46952 + pax_close_kernel();
46953 + }
46954
46955 /*
46956 * Find out how much IO memory is required for the mode with
46957 @@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
46958 info->flags = FBINFO_FLAG_DEFAULT |
46959 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
46960
46961 - if (!par->ypan)
46962 - info->fbops->fb_pan_display = NULL;
46963 + if (!par->ypan) {
46964 + pax_open_kernel();
46965 + *(void **)&info->fbops->fb_pan_display = NULL;
46966 + pax_close_kernel();
46967 + }
46968 }
46969
46970 static void uvesafb_init_mtrr(struct fb_info *info)
46971 @@ -1836,6 +1866,11 @@ out:
46972 if (par->vbe_modes)
46973 kfree(par->vbe_modes);
46974
46975 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46976 + if (par->pmi_code)
46977 + module_free_exec(NULL, par->pmi_code);
46978 +#endif
46979 +
46980 framebuffer_release(info);
46981 return err;
46982 }
46983 @@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
46984 kfree(par->vbe_state_orig);
46985 if (par->vbe_state_saved)
46986 kfree(par->vbe_state_saved);
46987 +
46988 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46989 + if (par->pmi_code)
46990 + module_free_exec(NULL, par->pmi_code);
46991 +#endif
46992 +
46993 }
46994
46995 framebuffer_release(info);
46996 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
46997 index 501b340..d80aa17 100644
46998 --- a/drivers/video/vesafb.c
46999 +++ b/drivers/video/vesafb.c
47000 @@ -9,6 +9,7 @@
47001 */
47002
47003 #include <linux/module.h>
47004 +#include <linux/moduleloader.h>
47005 #include <linux/kernel.h>
47006 #include <linux/errno.h>
47007 #include <linux/string.h>
47008 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
47009 static int vram_total __initdata; /* Set total amount of memory */
47010 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
47011 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
47012 -static void (*pmi_start)(void) __read_mostly;
47013 -static void (*pmi_pal) (void) __read_mostly;
47014 +static void (*pmi_start)(void) __read_only;
47015 +static void (*pmi_pal) (void) __read_only;
47016 static int depth __read_mostly;
47017 static int vga_compat __read_mostly;
47018 /* --------------------------------------------------------------------- */
47019 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
47020 unsigned int size_vmode;
47021 unsigned int size_remap;
47022 unsigned int size_total;
47023 + void *pmi_code = NULL;
47024
47025 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
47026 return -ENODEV;
47027 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
47028 size_remap = size_total;
47029 vesafb_fix.smem_len = size_remap;
47030
47031 -#ifndef __i386__
47032 - screen_info.vesapm_seg = 0;
47033 -#endif
47034 -
47035 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
47036 printk(KERN_WARNING
47037 "vesafb: cannot reserve video memory at 0x%lx\n",
47038 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
47039 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
47040 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
47041
47042 +#ifdef __i386__
47043 +
47044 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47045 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
47046 + if (!pmi_code)
47047 +#elif !defined(CONFIG_PAX_KERNEXEC)
47048 + if (0)
47049 +#endif
47050 +
47051 +#endif
47052 + screen_info.vesapm_seg = 0;
47053 +
47054 if (screen_info.vesapm_seg) {
47055 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
47056 - screen_info.vesapm_seg,screen_info.vesapm_off);
47057 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
47058 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
47059 }
47060
47061 if (screen_info.vesapm_seg < 0xc000)
47062 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
47063
47064 if (ypan || pmi_setpal) {
47065 unsigned short *pmi_base;
47066 +
47067 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
47068 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
47069 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
47070 +
47071 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47072 + pax_open_kernel();
47073 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
47074 +#else
47075 + pmi_code = pmi_base;
47076 +#endif
47077 +
47078 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
47079 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
47080 +
47081 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47082 + pmi_start = ktva_ktla(pmi_start);
47083 + pmi_pal = ktva_ktla(pmi_pal);
47084 + pax_close_kernel();
47085 +#endif
47086 +
47087 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
47088 if (pmi_base[3]) {
47089 printk(KERN_INFO "vesafb: pmi: ports = ");
47090 @@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47091 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
47092 (ypan ? FBINFO_HWACCEL_YPAN : 0);
47093
47094 - if (!ypan)
47095 - info->fbops->fb_pan_display = NULL;
47096 + if (!ypan) {
47097 + pax_open_kernel();
47098 + *(void **)&info->fbops->fb_pan_display = NULL;
47099 + pax_close_kernel();
47100 + }
47101
47102 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
47103 err = -ENOMEM;
47104 @@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47105 info->node, info->fix.id);
47106 return 0;
47107 err:
47108 +
47109 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47110 + module_free_exec(NULL, pmi_code);
47111 +#endif
47112 +
47113 if (info->screen_base)
47114 iounmap(info->screen_base);
47115 framebuffer_release(info);
47116 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
47117 index 88714ae..16c2e11 100644
47118 --- a/drivers/video/via/via_clock.h
47119 +++ b/drivers/video/via/via_clock.h
47120 @@ -56,7 +56,7 @@ struct via_clock {
47121
47122 void (*set_engine_pll_state)(u8 state);
47123 void (*set_engine_pll)(struct via_pll_config config);
47124 -};
47125 +} __no_const;
47126
47127
47128 static inline u32 get_pll_internal_frequency(u32 ref_freq,
47129 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
47130 index fef20db..d28b1ab 100644
47131 --- a/drivers/xen/xenfs/xenstored.c
47132 +++ b/drivers/xen/xenfs/xenstored.c
47133 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
47134 static int xsd_kva_open(struct inode *inode, struct file *file)
47135 {
47136 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
47137 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47138 + NULL);
47139 +#else
47140 xen_store_interface);
47141 +#endif
47142 +
47143 if (!file->private_data)
47144 return -ENOMEM;
47145 return 0;
47146 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
47147 index 890bed5..17ae73e 100644
47148 --- a/fs/9p/vfs_inode.c
47149 +++ b/fs/9p/vfs_inode.c
47150 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47151 void
47152 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47153 {
47154 - char *s = nd_get_link(nd);
47155 + const char *s = nd_get_link(nd);
47156
47157 p9_debug(P9_DEBUG_VFS, " %s %s\n",
47158 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
47159 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
47160 index 0efd152..b5802ad 100644
47161 --- a/fs/Kconfig.binfmt
47162 +++ b/fs/Kconfig.binfmt
47163 @@ -89,7 +89,7 @@ config HAVE_AOUT
47164
47165 config BINFMT_AOUT
47166 tristate "Kernel support for a.out and ECOFF binaries"
47167 - depends on HAVE_AOUT
47168 + depends on HAVE_AOUT && BROKEN
47169 ---help---
47170 A.out (Assembler.OUTput) is a set of formats for libraries and
47171 executables used in the earliest versions of UNIX. Linux used
47172 diff --git a/fs/aio.c b/fs/aio.c
47173 index 71f613c..9d01f1f 100644
47174 --- a/fs/aio.c
47175 +++ b/fs/aio.c
47176 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
47177 size += sizeof(struct io_event) * nr_events;
47178 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
47179
47180 - if (nr_pages < 0)
47181 + if (nr_pages <= 0)
47182 return -EINVAL;
47183
47184 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
47185 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
47186 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47187 {
47188 ssize_t ret;
47189 + struct iovec iovstack;
47190
47191 #ifdef CONFIG_COMPAT
47192 if (compat)
47193 ret = compat_rw_copy_check_uvector(type,
47194 (struct compat_iovec __user *)kiocb->ki_buf,
47195 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47196 + kiocb->ki_nbytes, 1, &iovstack,
47197 &kiocb->ki_iovec);
47198 else
47199 #endif
47200 ret = rw_copy_check_uvector(type,
47201 (struct iovec __user *)kiocb->ki_buf,
47202 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47203 + kiocb->ki_nbytes, 1, &iovstack,
47204 &kiocb->ki_iovec);
47205 if (ret < 0)
47206 goto out;
47207 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47208 if (ret < 0)
47209 goto out;
47210
47211 + if (kiocb->ki_iovec == &iovstack) {
47212 + kiocb->ki_inline_vec = iovstack;
47213 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
47214 + }
47215 kiocb->ki_nr_segs = kiocb->ki_nbytes;
47216 kiocb->ki_cur_seg = 0;
47217 /* ki_nbytes/left now reflect bytes instead of segs */
47218 diff --git a/fs/attr.c b/fs/attr.c
47219 index 1449adb..a2038c2 100644
47220 --- a/fs/attr.c
47221 +++ b/fs/attr.c
47222 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
47223 unsigned long limit;
47224
47225 limit = rlimit(RLIMIT_FSIZE);
47226 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
47227 if (limit != RLIM_INFINITY && offset > limit)
47228 goto out_sig;
47229 if (offset > inode->i_sb->s_maxbytes)
47230 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
47231 index 03bc1d3..6205356 100644
47232 --- a/fs/autofs4/waitq.c
47233 +++ b/fs/autofs4/waitq.c
47234 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
47235 {
47236 unsigned long sigpipe, flags;
47237 mm_segment_t fs;
47238 - const char *data = (const char *)addr;
47239 + const char __user *data = (const char __force_user *)addr;
47240 ssize_t wr = 0;
47241
47242 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
47243 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
47244 return 1;
47245 }
47246
47247 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47248 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
47249 +#endif
47250 +
47251 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47252 enum autofs_notify notify)
47253 {
47254 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47255
47256 /* If this is a direct mount request create a dummy name */
47257 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
47258 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47259 + /* this name does get written to userland via autofs4_write() */
47260 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
47261 +#else
47262 qstr.len = sprintf(name, "%p", dentry);
47263 +#endif
47264 else {
47265 qstr.len = autofs4_getpath(sbi, dentry, &name);
47266 if (!qstr.len) {
47267 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
47268 index 2b3bda8..6a2d4be 100644
47269 --- a/fs/befs/linuxvfs.c
47270 +++ b/fs/befs/linuxvfs.c
47271 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47272 {
47273 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
47274 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
47275 - char *link = nd_get_link(nd);
47276 + const char *link = nd_get_link(nd);
47277 if (!IS_ERR(link))
47278 kfree(link);
47279 }
47280 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
47281 index 6043567..16a9239 100644
47282 --- a/fs/binfmt_aout.c
47283 +++ b/fs/binfmt_aout.c
47284 @@ -16,6 +16,7 @@
47285 #include <linux/string.h>
47286 #include <linux/fs.h>
47287 #include <linux/file.h>
47288 +#include <linux/security.h>
47289 #include <linux/stat.h>
47290 #include <linux/fcntl.h>
47291 #include <linux/ptrace.h>
47292 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
47293 #endif
47294 # define START_STACK(u) ((void __user *)u.start_stack)
47295
47296 + memset(&dump, 0, sizeof(dump));
47297 +
47298 fs = get_fs();
47299 set_fs(KERNEL_DS);
47300 has_dumped = 1;
47301 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
47302
47303 /* If the size of the dump file exceeds the rlimit, then see what would happen
47304 if we wrote the stack, but not the data area. */
47305 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
47306 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
47307 dump.u_dsize = 0;
47308
47309 /* Make sure we have enough room to write the stack and data areas. */
47310 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
47311 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
47312 dump.u_ssize = 0;
47313
47314 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
47315 rlim = rlimit(RLIMIT_DATA);
47316 if (rlim >= RLIM_INFINITY)
47317 rlim = ~0;
47318 +
47319 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
47320 if (ex.a_data + ex.a_bss > rlim)
47321 return -ENOMEM;
47322
47323 @@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
47324
47325 install_exec_creds(bprm);
47326
47327 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47328 + current->mm->pax_flags = 0UL;
47329 +#endif
47330 +
47331 +#ifdef CONFIG_PAX_PAGEEXEC
47332 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
47333 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
47334 +
47335 +#ifdef CONFIG_PAX_EMUTRAMP
47336 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
47337 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
47338 +#endif
47339 +
47340 +#ifdef CONFIG_PAX_MPROTECT
47341 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
47342 + current->mm->pax_flags |= MF_PAX_MPROTECT;
47343 +#endif
47344 +
47345 + }
47346 +#endif
47347 +
47348 if (N_MAGIC(ex) == OMAGIC) {
47349 unsigned long text_addr, map_size;
47350 loff_t pos;
47351 @@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
47352 }
47353
47354 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
47355 - PROT_READ | PROT_WRITE | PROT_EXEC,
47356 + PROT_READ | PROT_WRITE,
47357 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
47358 fd_offset + ex.a_text);
47359 if (error != N_DATADDR(ex)) {
47360 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
47361 index 0c42cdb..9551bb8 100644
47362 --- a/fs/binfmt_elf.c
47363 +++ b/fs/binfmt_elf.c
47364 @@ -33,6 +33,7 @@
47365 #include <linux/elf.h>
47366 #include <linux/utsname.h>
47367 #include <linux/coredump.h>
47368 +#include <linux/xattr.h>
47369 #include <asm/uaccess.h>
47370 #include <asm/param.h>
47371 #include <asm/page.h>
47372 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
47373 #define elf_core_dump NULL
47374 #endif
47375
47376 +#ifdef CONFIG_PAX_MPROTECT
47377 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
47378 +#endif
47379 +
47380 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
47381 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
47382 #else
47383 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
47384 .load_binary = load_elf_binary,
47385 .load_shlib = load_elf_library,
47386 .core_dump = elf_core_dump,
47387 +
47388 +#ifdef CONFIG_PAX_MPROTECT
47389 + .handle_mprotect= elf_handle_mprotect,
47390 +#endif
47391 +
47392 .min_coredump = ELF_EXEC_PAGESIZE,
47393 };
47394
47395 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
47396
47397 static int set_brk(unsigned long start, unsigned long end)
47398 {
47399 + unsigned long e = end;
47400 +
47401 start = ELF_PAGEALIGN(start);
47402 end = ELF_PAGEALIGN(end);
47403 if (end > start) {
47404 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
47405 if (BAD_ADDR(addr))
47406 return addr;
47407 }
47408 - current->mm->start_brk = current->mm->brk = end;
47409 + current->mm->start_brk = current->mm->brk = e;
47410 return 0;
47411 }
47412
47413 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47414 elf_addr_t __user *u_rand_bytes;
47415 const char *k_platform = ELF_PLATFORM;
47416 const char *k_base_platform = ELF_BASE_PLATFORM;
47417 - unsigned char k_rand_bytes[16];
47418 + u32 k_rand_bytes[4];
47419 int items;
47420 elf_addr_t *elf_info;
47421 int ei_index = 0;
47422 const struct cred *cred = current_cred();
47423 struct vm_area_struct *vma;
47424 + unsigned long saved_auxv[AT_VECTOR_SIZE];
47425
47426 /*
47427 * In some cases (e.g. Hyper-Threading), we want to avoid L1
47428 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47429 * Generate 16 random bytes for userspace PRNG seeding.
47430 */
47431 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
47432 - u_rand_bytes = (elf_addr_t __user *)
47433 - STACK_ALLOC(p, sizeof(k_rand_bytes));
47434 + srandom32(k_rand_bytes[0] ^ random32());
47435 + srandom32(k_rand_bytes[1] ^ random32());
47436 + srandom32(k_rand_bytes[2] ^ random32());
47437 + srandom32(k_rand_bytes[3] ^ random32());
47438 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
47439 + u_rand_bytes = (elf_addr_t __user *) p;
47440 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
47441 return -EFAULT;
47442
47443 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47444 return -EFAULT;
47445 current->mm->env_end = p;
47446
47447 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
47448 +
47449 /* Put the elf_info on the stack in the right place. */
47450 sp = (elf_addr_t __user *)envp + 1;
47451 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
47452 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
47453 return -EFAULT;
47454 return 0;
47455 }
47456 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
47457 an ELF header */
47458
47459 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47460 - struct file *interpreter, unsigned long *interp_map_addr,
47461 - unsigned long no_base)
47462 + struct file *interpreter, unsigned long no_base)
47463 {
47464 struct elf_phdr *elf_phdata;
47465 struct elf_phdr *eppnt;
47466 - unsigned long load_addr = 0;
47467 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
47468 int load_addr_set = 0;
47469 unsigned long last_bss = 0, elf_bss = 0;
47470 - unsigned long error = ~0UL;
47471 + unsigned long error = -EINVAL;
47472 unsigned long total_size;
47473 int retval, i, size;
47474
47475 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47476 goto out_close;
47477 }
47478
47479 +#ifdef CONFIG_PAX_SEGMEXEC
47480 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
47481 + pax_task_size = SEGMEXEC_TASK_SIZE;
47482 +#endif
47483 +
47484 eppnt = elf_phdata;
47485 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
47486 if (eppnt->p_type == PT_LOAD) {
47487 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47488 map_addr = elf_map(interpreter, load_addr + vaddr,
47489 eppnt, elf_prot, elf_type, total_size);
47490 total_size = 0;
47491 - if (!*interp_map_addr)
47492 - *interp_map_addr = map_addr;
47493 error = map_addr;
47494 if (BAD_ADDR(map_addr))
47495 goto out_close;
47496 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47497 k = load_addr + eppnt->p_vaddr;
47498 if (BAD_ADDR(k) ||
47499 eppnt->p_filesz > eppnt->p_memsz ||
47500 - eppnt->p_memsz > TASK_SIZE ||
47501 - TASK_SIZE - eppnt->p_memsz < k) {
47502 + eppnt->p_memsz > pax_task_size ||
47503 + pax_task_size - eppnt->p_memsz < k) {
47504 error = -ENOMEM;
47505 goto out_close;
47506 }
47507 @@ -530,6 +551,315 @@ out:
47508 return error;
47509 }
47510
47511 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
47512 +#ifdef CONFIG_PAX_SOFTMODE
47513 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
47514 +{
47515 + unsigned long pax_flags = 0UL;
47516 +
47517 +#ifdef CONFIG_PAX_PAGEEXEC
47518 + if (elf_phdata->p_flags & PF_PAGEEXEC)
47519 + pax_flags |= MF_PAX_PAGEEXEC;
47520 +#endif
47521 +
47522 +#ifdef CONFIG_PAX_SEGMEXEC
47523 + if (elf_phdata->p_flags & PF_SEGMEXEC)
47524 + pax_flags |= MF_PAX_SEGMEXEC;
47525 +#endif
47526 +
47527 +#ifdef CONFIG_PAX_EMUTRAMP
47528 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
47529 + pax_flags |= MF_PAX_EMUTRAMP;
47530 +#endif
47531 +
47532 +#ifdef CONFIG_PAX_MPROTECT
47533 + if (elf_phdata->p_flags & PF_MPROTECT)
47534 + pax_flags |= MF_PAX_MPROTECT;
47535 +#endif
47536 +
47537 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47538 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
47539 + pax_flags |= MF_PAX_RANDMMAP;
47540 +#endif
47541 +
47542 + return pax_flags;
47543 +}
47544 +#endif
47545 +
47546 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
47547 +{
47548 + unsigned long pax_flags = 0UL;
47549 +
47550 +#ifdef CONFIG_PAX_PAGEEXEC
47551 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
47552 + pax_flags |= MF_PAX_PAGEEXEC;
47553 +#endif
47554 +
47555 +#ifdef CONFIG_PAX_SEGMEXEC
47556 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
47557 + pax_flags |= MF_PAX_SEGMEXEC;
47558 +#endif
47559 +
47560 +#ifdef CONFIG_PAX_EMUTRAMP
47561 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
47562 + pax_flags |= MF_PAX_EMUTRAMP;
47563 +#endif
47564 +
47565 +#ifdef CONFIG_PAX_MPROTECT
47566 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
47567 + pax_flags |= MF_PAX_MPROTECT;
47568 +#endif
47569 +
47570 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47571 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
47572 + pax_flags |= MF_PAX_RANDMMAP;
47573 +#endif
47574 +
47575 + return pax_flags;
47576 +}
47577 +#endif
47578 +
47579 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
47580 +#ifdef CONFIG_PAX_SOFTMODE
47581 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
47582 +{
47583 + unsigned long pax_flags = 0UL;
47584 +
47585 +#ifdef CONFIG_PAX_PAGEEXEC
47586 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
47587 + pax_flags |= MF_PAX_PAGEEXEC;
47588 +#endif
47589 +
47590 +#ifdef CONFIG_PAX_SEGMEXEC
47591 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
47592 + pax_flags |= MF_PAX_SEGMEXEC;
47593 +#endif
47594 +
47595 +#ifdef CONFIG_PAX_EMUTRAMP
47596 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
47597 + pax_flags |= MF_PAX_EMUTRAMP;
47598 +#endif
47599 +
47600 +#ifdef CONFIG_PAX_MPROTECT
47601 + if (pax_flags_softmode & MF_PAX_MPROTECT)
47602 + pax_flags |= MF_PAX_MPROTECT;
47603 +#endif
47604 +
47605 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47606 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
47607 + pax_flags |= MF_PAX_RANDMMAP;
47608 +#endif
47609 +
47610 + return pax_flags;
47611 +}
47612 +#endif
47613 +
47614 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
47615 +{
47616 + unsigned long pax_flags = 0UL;
47617 +
47618 +#ifdef CONFIG_PAX_PAGEEXEC
47619 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
47620 + pax_flags |= MF_PAX_PAGEEXEC;
47621 +#endif
47622 +
47623 +#ifdef CONFIG_PAX_SEGMEXEC
47624 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
47625 + pax_flags |= MF_PAX_SEGMEXEC;
47626 +#endif
47627 +
47628 +#ifdef CONFIG_PAX_EMUTRAMP
47629 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
47630 + pax_flags |= MF_PAX_EMUTRAMP;
47631 +#endif
47632 +
47633 +#ifdef CONFIG_PAX_MPROTECT
47634 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
47635 + pax_flags |= MF_PAX_MPROTECT;
47636 +#endif
47637 +
47638 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47639 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
47640 + pax_flags |= MF_PAX_RANDMMAP;
47641 +#endif
47642 +
47643 + return pax_flags;
47644 +}
47645 +#endif
47646 +
47647 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47648 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
47649 +{
47650 + unsigned long pax_flags = 0UL;
47651 +
47652 +#ifdef CONFIG_PAX_EI_PAX
47653 +
47654 +#ifdef CONFIG_PAX_PAGEEXEC
47655 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
47656 + pax_flags |= MF_PAX_PAGEEXEC;
47657 +#endif
47658 +
47659 +#ifdef CONFIG_PAX_SEGMEXEC
47660 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
47661 + pax_flags |= MF_PAX_SEGMEXEC;
47662 +#endif
47663 +
47664 +#ifdef CONFIG_PAX_EMUTRAMP
47665 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
47666 + pax_flags |= MF_PAX_EMUTRAMP;
47667 +#endif
47668 +
47669 +#ifdef CONFIG_PAX_MPROTECT
47670 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
47671 + pax_flags |= MF_PAX_MPROTECT;
47672 +#endif
47673 +
47674 +#ifdef CONFIG_PAX_ASLR
47675 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
47676 + pax_flags |= MF_PAX_RANDMMAP;
47677 +#endif
47678 +
47679 +#else
47680 +
47681 +#ifdef CONFIG_PAX_PAGEEXEC
47682 + pax_flags |= MF_PAX_PAGEEXEC;
47683 +#endif
47684 +
47685 +#ifdef CONFIG_PAX_SEGMEXEC
47686 + pax_flags |= MF_PAX_SEGMEXEC;
47687 +#endif
47688 +
47689 +#ifdef CONFIG_PAX_MPROTECT
47690 + pax_flags |= MF_PAX_MPROTECT;
47691 +#endif
47692 +
47693 +#ifdef CONFIG_PAX_RANDMMAP
47694 + if (randomize_va_space)
47695 + pax_flags |= MF_PAX_RANDMMAP;
47696 +#endif
47697 +
47698 +#endif
47699 +
47700 + return pax_flags;
47701 +}
47702 +
47703 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
47704 +{
47705 +
47706 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
47707 + unsigned long i;
47708 +
47709 + for (i = 0UL; i < elf_ex->e_phnum; i++)
47710 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
47711 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
47712 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
47713 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
47714 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
47715 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
47716 + return ~0UL;
47717 +
47718 +#ifdef CONFIG_PAX_SOFTMODE
47719 + if (pax_softmode)
47720 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
47721 + else
47722 +#endif
47723 +
47724 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
47725 + break;
47726 + }
47727 +#endif
47728 +
47729 + return ~0UL;
47730 +}
47731 +
47732 +static unsigned long pax_parse_xattr_pax(struct file * const file)
47733 +{
47734 +
47735 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
47736 + ssize_t xattr_size, i;
47737 + unsigned char xattr_value[5];
47738 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
47739 +
47740 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
47741 + if (xattr_size <= 0 || xattr_size > 5)
47742 + return ~0UL;
47743 +
47744 + for (i = 0; i < xattr_size; i++)
47745 + switch (xattr_value[i]) {
47746 + default:
47747 + return ~0UL;
47748 +
47749 +#define parse_flag(option1, option2, flag) \
47750 + case option1: \
47751 + if (pax_flags_hardmode & MF_PAX_##flag) \
47752 + return ~0UL; \
47753 + pax_flags_hardmode |= MF_PAX_##flag; \
47754 + break; \
47755 + case option2: \
47756 + if (pax_flags_softmode & MF_PAX_##flag) \
47757 + return ~0UL; \
47758 + pax_flags_softmode |= MF_PAX_##flag; \
47759 + break;
47760 +
47761 + parse_flag('p', 'P', PAGEEXEC);
47762 + parse_flag('e', 'E', EMUTRAMP);
47763 + parse_flag('m', 'M', MPROTECT);
47764 + parse_flag('r', 'R', RANDMMAP);
47765 + parse_flag('s', 'S', SEGMEXEC);
47766 +
47767 +#undef parse_flag
47768 + }
47769 +
47770 + if (pax_flags_hardmode & pax_flags_softmode)
47771 + return ~0UL;
47772 +
47773 +#ifdef CONFIG_PAX_SOFTMODE
47774 + if (pax_softmode)
47775 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
47776 + else
47777 +#endif
47778 +
47779 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
47780 +#else
47781 + return ~0UL;
47782 +#endif
47783 +
47784 +}
47785 +
47786 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
47787 +{
47788 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
47789 +
47790 + pax_flags = pax_parse_ei_pax(elf_ex);
47791 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
47792 + xattr_pax_flags = pax_parse_xattr_pax(file);
47793 +
47794 + if (pt_pax_flags == ~0UL)
47795 + pt_pax_flags = xattr_pax_flags;
47796 + else if (xattr_pax_flags == ~0UL)
47797 + xattr_pax_flags = pt_pax_flags;
47798 + if (pt_pax_flags != xattr_pax_flags)
47799 + return -EINVAL;
47800 + if (pt_pax_flags != ~0UL)
47801 + pax_flags = pt_pax_flags;
47802 +
47803 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
47804 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47805 + if ((__supported_pte_mask & _PAGE_NX))
47806 + pax_flags &= ~MF_PAX_SEGMEXEC;
47807 + else
47808 + pax_flags &= ~MF_PAX_PAGEEXEC;
47809 + }
47810 +#endif
47811 +
47812 + if (0 > pax_check_flags(&pax_flags))
47813 + return -EINVAL;
47814 +
47815 + current->mm->pax_flags = pax_flags;
47816 + return 0;
47817 +}
47818 +#endif
47819 +
47820 /*
47821 * These are the functions used to load ELF style executables and shared
47822 * libraries. There is no binary dependent code anywhere else.
47823 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
47824 {
47825 unsigned int random_variable = 0;
47826
47827 +#ifdef CONFIG_PAX_RANDUSTACK
47828 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
47829 + return stack_top - current->mm->delta_stack;
47830 +#endif
47831 +
47832 if ((current->flags & PF_RANDOMIZE) &&
47833 !(current->personality & ADDR_NO_RANDOMIZE)) {
47834 random_variable = get_random_int() & STACK_RND_MASK;
47835 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
47836 unsigned long load_addr = 0, load_bias = 0;
47837 int load_addr_set = 0;
47838 char * elf_interpreter = NULL;
47839 - unsigned long error;
47840 + unsigned long error = 0;
47841 struct elf_phdr *elf_ppnt, *elf_phdata;
47842 unsigned long elf_bss, elf_brk;
47843 int retval, i;
47844 @@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
47845 unsigned long start_code, end_code, start_data, end_data;
47846 unsigned long reloc_func_desc __maybe_unused = 0;
47847 int executable_stack = EXSTACK_DEFAULT;
47848 - unsigned long def_flags = 0;
47849 struct pt_regs *regs = current_pt_regs();
47850 struct {
47851 struct elfhdr elf_ex;
47852 struct elfhdr interp_elf_ex;
47853 } *loc;
47854 + unsigned long pax_task_size = TASK_SIZE;
47855
47856 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
47857 if (!loc) {
47858 @@ -715,11 +1050,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
47859 goto out_free_dentry;
47860
47861 /* OK, This is the point of no return */
47862 - current->mm->def_flags = def_flags;
47863 +
47864 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47865 + current->mm->pax_flags = 0UL;
47866 +#endif
47867 +
47868 +#ifdef CONFIG_PAX_DLRESOLVE
47869 + current->mm->call_dl_resolve = 0UL;
47870 +#endif
47871 +
47872 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
47873 + current->mm->call_syscall = 0UL;
47874 +#endif
47875 +
47876 +#ifdef CONFIG_PAX_ASLR
47877 + current->mm->delta_mmap = 0UL;
47878 + current->mm->delta_stack = 0UL;
47879 + current->mm->aslr_gap = 0UL;
47880 +#endif
47881 +
47882 + current->mm->def_flags = 0;
47883 +
47884 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47885 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
47886 + send_sig(SIGKILL, current, 0);
47887 + goto out_free_dentry;
47888 + }
47889 +#endif
47890 +
47891 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
47892 + pax_set_initial_flags(bprm);
47893 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
47894 + if (pax_set_initial_flags_func)
47895 + (pax_set_initial_flags_func)(bprm);
47896 +#endif
47897 +
47898 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
47899 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
47900 + current->mm->context.user_cs_limit = PAGE_SIZE;
47901 + current->mm->def_flags |= VM_PAGEEXEC;
47902 + }
47903 +#endif
47904 +
47905 +#ifdef CONFIG_PAX_SEGMEXEC
47906 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
47907 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
47908 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
47909 + pax_task_size = SEGMEXEC_TASK_SIZE;
47910 + current->mm->def_flags |= VM_NOHUGEPAGE;
47911 + }
47912 +#endif
47913 +
47914 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
47915 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47916 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
47917 + put_cpu();
47918 + }
47919 +#endif
47920
47921 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
47922 may depend on the personality. */
47923 SET_PERSONALITY(loc->elf_ex);
47924 +
47925 +#ifdef CONFIG_PAX_ASLR
47926 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
47927 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
47928 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
47929 + }
47930 +#endif
47931 +
47932 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47933 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47934 + executable_stack = EXSTACK_DISABLE_X;
47935 + current->personality &= ~READ_IMPLIES_EXEC;
47936 + } else
47937 +#endif
47938 +
47939 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
47940 current->personality |= READ_IMPLIES_EXEC;
47941
47942 @@ -810,6 +1216,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
47943 #else
47944 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
47945 #endif
47946 +
47947 +#ifdef CONFIG_PAX_RANDMMAP
47948 + /* PaX: randomize base address at the default exe base if requested */
47949 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
47950 +#ifdef CONFIG_SPARC64
47951 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
47952 +#else
47953 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
47954 +#endif
47955 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
47956 + elf_flags |= MAP_FIXED;
47957 + }
47958 +#endif
47959 +
47960 }
47961
47962 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
47963 @@ -842,9 +1262,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
47964 * allowed task size. Note that p_filesz must always be
47965 * <= p_memsz so it is only necessary to check p_memsz.
47966 */
47967 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
47968 - elf_ppnt->p_memsz > TASK_SIZE ||
47969 - TASK_SIZE - elf_ppnt->p_memsz < k) {
47970 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
47971 + elf_ppnt->p_memsz > pax_task_size ||
47972 + pax_task_size - elf_ppnt->p_memsz < k) {
47973 /* set_brk can never work. Avoid overflows. */
47974 send_sig(SIGKILL, current, 0);
47975 retval = -EINVAL;
47976 @@ -883,17 +1303,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
47977 goto out_free_dentry;
47978 }
47979 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
47980 - send_sig(SIGSEGV, current, 0);
47981 - retval = -EFAULT; /* Nobody gets to see this, but.. */
47982 - goto out_free_dentry;
47983 + /*
47984 + * This bss-zeroing can fail if the ELF
47985 + * file specifies odd protections. So
47986 + * we don't check the return value
47987 + */
47988 }
47989
47990 +#ifdef CONFIG_PAX_RANDMMAP
47991 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
47992 + unsigned long start, size;
47993 +
47994 + start = ELF_PAGEALIGN(elf_brk);
47995 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
47996 + down_read(&current->mm->mmap_sem);
47997 + retval = -ENOMEM;
47998 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
47999 + unsigned long prot = PROT_NONE;
48000 +
48001 + up_read(&current->mm->mmap_sem);
48002 + current->mm->aslr_gap += PAGE_ALIGN(size) >> PAGE_SHIFT;
48003 +// if (current->personality & ADDR_NO_RANDOMIZE)
48004 +// prot = PROT_READ;
48005 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
48006 + retval = IS_ERR_VALUE(start) ? start : 0;
48007 + } else
48008 + up_read(&current->mm->mmap_sem);
48009 + if (retval == 0)
48010 + retval = set_brk(start + size, start + size + PAGE_SIZE);
48011 + if (retval < 0) {
48012 + send_sig(SIGKILL, current, 0);
48013 + goto out_free_dentry;
48014 + }
48015 + }
48016 +#endif
48017 +
48018 if (elf_interpreter) {
48019 - unsigned long interp_map_addr = 0;
48020 -
48021 elf_entry = load_elf_interp(&loc->interp_elf_ex,
48022 interpreter,
48023 - &interp_map_addr,
48024 load_bias);
48025 if (!IS_ERR((void *)elf_entry)) {
48026 /*
48027 @@ -1115,7 +1562,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
48028 * Decide what to dump of a segment, part, all or none.
48029 */
48030 static unsigned long vma_dump_size(struct vm_area_struct *vma,
48031 - unsigned long mm_flags)
48032 + unsigned long mm_flags, long signr)
48033 {
48034 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
48035
48036 @@ -1152,7 +1599,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
48037 if (vma->vm_file == NULL)
48038 return 0;
48039
48040 - if (FILTER(MAPPED_PRIVATE))
48041 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
48042 goto whole;
48043
48044 /*
48045 @@ -1374,9 +1821,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
48046 {
48047 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
48048 int i = 0;
48049 - do
48050 + do {
48051 i += 2;
48052 - while (auxv[i - 2] != AT_NULL);
48053 + } while (auxv[i - 2] != AT_NULL);
48054 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
48055 }
48056
48057 @@ -2006,14 +2453,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
48058 }
48059
48060 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
48061 - unsigned long mm_flags)
48062 + struct coredump_params *cprm)
48063 {
48064 struct vm_area_struct *vma;
48065 size_t size = 0;
48066
48067 for (vma = first_vma(current, gate_vma); vma != NULL;
48068 vma = next_vma(vma, gate_vma))
48069 - size += vma_dump_size(vma, mm_flags);
48070 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48071 return size;
48072 }
48073
48074 @@ -2107,7 +2554,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48075
48076 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
48077
48078 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
48079 + offset += elf_core_vma_data_size(gate_vma, cprm);
48080 offset += elf_core_extra_data_size();
48081 e_shoff = offset;
48082
48083 @@ -2121,10 +2568,12 @@ static int elf_core_dump(struct coredump_params *cprm)
48084 offset = dataoff;
48085
48086 size += sizeof(*elf);
48087 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
48088 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
48089 goto end_coredump;
48090
48091 size += sizeof(*phdr4note);
48092 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
48093 if (size > cprm->limit
48094 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
48095 goto end_coredump;
48096 @@ -2138,7 +2587,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48097 phdr.p_offset = offset;
48098 phdr.p_vaddr = vma->vm_start;
48099 phdr.p_paddr = 0;
48100 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
48101 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48102 phdr.p_memsz = vma->vm_end - vma->vm_start;
48103 offset += phdr.p_filesz;
48104 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
48105 @@ -2149,6 +2598,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48106 phdr.p_align = ELF_EXEC_PAGESIZE;
48107
48108 size += sizeof(phdr);
48109 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
48110 if (size > cprm->limit
48111 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
48112 goto end_coredump;
48113 @@ -2173,7 +2623,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48114 unsigned long addr;
48115 unsigned long end;
48116
48117 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
48118 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48119
48120 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
48121 struct page *page;
48122 @@ -2182,6 +2632,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48123 page = get_dump_page(addr);
48124 if (page) {
48125 void *kaddr = kmap(page);
48126 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
48127 stop = ((size += PAGE_SIZE) > cprm->limit) ||
48128 !dump_write(cprm->file, kaddr,
48129 PAGE_SIZE);
48130 @@ -2199,6 +2650,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48131
48132 if (e_phnum == PN_XNUM) {
48133 size += sizeof(*shdr4extnum);
48134 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
48135 if (size > cprm->limit
48136 || !dump_write(cprm->file, shdr4extnum,
48137 sizeof(*shdr4extnum)))
48138 @@ -2219,6 +2671,97 @@ out:
48139
48140 #endif /* CONFIG_ELF_CORE */
48141
48142 +#ifdef CONFIG_PAX_MPROTECT
48143 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
48144 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
48145 + * we'll remove VM_MAYWRITE for good on RELRO segments.
48146 + *
48147 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
48148 + * basis because we want to allow the common case and not the special ones.
48149 + */
48150 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
48151 +{
48152 + struct elfhdr elf_h;
48153 + struct elf_phdr elf_p;
48154 + unsigned long i;
48155 + unsigned long oldflags;
48156 + bool is_textrel_rw, is_textrel_rx, is_relro;
48157 +
48158 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
48159 + return;
48160 +
48161 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
48162 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
48163 +
48164 +#ifdef CONFIG_PAX_ELFRELOCS
48165 + /* possible TEXTREL */
48166 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
48167 + 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);
48168 +#else
48169 + is_textrel_rw = false;
48170 + is_textrel_rx = false;
48171 +#endif
48172 +
48173 + /* possible RELRO */
48174 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
48175 +
48176 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
48177 + return;
48178 +
48179 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
48180 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
48181 +
48182 +#ifdef CONFIG_PAX_ETEXECRELOCS
48183 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48184 +#else
48185 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
48186 +#endif
48187 +
48188 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48189 + !elf_check_arch(&elf_h) ||
48190 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
48191 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
48192 + return;
48193 +
48194 + for (i = 0UL; i < elf_h.e_phnum; i++) {
48195 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
48196 + return;
48197 + switch (elf_p.p_type) {
48198 + case PT_DYNAMIC:
48199 + if (!is_textrel_rw && !is_textrel_rx)
48200 + continue;
48201 + i = 0UL;
48202 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
48203 + elf_dyn dyn;
48204 +
48205 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
48206 + return;
48207 + if (dyn.d_tag == DT_NULL)
48208 + return;
48209 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
48210 + gr_log_textrel(vma);
48211 + if (is_textrel_rw)
48212 + vma->vm_flags |= VM_MAYWRITE;
48213 + else
48214 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
48215 + vma->vm_flags &= ~VM_MAYWRITE;
48216 + return;
48217 + }
48218 + i++;
48219 + }
48220 + return;
48221 +
48222 + case PT_GNU_RELRO:
48223 + if (!is_relro)
48224 + continue;
48225 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
48226 + vma->vm_flags &= ~VM_MAYWRITE;
48227 + return;
48228 + }
48229 + }
48230 +}
48231 +#endif
48232 +
48233 static int __init init_elf_binfmt(void)
48234 {
48235 register_binfmt(&elf_format);
48236 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
48237 index b563719..3868998 100644
48238 --- a/fs/binfmt_flat.c
48239 +++ b/fs/binfmt_flat.c
48240 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
48241 realdatastart = (unsigned long) -ENOMEM;
48242 printk("Unable to allocate RAM for process data, errno %d\n",
48243 (int)-realdatastart);
48244 + down_write(&current->mm->mmap_sem);
48245 vm_munmap(textpos, text_len);
48246 + up_write(&current->mm->mmap_sem);
48247 ret = realdatastart;
48248 goto err;
48249 }
48250 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48251 }
48252 if (IS_ERR_VALUE(result)) {
48253 printk("Unable to read data+bss, errno %d\n", (int)-result);
48254 + down_write(&current->mm->mmap_sem);
48255 vm_munmap(textpos, text_len);
48256 vm_munmap(realdatastart, len);
48257 + up_write(&current->mm->mmap_sem);
48258 ret = result;
48259 goto err;
48260 }
48261 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48262 }
48263 if (IS_ERR_VALUE(result)) {
48264 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
48265 + down_write(&current->mm->mmap_sem);
48266 vm_munmap(textpos, text_len + data_len + extra +
48267 MAX_SHARED_LIBS * sizeof(unsigned long));
48268 + up_write(&current->mm->mmap_sem);
48269 ret = result;
48270 goto err;
48271 }
48272 diff --git a/fs/bio.c b/fs/bio.c
48273 index b96fc6c..431d628 100644
48274 --- a/fs/bio.c
48275 +++ b/fs/bio.c
48276 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
48277 /*
48278 * Overflow, abort
48279 */
48280 - if (end < start)
48281 + if (end < start || end - start > INT_MAX - nr_pages)
48282 return ERR_PTR(-EINVAL);
48283
48284 nr_pages += end - start;
48285 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
48286 /*
48287 * Overflow, abort
48288 */
48289 - if (end < start)
48290 + if (end < start || end - start > INT_MAX - nr_pages)
48291 return ERR_PTR(-EINVAL);
48292
48293 nr_pages += end - start;
48294 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
48295 const int read = bio_data_dir(bio) == READ;
48296 struct bio_map_data *bmd = bio->bi_private;
48297 int i;
48298 - char *p = bmd->sgvecs[0].iov_base;
48299 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
48300
48301 __bio_for_each_segment(bvec, bio, i, 0) {
48302 char *addr = page_address(bvec->bv_page);
48303 diff --git a/fs/block_dev.c b/fs/block_dev.c
48304 index 78333a3..23dcb4d 100644
48305 --- a/fs/block_dev.c
48306 +++ b/fs/block_dev.c
48307 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
48308 else if (bdev->bd_contains == bdev)
48309 return true; /* is a whole device which isn't held */
48310
48311 - else if (whole->bd_holder == bd_may_claim)
48312 + else if (whole->bd_holder == (void *)bd_may_claim)
48313 return true; /* is a partition of a device that is being partitioned */
48314 else if (whole->bd_holder != NULL)
48315 return false; /* is a partition of a held device */
48316 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
48317 index eea5da7..88fead70 100644
48318 --- a/fs/btrfs/ctree.c
48319 +++ b/fs/btrfs/ctree.c
48320 @@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
48321 free_extent_buffer(buf);
48322 add_root_to_dirty_list(root);
48323 } else {
48324 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
48325 - parent_start = parent->start;
48326 - else
48327 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
48328 + if (parent)
48329 + parent_start = parent->start;
48330 + else
48331 + parent_start = 0;
48332 + } else
48333 parent_start = 0;
48334
48335 WARN_ON(trans->transid != btrfs_header_generation(parent));
48336 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
48337 index 659ea81..0f63c1a 100644
48338 --- a/fs/btrfs/inode.c
48339 +++ b/fs/btrfs/inode.c
48340 @@ -7300,7 +7300,7 @@ fail:
48341 return -ENOMEM;
48342 }
48343
48344 -static int btrfs_getattr(struct vfsmount *mnt,
48345 +int btrfs_getattr(struct vfsmount *mnt,
48346 struct dentry *dentry, struct kstat *stat)
48347 {
48348 struct inode *inode = dentry->d_inode;
48349 @@ -7314,6 +7314,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
48350 return 0;
48351 }
48352
48353 +EXPORT_SYMBOL(btrfs_getattr);
48354 +
48355 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
48356 +{
48357 + return BTRFS_I(inode)->root->anon_dev;
48358 +}
48359 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
48360 +
48361 /*
48362 * If a file is moved, it will inherit the cow and compression flags of the new
48363 * directory.
48364 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
48365 index 338f259..b657640 100644
48366 --- a/fs/btrfs/ioctl.c
48367 +++ b/fs/btrfs/ioctl.c
48368 @@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48369 for (i = 0; i < num_types; i++) {
48370 struct btrfs_space_info *tmp;
48371
48372 + /* Don't copy in more than we allocated */
48373 if (!slot_count)
48374 break;
48375
48376 + slot_count--;
48377 +
48378 info = NULL;
48379 rcu_read_lock();
48380 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
48381 @@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48382 memcpy(dest, &space, sizeof(space));
48383 dest++;
48384 space_args.total_spaces++;
48385 - slot_count--;
48386 }
48387 - if (!slot_count)
48388 - break;
48389 }
48390 up_read(&info->groups_sem);
48391 }
48392 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
48393 index 300e09a..9fe4539 100644
48394 --- a/fs/btrfs/relocation.c
48395 +++ b/fs/btrfs/relocation.c
48396 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
48397 }
48398 spin_unlock(&rc->reloc_root_tree.lock);
48399
48400 - BUG_ON((struct btrfs_root *)node->data != root);
48401 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
48402
48403 if (!del) {
48404 spin_lock(&rc->reloc_root_tree.lock);
48405 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
48406 index d8982e9..29a85fa 100644
48407 --- a/fs/btrfs/super.c
48408 +++ b/fs/btrfs/super.c
48409 @@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
48410 function, line, errstr);
48411 return;
48412 }
48413 - ACCESS_ONCE(trans->transaction->aborted) = errno;
48414 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
48415 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
48416 }
48417 /*
48418 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
48419 index 622f469..e8d2d55 100644
48420 --- a/fs/cachefiles/bind.c
48421 +++ b/fs/cachefiles/bind.c
48422 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
48423 args);
48424
48425 /* start by checking things over */
48426 - ASSERT(cache->fstop_percent >= 0 &&
48427 - cache->fstop_percent < cache->fcull_percent &&
48428 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
48429 cache->fcull_percent < cache->frun_percent &&
48430 cache->frun_percent < 100);
48431
48432 - ASSERT(cache->bstop_percent >= 0 &&
48433 - cache->bstop_percent < cache->bcull_percent &&
48434 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
48435 cache->bcull_percent < cache->brun_percent &&
48436 cache->brun_percent < 100);
48437
48438 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
48439 index 0a1467b..6a53245 100644
48440 --- a/fs/cachefiles/daemon.c
48441 +++ b/fs/cachefiles/daemon.c
48442 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
48443 if (n > buflen)
48444 return -EMSGSIZE;
48445
48446 - if (copy_to_user(_buffer, buffer, n) != 0)
48447 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
48448 return -EFAULT;
48449
48450 return n;
48451 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
48452 if (test_bit(CACHEFILES_DEAD, &cache->flags))
48453 return -EIO;
48454
48455 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
48456 + if (datalen > PAGE_SIZE - 1)
48457 return -EOPNOTSUPP;
48458
48459 /* drag the command string into the kernel so we can parse it */
48460 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
48461 if (args[0] != '%' || args[1] != '\0')
48462 return -EINVAL;
48463
48464 - if (fstop < 0 || fstop >= cache->fcull_percent)
48465 + if (fstop >= cache->fcull_percent)
48466 return cachefiles_daemon_range_error(cache, args);
48467
48468 cache->fstop_percent = fstop;
48469 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
48470 if (args[0] != '%' || args[1] != '\0')
48471 return -EINVAL;
48472
48473 - if (bstop < 0 || bstop >= cache->bcull_percent)
48474 + if (bstop >= cache->bcull_percent)
48475 return cachefiles_daemon_range_error(cache, args);
48476
48477 cache->bstop_percent = bstop;
48478 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
48479 index 4938251..7e01445 100644
48480 --- a/fs/cachefiles/internal.h
48481 +++ b/fs/cachefiles/internal.h
48482 @@ -59,7 +59,7 @@ struct cachefiles_cache {
48483 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
48484 struct rb_root active_nodes; /* active nodes (can't be culled) */
48485 rwlock_t active_lock; /* lock for active_nodes */
48486 - atomic_t gravecounter; /* graveyard uniquifier */
48487 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
48488 unsigned frun_percent; /* when to stop culling (% files) */
48489 unsigned fcull_percent; /* when to start culling (% files) */
48490 unsigned fstop_percent; /* when to stop allocating (% files) */
48491 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
48492 * proc.c
48493 */
48494 #ifdef CONFIG_CACHEFILES_HISTOGRAM
48495 -extern atomic_t cachefiles_lookup_histogram[HZ];
48496 -extern atomic_t cachefiles_mkdir_histogram[HZ];
48497 -extern atomic_t cachefiles_create_histogram[HZ];
48498 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
48499 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
48500 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
48501
48502 extern int __init cachefiles_proc_init(void);
48503 extern void cachefiles_proc_cleanup(void);
48504 static inline
48505 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
48506 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
48507 {
48508 unsigned long jif = jiffies - start_jif;
48509 if (jif >= HZ)
48510 jif = HZ - 1;
48511 - atomic_inc(&histogram[jif]);
48512 + atomic_inc_unchecked(&histogram[jif]);
48513 }
48514
48515 #else
48516 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
48517 index 8c01c5fc..15f982e 100644
48518 --- a/fs/cachefiles/namei.c
48519 +++ b/fs/cachefiles/namei.c
48520 @@ -317,7 +317,7 @@ try_again:
48521 /* first step is to make up a grave dentry in the graveyard */
48522 sprintf(nbuffer, "%08x%08x",
48523 (uint32_t) get_seconds(),
48524 - (uint32_t) atomic_inc_return(&cache->gravecounter));
48525 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
48526
48527 /* do the multiway lock magic */
48528 trap = lock_rename(cache->graveyard, dir);
48529 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
48530 index eccd339..4c1d995 100644
48531 --- a/fs/cachefiles/proc.c
48532 +++ b/fs/cachefiles/proc.c
48533 @@ -14,9 +14,9 @@
48534 #include <linux/seq_file.h>
48535 #include "internal.h"
48536
48537 -atomic_t cachefiles_lookup_histogram[HZ];
48538 -atomic_t cachefiles_mkdir_histogram[HZ];
48539 -atomic_t cachefiles_create_histogram[HZ];
48540 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
48541 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
48542 +atomic_unchecked_t cachefiles_create_histogram[HZ];
48543
48544 /*
48545 * display the latency histogram
48546 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
48547 return 0;
48548 default:
48549 index = (unsigned long) v - 3;
48550 - x = atomic_read(&cachefiles_lookup_histogram[index]);
48551 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
48552 - z = atomic_read(&cachefiles_create_histogram[index]);
48553 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
48554 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
48555 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
48556 if (x == 0 && y == 0 && z == 0)
48557 return 0;
48558
48559 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
48560 index 4809922..aab2c39 100644
48561 --- a/fs/cachefiles/rdwr.c
48562 +++ b/fs/cachefiles/rdwr.c
48563 @@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
48564 old_fs = get_fs();
48565 set_fs(KERNEL_DS);
48566 ret = file->f_op->write(
48567 - file, (const void __user *) data, len, &pos);
48568 + file, (const void __force_user *) data, len, &pos);
48569 set_fs(old_fs);
48570 kunmap(page);
48571 if (ret != len)
48572 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
48573 index 8c1aabe..bbf856a 100644
48574 --- a/fs/ceph/dir.c
48575 +++ b/fs/ceph/dir.c
48576 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
48577 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
48578 struct ceph_mds_client *mdsc = fsc->mdsc;
48579 unsigned frag = fpos_frag(filp->f_pos);
48580 - int off = fpos_off(filp->f_pos);
48581 + unsigned int off = fpos_off(filp->f_pos);
48582 int err;
48583 u32 ftype;
48584 struct ceph_mds_reply_info_parsed *rinfo;
48585 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
48586 index d9ea6ed..1e6c8ac 100644
48587 --- a/fs/cifs/cifs_debug.c
48588 +++ b/fs/cifs/cifs_debug.c
48589 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
48590
48591 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
48592 #ifdef CONFIG_CIFS_STATS2
48593 - atomic_set(&totBufAllocCount, 0);
48594 - atomic_set(&totSmBufAllocCount, 0);
48595 + atomic_set_unchecked(&totBufAllocCount, 0);
48596 + atomic_set_unchecked(&totSmBufAllocCount, 0);
48597 #endif /* CONFIG_CIFS_STATS2 */
48598 spin_lock(&cifs_tcp_ses_lock);
48599 list_for_each(tmp1, &cifs_tcp_ses_list) {
48600 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
48601 tcon = list_entry(tmp3,
48602 struct cifs_tcon,
48603 tcon_list);
48604 - atomic_set(&tcon->num_smbs_sent, 0);
48605 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
48606 if (server->ops->clear_stats)
48607 server->ops->clear_stats(tcon);
48608 }
48609 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
48610 smBufAllocCount.counter, cifs_min_small);
48611 #ifdef CONFIG_CIFS_STATS2
48612 seq_printf(m, "Total Large %d Small %d Allocations\n",
48613 - atomic_read(&totBufAllocCount),
48614 - atomic_read(&totSmBufAllocCount));
48615 + atomic_read_unchecked(&totBufAllocCount),
48616 + atomic_read_unchecked(&totSmBufAllocCount));
48617 #endif /* CONFIG_CIFS_STATS2 */
48618
48619 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
48620 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
48621 if (tcon->need_reconnect)
48622 seq_puts(m, "\tDISCONNECTED ");
48623 seq_printf(m, "\nSMBs: %d",
48624 - atomic_read(&tcon->num_smbs_sent));
48625 + atomic_read_unchecked(&tcon->num_smbs_sent));
48626 if (server->ops->print_stats)
48627 server->ops->print_stats(m, tcon);
48628 }
48629 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
48630 index e328339..322228b 100644
48631 --- a/fs/cifs/cifsfs.c
48632 +++ b/fs/cifs/cifsfs.c
48633 @@ -1002,7 +1002,7 @@ cifs_init_request_bufs(void)
48634 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
48635 cifs_req_cachep = kmem_cache_create("cifs_request",
48636 CIFSMaxBufSize + max_hdr_size, 0,
48637 - SLAB_HWCACHE_ALIGN, NULL);
48638 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
48639 if (cifs_req_cachep == NULL)
48640 return -ENOMEM;
48641
48642 @@ -1029,7 +1029,7 @@ cifs_init_request_bufs(void)
48643 efficient to alloc 1 per page off the slab compared to 17K (5page)
48644 alloc of large cifs buffers even when page debugging is on */
48645 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
48646 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
48647 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
48648 NULL);
48649 if (cifs_sm_req_cachep == NULL) {
48650 mempool_destroy(cifs_req_poolp);
48651 @@ -1114,8 +1114,8 @@ init_cifs(void)
48652 atomic_set(&bufAllocCount, 0);
48653 atomic_set(&smBufAllocCount, 0);
48654 #ifdef CONFIG_CIFS_STATS2
48655 - atomic_set(&totBufAllocCount, 0);
48656 - atomic_set(&totSmBufAllocCount, 0);
48657 + atomic_set_unchecked(&totBufAllocCount, 0);
48658 + atomic_set_unchecked(&totSmBufAllocCount, 0);
48659 #endif /* CONFIG_CIFS_STATS2 */
48660
48661 atomic_set(&midCount, 0);
48662 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
48663 index e6899ce..d6b2920 100644
48664 --- a/fs/cifs/cifsglob.h
48665 +++ b/fs/cifs/cifsglob.h
48666 @@ -751,35 +751,35 @@ struct cifs_tcon {
48667 __u16 Flags; /* optional support bits */
48668 enum statusEnum tidStatus;
48669 #ifdef CONFIG_CIFS_STATS
48670 - atomic_t num_smbs_sent;
48671 + atomic_unchecked_t num_smbs_sent;
48672 union {
48673 struct {
48674 - atomic_t num_writes;
48675 - atomic_t num_reads;
48676 - atomic_t num_flushes;
48677 - atomic_t num_oplock_brks;
48678 - atomic_t num_opens;
48679 - atomic_t num_closes;
48680 - atomic_t num_deletes;
48681 - atomic_t num_mkdirs;
48682 - atomic_t num_posixopens;
48683 - atomic_t num_posixmkdirs;
48684 - atomic_t num_rmdirs;
48685 - atomic_t num_renames;
48686 - atomic_t num_t2renames;
48687 - atomic_t num_ffirst;
48688 - atomic_t num_fnext;
48689 - atomic_t num_fclose;
48690 - atomic_t num_hardlinks;
48691 - atomic_t num_symlinks;
48692 - atomic_t num_locks;
48693 - atomic_t num_acl_get;
48694 - atomic_t num_acl_set;
48695 + atomic_unchecked_t num_writes;
48696 + atomic_unchecked_t num_reads;
48697 + atomic_unchecked_t num_flushes;
48698 + atomic_unchecked_t num_oplock_brks;
48699 + atomic_unchecked_t num_opens;
48700 + atomic_unchecked_t num_closes;
48701 + atomic_unchecked_t num_deletes;
48702 + atomic_unchecked_t num_mkdirs;
48703 + atomic_unchecked_t num_posixopens;
48704 + atomic_unchecked_t num_posixmkdirs;
48705 + atomic_unchecked_t num_rmdirs;
48706 + atomic_unchecked_t num_renames;
48707 + atomic_unchecked_t num_t2renames;
48708 + atomic_unchecked_t num_ffirst;
48709 + atomic_unchecked_t num_fnext;
48710 + atomic_unchecked_t num_fclose;
48711 + atomic_unchecked_t num_hardlinks;
48712 + atomic_unchecked_t num_symlinks;
48713 + atomic_unchecked_t num_locks;
48714 + atomic_unchecked_t num_acl_get;
48715 + atomic_unchecked_t num_acl_set;
48716 } cifs_stats;
48717 #ifdef CONFIG_CIFS_SMB2
48718 struct {
48719 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
48720 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
48721 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
48722 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
48723 } smb2_stats;
48724 #endif /* CONFIG_CIFS_SMB2 */
48725 } stats;
48726 @@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
48727 }
48728
48729 #ifdef CONFIG_CIFS_STATS
48730 -#define cifs_stats_inc atomic_inc
48731 +#define cifs_stats_inc atomic_inc_unchecked
48732
48733 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
48734 unsigned int bytes)
48735 @@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
48736 /* Various Debug counters */
48737 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
48738 #ifdef CONFIG_CIFS_STATS2
48739 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
48740 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
48741 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
48742 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
48743 #endif
48744 GLOBAL_EXTERN atomic_t smBufAllocCount;
48745 GLOBAL_EXTERN atomic_t midCount;
48746 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
48747 index 51dc2fb..1e12a33 100644
48748 --- a/fs/cifs/link.c
48749 +++ b/fs/cifs/link.c
48750 @@ -616,7 +616,7 @@ symlink_exit:
48751
48752 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
48753 {
48754 - char *p = nd_get_link(nd);
48755 + const char *p = nd_get_link(nd);
48756 if (!IS_ERR(p))
48757 kfree(p);
48758 }
48759 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
48760 index 3a00c0d..42d901c 100644
48761 --- a/fs/cifs/misc.c
48762 +++ b/fs/cifs/misc.c
48763 @@ -169,7 +169,7 @@ cifs_buf_get(void)
48764 memset(ret_buf, 0, buf_size + 3);
48765 atomic_inc(&bufAllocCount);
48766 #ifdef CONFIG_CIFS_STATS2
48767 - atomic_inc(&totBufAllocCount);
48768 + atomic_inc_unchecked(&totBufAllocCount);
48769 #endif /* CONFIG_CIFS_STATS2 */
48770 }
48771
48772 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
48773 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
48774 atomic_inc(&smBufAllocCount);
48775 #ifdef CONFIG_CIFS_STATS2
48776 - atomic_inc(&totSmBufAllocCount);
48777 + atomic_inc_unchecked(&totSmBufAllocCount);
48778 #endif /* CONFIG_CIFS_STATS2 */
48779
48780 }
48781 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
48782 index 47bc5a8..10decbe 100644
48783 --- a/fs/cifs/smb1ops.c
48784 +++ b/fs/cifs/smb1ops.c
48785 @@ -586,27 +586,27 @@ static void
48786 cifs_clear_stats(struct cifs_tcon *tcon)
48787 {
48788 #ifdef CONFIG_CIFS_STATS
48789 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
48790 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
48791 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
48792 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
48793 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
48794 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
48795 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
48796 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
48797 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
48798 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
48799 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
48800 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
48801 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
48802 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
48803 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
48804 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
48805 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
48806 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
48807 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
48808 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
48809 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
48810 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
48811 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
48812 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
48813 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
48814 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
48815 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
48816 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
48817 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
48818 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
48819 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
48820 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
48821 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
48822 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
48823 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
48824 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
48825 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
48826 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
48827 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
48828 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
48829 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
48830 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
48831 #endif
48832 }
48833
48834 @@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
48835 {
48836 #ifdef CONFIG_CIFS_STATS
48837 seq_printf(m, " Oplocks breaks: %d",
48838 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
48839 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
48840 seq_printf(m, "\nReads: %d Bytes: %llu",
48841 - atomic_read(&tcon->stats.cifs_stats.num_reads),
48842 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
48843 (long long)(tcon->bytes_read));
48844 seq_printf(m, "\nWrites: %d Bytes: %llu",
48845 - atomic_read(&tcon->stats.cifs_stats.num_writes),
48846 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
48847 (long long)(tcon->bytes_written));
48848 seq_printf(m, "\nFlushes: %d",
48849 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
48850 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
48851 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
48852 - atomic_read(&tcon->stats.cifs_stats.num_locks),
48853 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
48854 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
48855 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
48856 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
48857 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
48858 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
48859 - atomic_read(&tcon->stats.cifs_stats.num_opens),
48860 - atomic_read(&tcon->stats.cifs_stats.num_closes),
48861 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
48862 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
48863 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
48864 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
48865 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
48866 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
48867 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
48868 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
48869 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
48870 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
48871 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
48872 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
48873 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
48874 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
48875 seq_printf(m, "\nRenames: %d T2 Renames %d",
48876 - atomic_read(&tcon->stats.cifs_stats.num_renames),
48877 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
48878 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
48879 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
48880 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
48881 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
48882 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
48883 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
48884 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
48885 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
48886 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
48887 #endif
48888 }
48889
48890 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
48891 index bceffe7..cd1ae59 100644
48892 --- a/fs/cifs/smb2ops.c
48893 +++ b/fs/cifs/smb2ops.c
48894 @@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
48895 #ifdef CONFIG_CIFS_STATS
48896 int i;
48897 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
48898 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
48899 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
48900 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
48901 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
48902 }
48903 #endif
48904 }
48905 @@ -284,66 +284,66 @@ static void
48906 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
48907 {
48908 #ifdef CONFIG_CIFS_STATS
48909 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
48910 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
48911 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
48912 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
48913 seq_printf(m, "\nNegotiates: %d sent %d failed",
48914 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
48915 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
48916 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
48917 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
48918 seq_printf(m, "\nSessionSetups: %d sent %d failed",
48919 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
48920 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
48921 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
48922 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
48923 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
48924 seq_printf(m, "\nLogoffs: %d sent %d failed",
48925 - atomic_read(&sent[SMB2_LOGOFF_HE]),
48926 - atomic_read(&failed[SMB2_LOGOFF_HE]));
48927 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
48928 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
48929 seq_printf(m, "\nTreeConnects: %d sent %d failed",
48930 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
48931 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
48932 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
48933 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
48934 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
48935 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
48936 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
48937 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
48938 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
48939 seq_printf(m, "\nCreates: %d sent %d failed",
48940 - atomic_read(&sent[SMB2_CREATE_HE]),
48941 - atomic_read(&failed[SMB2_CREATE_HE]));
48942 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
48943 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
48944 seq_printf(m, "\nCloses: %d sent %d failed",
48945 - atomic_read(&sent[SMB2_CLOSE_HE]),
48946 - atomic_read(&failed[SMB2_CLOSE_HE]));
48947 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
48948 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
48949 seq_printf(m, "\nFlushes: %d sent %d failed",
48950 - atomic_read(&sent[SMB2_FLUSH_HE]),
48951 - atomic_read(&failed[SMB2_FLUSH_HE]));
48952 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
48953 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
48954 seq_printf(m, "\nReads: %d sent %d failed",
48955 - atomic_read(&sent[SMB2_READ_HE]),
48956 - atomic_read(&failed[SMB2_READ_HE]));
48957 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
48958 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
48959 seq_printf(m, "\nWrites: %d sent %d failed",
48960 - atomic_read(&sent[SMB2_WRITE_HE]),
48961 - atomic_read(&failed[SMB2_WRITE_HE]));
48962 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
48963 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
48964 seq_printf(m, "\nLocks: %d sent %d failed",
48965 - atomic_read(&sent[SMB2_LOCK_HE]),
48966 - atomic_read(&failed[SMB2_LOCK_HE]));
48967 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
48968 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
48969 seq_printf(m, "\nIOCTLs: %d sent %d failed",
48970 - atomic_read(&sent[SMB2_IOCTL_HE]),
48971 - atomic_read(&failed[SMB2_IOCTL_HE]));
48972 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
48973 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
48974 seq_printf(m, "\nCancels: %d sent %d failed",
48975 - atomic_read(&sent[SMB2_CANCEL_HE]),
48976 - atomic_read(&failed[SMB2_CANCEL_HE]));
48977 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
48978 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
48979 seq_printf(m, "\nEchos: %d sent %d failed",
48980 - atomic_read(&sent[SMB2_ECHO_HE]),
48981 - atomic_read(&failed[SMB2_ECHO_HE]));
48982 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
48983 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
48984 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
48985 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
48986 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
48987 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
48988 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
48989 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
48990 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
48991 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
48992 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
48993 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
48994 seq_printf(m, "\nQueryInfos: %d sent %d failed",
48995 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
48996 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
48997 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
48998 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
48999 seq_printf(m, "\nSetInfos: %d sent %d failed",
49000 - atomic_read(&sent[SMB2_SET_INFO_HE]),
49001 - atomic_read(&failed[SMB2_SET_INFO_HE]));
49002 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
49003 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
49004 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
49005 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
49006 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
49007 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
49008 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
49009 #endif
49010 }
49011
49012 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
49013 index 41d9d07..dbb4772 100644
49014 --- a/fs/cifs/smb2pdu.c
49015 +++ b/fs/cifs/smb2pdu.c
49016 @@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
49017 default:
49018 cERROR(1, "info level %u isn't supported",
49019 srch_inf->info_level);
49020 - rc = -EINVAL;
49021 - goto qdir_exit;
49022 + return -EINVAL;
49023 }
49024
49025 req->FileIndex = cpu_to_le32(index);
49026 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
49027 index 958ae0e..505c9d0 100644
49028 --- a/fs/coda/cache.c
49029 +++ b/fs/coda/cache.c
49030 @@ -24,7 +24,7 @@
49031 #include "coda_linux.h"
49032 #include "coda_cache.h"
49033
49034 -static atomic_t permission_epoch = ATOMIC_INIT(0);
49035 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
49036
49037 /* replace or extend an acl cache hit */
49038 void coda_cache_enter(struct inode *inode, int mask)
49039 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
49040 struct coda_inode_info *cii = ITOC(inode);
49041
49042 spin_lock(&cii->c_lock);
49043 - cii->c_cached_epoch = atomic_read(&permission_epoch);
49044 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
49045 if (cii->c_uid != current_fsuid()) {
49046 cii->c_uid = current_fsuid();
49047 cii->c_cached_perm = mask;
49048 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
49049 {
49050 struct coda_inode_info *cii = ITOC(inode);
49051 spin_lock(&cii->c_lock);
49052 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
49053 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
49054 spin_unlock(&cii->c_lock);
49055 }
49056
49057 /* remove all acl caches */
49058 void coda_cache_clear_all(struct super_block *sb)
49059 {
49060 - atomic_inc(&permission_epoch);
49061 + atomic_inc_unchecked(&permission_epoch);
49062 }
49063
49064
49065 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
49066 spin_lock(&cii->c_lock);
49067 hit = (mask & cii->c_cached_perm) == mask &&
49068 cii->c_uid == current_fsuid() &&
49069 - cii->c_cached_epoch == atomic_read(&permission_epoch);
49070 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
49071 spin_unlock(&cii->c_lock);
49072
49073 return hit;
49074 diff --git a/fs/compat.c b/fs/compat.c
49075 index a06dcbc..dacb6d3 100644
49076 --- a/fs/compat.c
49077 +++ b/fs/compat.c
49078 @@ -54,7 +54,7 @@
49079 #include <asm/ioctls.h>
49080 #include "internal.h"
49081
49082 -int compat_log = 1;
49083 +int compat_log = 0;
49084
49085 int compat_printk(const char *fmt, ...)
49086 {
49087 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
49088
49089 set_fs(KERNEL_DS);
49090 /* The __user pointer cast is valid because of the set_fs() */
49091 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
49092 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
49093 set_fs(oldfs);
49094 /* truncating is ok because it's a user address */
49095 if (!ret)
49096 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
49097 goto out;
49098
49099 ret = -EINVAL;
49100 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
49101 + if (nr_segs > UIO_MAXIOV)
49102 goto out;
49103 if (nr_segs > fast_segs) {
49104 ret = -ENOMEM;
49105 @@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
49106
49107 struct compat_readdir_callback {
49108 struct compat_old_linux_dirent __user *dirent;
49109 + struct file * file;
49110 int result;
49111 };
49112
49113 @@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
49114 buf->result = -EOVERFLOW;
49115 return -EOVERFLOW;
49116 }
49117 +
49118 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49119 + return 0;
49120 +
49121 buf->result++;
49122 dirent = buf->dirent;
49123 if (!access_ok(VERIFY_WRITE, dirent,
49124 @@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
49125
49126 buf.result = 0;
49127 buf.dirent = dirent;
49128 + buf.file = f.file;
49129
49130 error = vfs_readdir(f.file, compat_fillonedir, &buf);
49131 if (buf.result)
49132 @@ -901,6 +907,7 @@ struct compat_linux_dirent {
49133 struct compat_getdents_callback {
49134 struct compat_linux_dirent __user *current_dir;
49135 struct compat_linux_dirent __user *previous;
49136 + struct file * file;
49137 int count;
49138 int error;
49139 };
49140 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
49141 buf->error = -EOVERFLOW;
49142 return -EOVERFLOW;
49143 }
49144 +
49145 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49146 + return 0;
49147 +
49148 dirent = buf->previous;
49149 if (dirent) {
49150 if (__put_user(offset, &dirent->d_off))
49151 @@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49152 buf.previous = NULL;
49153 buf.count = count;
49154 buf.error = 0;
49155 + buf.file = f.file;
49156
49157 error = vfs_readdir(f.file, compat_filldir, &buf);
49158 if (error >= 0)
49159 @@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49160 struct compat_getdents_callback64 {
49161 struct linux_dirent64 __user *current_dir;
49162 struct linux_dirent64 __user *previous;
49163 + struct file * file;
49164 int count;
49165 int error;
49166 };
49167 @@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
49168 buf->error = -EINVAL; /* only used if we fail.. */
49169 if (reclen > buf->count)
49170 return -EINVAL;
49171 +
49172 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49173 + return 0;
49174 +
49175 dirent = buf->previous;
49176
49177 if (dirent) {
49178 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
49179 buf.previous = NULL;
49180 buf.count = count;
49181 buf.error = 0;
49182 + buf.file = f.file;
49183
49184 error = vfs_readdir(f.file, compat_filldir64, &buf);
49185 if (error >= 0)
49186 error = buf.error;
49187 lastdirent = buf.previous;
49188 if (lastdirent) {
49189 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
49190 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
49191 if (__put_user_unaligned(d_off, &lastdirent->d_off))
49192 error = -EFAULT;
49193 else
49194 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
49195 index a81147e..20bf2b5 100644
49196 --- a/fs/compat_binfmt_elf.c
49197 +++ b/fs/compat_binfmt_elf.c
49198 @@ -30,11 +30,13 @@
49199 #undef elf_phdr
49200 #undef elf_shdr
49201 #undef elf_note
49202 +#undef elf_dyn
49203 #undef elf_addr_t
49204 #define elfhdr elf32_hdr
49205 #define elf_phdr elf32_phdr
49206 #define elf_shdr elf32_shdr
49207 #define elf_note elf32_note
49208 +#define elf_dyn Elf32_Dyn
49209 #define elf_addr_t Elf32_Addr
49210
49211 /*
49212 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
49213 index e2f57a0..3c78771 100644
49214 --- a/fs/compat_ioctl.c
49215 +++ b/fs/compat_ioctl.c
49216 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
49217 return -EFAULT;
49218 if (__get_user(udata, &ss32->iomem_base))
49219 return -EFAULT;
49220 - ss.iomem_base = compat_ptr(udata);
49221 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
49222 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
49223 __get_user(ss.port_high, &ss32->port_high))
49224 return -EFAULT;
49225 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
49226 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
49227 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
49228 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
49229 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49230 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49231 return -EFAULT;
49232
49233 return ioctl_preallocate(file, p);
49234 @@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
49235 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
49236 {
49237 unsigned int a, b;
49238 - a = *(unsigned int *)p;
49239 - b = *(unsigned int *)q;
49240 + a = *(const unsigned int *)p;
49241 + b = *(const unsigned int *)q;
49242 if (a > b)
49243 return 1;
49244 if (a < b)
49245 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
49246 index 712b10f..c33c4ca 100644
49247 --- a/fs/configfs/dir.c
49248 +++ b/fs/configfs/dir.c
49249 @@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
49250 static int configfs_depend_prep(struct dentry *origin,
49251 struct config_item *target)
49252 {
49253 - struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
49254 + struct configfs_dirent *child_sd, *sd;
49255 int ret = 0;
49256
49257 - BUG_ON(!origin || !sd);
49258 + BUG_ON(!origin || !origin->d_fsdata);
49259 + sd = origin->d_fsdata;
49260
49261 if (sd->s_element == target) /* Boo-yah */
49262 goto out;
49263 @@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49264 }
49265 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
49266 struct configfs_dirent *next;
49267 - const char * name;
49268 + const unsigned char * name;
49269 + char d_name[sizeof(next->s_dentry->d_iname)];
49270 int len;
49271 struct inode *inode = NULL;
49272
49273 @@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49274 continue;
49275
49276 name = configfs_get_name(next);
49277 - len = strlen(name);
49278 + if (next->s_dentry && name == next->s_dentry->d_iname) {
49279 + len = next->s_dentry->d_name.len;
49280 + memcpy(d_name, name, len);
49281 + name = d_name;
49282 + } else
49283 + len = strlen(name);
49284
49285 /*
49286 * We'll have a dentry and an inode for
49287 diff --git a/fs/coredump.c b/fs/coredump.c
49288 index 1774932..5812106 100644
49289 --- a/fs/coredump.c
49290 +++ b/fs/coredump.c
49291 @@ -52,7 +52,7 @@ struct core_name {
49292 char *corename;
49293 int used, size;
49294 };
49295 -static atomic_t call_count = ATOMIC_INIT(1);
49296 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
49297
49298 /* The maximal length of core_pattern is also specified in sysctl.c */
49299
49300 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
49301 {
49302 char *old_corename = cn->corename;
49303
49304 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
49305 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
49306 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
49307
49308 if (!cn->corename) {
49309 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
49310 int pid_in_pattern = 0;
49311 int err = 0;
49312
49313 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
49314 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
49315 cn->corename = kmalloc(cn->size, GFP_KERNEL);
49316 cn->used = 0;
49317
49318 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
49319 pipe = file->f_path.dentry->d_inode->i_pipe;
49320
49321 pipe_lock(pipe);
49322 - pipe->readers++;
49323 - pipe->writers--;
49324 + atomic_inc(&pipe->readers);
49325 + atomic_dec(&pipe->writers);
49326
49327 - while ((pipe->readers > 1) && (!signal_pending(current))) {
49328 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
49329 wake_up_interruptible_sync(&pipe->wait);
49330 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49331 pipe_wait(pipe);
49332 }
49333
49334 - pipe->readers--;
49335 - pipe->writers++;
49336 + atomic_dec(&pipe->readers);
49337 + atomic_inc(&pipe->writers);
49338 pipe_unlock(pipe);
49339
49340 }
49341 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
49342 int ispipe;
49343 struct files_struct *displaced;
49344 bool need_nonrelative = false;
49345 - static atomic_t core_dump_count = ATOMIC_INIT(0);
49346 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
49347 + long signr = siginfo->si_signo;
49348 struct coredump_params cprm = {
49349 .siginfo = siginfo,
49350 .regs = signal_pt_regs(),
49351 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
49352 .mm_flags = mm->flags,
49353 };
49354
49355 - audit_core_dumps(siginfo->si_signo);
49356 + audit_core_dumps(signr);
49357 +
49358 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
49359 + gr_handle_brute_attach(cprm.mm_flags);
49360
49361 binfmt = mm->binfmt;
49362 if (!binfmt || !binfmt->core_dump)
49363 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
49364 need_nonrelative = true;
49365 }
49366
49367 - retval = coredump_wait(siginfo->si_signo, &core_state);
49368 + retval = coredump_wait(signr, &core_state);
49369 if (retval < 0)
49370 goto fail_creds;
49371
49372 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
49373 }
49374 cprm.limit = RLIM_INFINITY;
49375
49376 - dump_count = atomic_inc_return(&core_dump_count);
49377 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
49378 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
49379 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
49380 task_tgid_vnr(current), current->comm);
49381 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
49382 } else {
49383 struct inode *inode;
49384
49385 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
49386 +
49387 if (cprm.limit < binfmt->min_coredump)
49388 goto fail_unlock;
49389
49390 @@ -640,7 +646,7 @@ close_fail:
49391 filp_close(cprm.file, NULL);
49392 fail_dropcount:
49393 if (ispipe)
49394 - atomic_dec(&core_dump_count);
49395 + atomic_dec_unchecked(&core_dump_count);
49396 fail_unlock:
49397 kfree(cn.corename);
49398 fail_corename:
49399 @@ -659,7 +665,7 @@ fail:
49400 */
49401 int dump_write(struct file *file, const void *addr, int nr)
49402 {
49403 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
49404 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
49405 }
49406 EXPORT_SYMBOL(dump_write);
49407
49408 diff --git a/fs/dcache.c b/fs/dcache.c
49409 index 19153a0..428c2f5 100644
49410 --- a/fs/dcache.c
49411 +++ b/fs/dcache.c
49412 @@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
49413 mempages -= reserve;
49414
49415 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
49416 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
49417 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
49418
49419 dcache_init();
49420 inode_init();
49421 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
49422 index a5f12b7..4ee8a6f 100644
49423 --- a/fs/debugfs/inode.c
49424 +++ b/fs/debugfs/inode.c
49425 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
49426 */
49427 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
49428 {
49429 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49430 + return __create_file(name, S_IFDIR | S_IRWXU,
49431 +#else
49432 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
49433 +#endif
49434 parent, NULL, NULL);
49435 }
49436 EXPORT_SYMBOL_GPL(debugfs_create_dir);
49437 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
49438 index cc7709e..7e7211f 100644
49439 --- a/fs/ecryptfs/inode.c
49440 +++ b/fs/ecryptfs/inode.c
49441 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
49442 old_fs = get_fs();
49443 set_fs(get_ds());
49444 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
49445 - (char __user *)lower_buf,
49446 + (char __force_user *)lower_buf,
49447 PATH_MAX);
49448 set_fs(old_fs);
49449 if (rc < 0)
49450 @@ -706,7 +706,7 @@ out:
49451 static void
49452 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
49453 {
49454 - char *buf = nd_get_link(nd);
49455 + const char *buf = nd_get_link(nd);
49456 if (!IS_ERR(buf)) {
49457 /* Free the char* */
49458 kfree(buf);
49459 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
49460 index 412e6ed..4292d22 100644
49461 --- a/fs/ecryptfs/miscdev.c
49462 +++ b/fs/ecryptfs/miscdev.c
49463 @@ -315,7 +315,7 @@ check_list:
49464 goto out_unlock_msg_ctx;
49465 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
49466 if (msg_ctx->msg) {
49467 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
49468 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
49469 goto out_unlock_msg_ctx;
49470 i += packet_length_size;
49471 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
49472 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
49473 index b2a34a1..162fa69 100644
49474 --- a/fs/ecryptfs/read_write.c
49475 +++ b/fs/ecryptfs/read_write.c
49476 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
49477 return -EIO;
49478 fs_save = get_fs();
49479 set_fs(get_ds());
49480 - rc = vfs_write(lower_file, data, size, &offset);
49481 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
49482 set_fs(fs_save);
49483 mark_inode_dirty_sync(ecryptfs_inode);
49484 return rc;
49485 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
49486 return -EIO;
49487 fs_save = get_fs();
49488 set_fs(get_ds());
49489 - rc = vfs_read(lower_file, data, size, &offset);
49490 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
49491 set_fs(fs_save);
49492 return rc;
49493 }
49494 diff --git a/fs/exec.c b/fs/exec.c
49495 index 20df02c..81c9e78 100644
49496 --- a/fs/exec.c
49497 +++ b/fs/exec.c
49498 @@ -55,6 +55,17 @@
49499 #include <linux/pipe_fs_i.h>
49500 #include <linux/oom.h>
49501 #include <linux/compat.h>
49502 +#include <linux/random.h>
49503 +#include <linux/seq_file.h>
49504 +#include <linux/coredump.h>
49505 +#include <linux/mman.h>
49506 +
49507 +#ifdef CONFIG_PAX_REFCOUNT
49508 +#include <linux/kallsyms.h>
49509 +#include <linux/kdebug.h>
49510 +#endif
49511 +
49512 +#include <trace/events/fs.h>
49513
49514 #include <asm/uaccess.h>
49515 #include <asm/mmu_context.h>
49516 @@ -66,6 +77,18 @@
49517
49518 #include <trace/events/sched.h>
49519
49520 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49521 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
49522 +{
49523 + 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");
49524 +}
49525 +#endif
49526 +
49527 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
49528 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
49529 +EXPORT_SYMBOL(pax_set_initial_flags_func);
49530 +#endif
49531 +
49532 int suid_dumpable = 0;
49533
49534 static LIST_HEAD(formats);
49535 @@ -75,8 +98,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
49536 {
49537 BUG_ON(!fmt);
49538 write_lock(&binfmt_lock);
49539 - insert ? list_add(&fmt->lh, &formats) :
49540 - list_add_tail(&fmt->lh, &formats);
49541 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
49542 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
49543 write_unlock(&binfmt_lock);
49544 }
49545
49546 @@ -85,7 +108,7 @@ EXPORT_SYMBOL(__register_binfmt);
49547 void unregister_binfmt(struct linux_binfmt * fmt)
49548 {
49549 write_lock(&binfmt_lock);
49550 - list_del(&fmt->lh);
49551 + pax_list_del((struct list_head *)&fmt->lh);
49552 write_unlock(&binfmt_lock);
49553 }
49554
49555 @@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
49556 int write)
49557 {
49558 struct page *page;
49559 - int ret;
49560
49561 -#ifdef CONFIG_STACK_GROWSUP
49562 - if (write) {
49563 - ret = expand_downwards(bprm->vma, pos);
49564 - if (ret < 0)
49565 - return NULL;
49566 - }
49567 -#endif
49568 - ret = get_user_pages(current, bprm->mm, pos,
49569 - 1, write, 1, &page, NULL);
49570 - if (ret <= 0)
49571 + if (0 > expand_downwards(bprm->vma, pos))
49572 + return NULL;
49573 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
49574 return NULL;
49575
49576 if (write) {
49577 @@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
49578 if (size <= ARG_MAX)
49579 return page;
49580
49581 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49582 + // only allow 512KB for argv+env on suid/sgid binaries
49583 + // to prevent easy ASLR exhaustion
49584 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
49585 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
49586 + (size > (512 * 1024))) {
49587 + put_page(page);
49588 + return NULL;
49589 + }
49590 +#endif
49591 +
49592 /*
49593 * Limit to 1/4-th the stack size for the argv+env strings.
49594 * This ensures that:
49595 @@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
49596 vma->vm_end = STACK_TOP_MAX;
49597 vma->vm_start = vma->vm_end - PAGE_SIZE;
49598 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
49599 +
49600 +#ifdef CONFIG_PAX_SEGMEXEC
49601 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
49602 +#endif
49603 +
49604 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
49605 INIT_LIST_HEAD(&vma->anon_vma_chain);
49606
49607 @@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
49608 mm->stack_vm = mm->total_vm = 1;
49609 up_write(&mm->mmap_sem);
49610 bprm->p = vma->vm_end - sizeof(void *);
49611 +
49612 +#ifdef CONFIG_PAX_RANDUSTACK
49613 + if (randomize_va_space)
49614 + bprm->p ^= random32() & ~PAGE_MASK;
49615 +#endif
49616 +
49617 return 0;
49618 err:
49619 up_write(&mm->mmap_sem);
49620 @@ -384,19 +421,7 @@ err:
49621 return err;
49622 }
49623
49624 -struct user_arg_ptr {
49625 -#ifdef CONFIG_COMPAT
49626 - bool is_compat;
49627 -#endif
49628 - union {
49629 - const char __user *const __user *native;
49630 -#ifdef CONFIG_COMPAT
49631 - const compat_uptr_t __user *compat;
49632 -#endif
49633 - } ptr;
49634 -};
49635 -
49636 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49637 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49638 {
49639 const char __user *native;
49640
49641 @@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49642 compat_uptr_t compat;
49643
49644 if (get_user(compat, argv.ptr.compat + nr))
49645 - return ERR_PTR(-EFAULT);
49646 + return (const char __force_user *)ERR_PTR(-EFAULT);
49647
49648 return compat_ptr(compat);
49649 }
49650 #endif
49651
49652 if (get_user(native, argv.ptr.native + nr))
49653 - return ERR_PTR(-EFAULT);
49654 + return (const char __force_user *)ERR_PTR(-EFAULT);
49655
49656 return native;
49657 }
49658 @@ -431,7 +456,7 @@ static int count(struct user_arg_ptr argv, int max)
49659 if (!p)
49660 break;
49661
49662 - if (IS_ERR(p))
49663 + if (IS_ERR((const char __force_kernel *)p))
49664 return -EFAULT;
49665
49666 if (i >= max)
49667 @@ -466,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
49668
49669 ret = -EFAULT;
49670 str = get_user_arg_ptr(argv, argc);
49671 - if (IS_ERR(str))
49672 + if (IS_ERR((const char __force_kernel *)str))
49673 goto out;
49674
49675 len = strnlen_user(str, MAX_ARG_STRLEN);
49676 @@ -548,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
49677 int r;
49678 mm_segment_t oldfs = get_fs();
49679 struct user_arg_ptr argv = {
49680 - .ptr.native = (const char __user *const __user *)__argv,
49681 + .ptr.native = (const char __force_user *const __force_user *)__argv,
49682 };
49683
49684 set_fs(KERNEL_DS);
49685 @@ -583,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
49686 unsigned long new_end = old_end - shift;
49687 struct mmu_gather tlb;
49688
49689 - BUG_ON(new_start > new_end);
49690 + if (new_start >= new_end || new_start < mmap_min_addr)
49691 + return -ENOMEM;
49692
49693 /*
49694 * ensure there are no vmas between where we want to go
49695 @@ -592,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
49696 if (vma != find_vma(mm, new_start))
49697 return -EFAULT;
49698
49699 +#ifdef CONFIG_PAX_SEGMEXEC
49700 + BUG_ON(pax_find_mirror_vma(vma));
49701 +#endif
49702 +
49703 /*
49704 * cover the whole range: [new_start, old_end)
49705 */
49706 @@ -672,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
49707 stack_top = arch_align_stack(stack_top);
49708 stack_top = PAGE_ALIGN(stack_top);
49709
49710 - if (unlikely(stack_top < mmap_min_addr) ||
49711 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
49712 - return -ENOMEM;
49713 -
49714 stack_shift = vma->vm_end - stack_top;
49715
49716 bprm->p -= stack_shift;
49717 @@ -687,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
49718 bprm->exec -= stack_shift;
49719
49720 down_write(&mm->mmap_sem);
49721 +
49722 + /* Move stack pages down in memory. */
49723 + if (stack_shift) {
49724 + ret = shift_arg_pages(vma, stack_shift);
49725 + if (ret)
49726 + goto out_unlock;
49727 + }
49728 +
49729 vm_flags = VM_STACK_FLAGS;
49730
49731 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49732 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49733 + vm_flags &= ~VM_EXEC;
49734 +
49735 +#ifdef CONFIG_PAX_MPROTECT
49736 + if (mm->pax_flags & MF_PAX_MPROTECT)
49737 + vm_flags &= ~VM_MAYEXEC;
49738 +#endif
49739 +
49740 + }
49741 +#endif
49742 +
49743 /*
49744 * Adjust stack execute permissions; explicitly enable for
49745 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
49746 @@ -707,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
49747 goto out_unlock;
49748 BUG_ON(prev != vma);
49749
49750 - /* Move stack pages down in memory. */
49751 - if (stack_shift) {
49752 - ret = shift_arg_pages(vma, stack_shift);
49753 - if (ret)
49754 - goto out_unlock;
49755 - }
49756 -
49757 /* mprotect_fixup is overkill to remove the temporary stack flags */
49758 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
49759
49760 @@ -737,6 +776,30 @@ int setup_arg_pages(struct linux_binprm *bprm,
49761 #endif
49762 current->mm->start_stack = bprm->p;
49763 ret = expand_stack(vma, stack_base);
49764 +
49765 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
49766 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
49767 + unsigned long size, flags, vm_flags;
49768 +
49769 + size = STACK_TOP - vma->vm_end;
49770 + flags = MAP_FIXED | MAP_PRIVATE;
49771 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
49772 +
49773 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
49774 +
49775 +#ifdef CONFIG_X86
49776 + if (!ret) {
49777 + current->mm->aslr_gap += size >> PAGE_SHIFT;
49778 + size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
49779 + ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
49780 + if (!ret)
49781 + current->mm->aslr_gap += size >> PAGE_SHIFT;
49782 + }
49783 +#endif
49784 +
49785 + }
49786 +#endif
49787 +
49788 if (ret)
49789 ret = -EFAULT;
49790
49791 @@ -772,6 +835,8 @@ struct file *open_exec(const char *name)
49792
49793 fsnotify_open(file);
49794
49795 + trace_open_exec(name);
49796 +
49797 err = deny_write_access(file);
49798 if (err)
49799 goto exit;
49800 @@ -795,7 +860,7 @@ int kernel_read(struct file *file, loff_t offset,
49801 old_fs = get_fs();
49802 set_fs(get_ds());
49803 /* The cast to a user pointer is valid due to the set_fs() */
49804 - result = vfs_read(file, (void __user *)addr, count, &pos);
49805 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
49806 set_fs(old_fs);
49807 return result;
49808 }
49809 @@ -1247,7 +1312,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
49810 }
49811 rcu_read_unlock();
49812
49813 - if (p->fs->users > n_fs) {
49814 + if (atomic_read(&p->fs->users) > n_fs) {
49815 bprm->unsafe |= LSM_UNSAFE_SHARE;
49816 } else {
49817 res = -EAGAIN;
49818 @@ -1447,6 +1512,28 @@ int search_binary_handler(struct linux_binprm *bprm)
49819
49820 EXPORT_SYMBOL(search_binary_handler);
49821
49822 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49823 +static DEFINE_PER_CPU(u64, exec_counter);
49824 +static int __init init_exec_counters(void)
49825 +{
49826 + unsigned int cpu;
49827 +
49828 + for_each_possible_cpu(cpu) {
49829 + per_cpu(exec_counter, cpu) = (u64)cpu;
49830 + }
49831 +
49832 + return 0;
49833 +}
49834 +early_initcall(init_exec_counters);
49835 +static inline void increment_exec_counter(void)
49836 +{
49837 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
49838 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
49839 +}
49840 +#else
49841 +static inline void increment_exec_counter(void) {}
49842 +#endif
49843 +
49844 /*
49845 * sys_execve() executes a new program.
49846 */
49847 @@ -1454,6 +1541,11 @@ static int do_execve_common(const char *filename,
49848 struct user_arg_ptr argv,
49849 struct user_arg_ptr envp)
49850 {
49851 +#ifdef CONFIG_GRKERNSEC
49852 + struct file *old_exec_file;
49853 + struct acl_subject_label *old_acl;
49854 + struct rlimit old_rlim[RLIM_NLIMITS];
49855 +#endif
49856 struct linux_binprm *bprm;
49857 struct file *file;
49858 struct files_struct *displaced;
49859 @@ -1461,6 +1553,8 @@ static int do_execve_common(const char *filename,
49860 int retval;
49861 const struct cred *cred = current_cred();
49862
49863 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
49864 +
49865 /*
49866 * We move the actual failure in case of RLIMIT_NPROC excess from
49867 * set*uid() to execve() because too many poorly written programs
49868 @@ -1501,12 +1595,27 @@ static int do_execve_common(const char *filename,
49869 if (IS_ERR(file))
49870 goto out_unmark;
49871
49872 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
49873 + retval = -EPERM;
49874 + goto out_file;
49875 + }
49876 +
49877 sched_exec();
49878
49879 bprm->file = file;
49880 bprm->filename = filename;
49881 bprm->interp = filename;
49882
49883 + if (gr_process_user_ban()) {
49884 + retval = -EPERM;
49885 + goto out_file;
49886 + }
49887 +
49888 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
49889 + retval = -EACCES;
49890 + goto out_file;
49891 + }
49892 +
49893 retval = bprm_mm_init(bprm);
49894 if (retval)
49895 goto out_file;
49896 @@ -1523,24 +1632,65 @@ static int do_execve_common(const char *filename,
49897 if (retval < 0)
49898 goto out;
49899
49900 +#ifdef CONFIG_GRKERNSEC
49901 + old_acl = current->acl;
49902 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
49903 + old_exec_file = current->exec_file;
49904 + get_file(file);
49905 + current->exec_file = file;
49906 +#endif
49907 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49908 + /* limit suid stack to 8MB
49909 + * we saved the old limits above and will restore them if this exec fails
49910 + */
49911 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
49912 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
49913 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
49914 +#endif
49915 +
49916 + if (!gr_tpe_allow(file)) {
49917 + retval = -EACCES;
49918 + goto out_fail;
49919 + }
49920 +
49921 + if (gr_check_crash_exec(file)) {
49922 + retval = -EACCES;
49923 + goto out_fail;
49924 + }
49925 +
49926 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
49927 + bprm->unsafe);
49928 + if (retval < 0)
49929 + goto out_fail;
49930 +
49931 retval = copy_strings_kernel(1, &bprm->filename, bprm);
49932 if (retval < 0)
49933 - goto out;
49934 + goto out_fail;
49935
49936 bprm->exec = bprm->p;
49937 retval = copy_strings(bprm->envc, envp, bprm);
49938 if (retval < 0)
49939 - goto out;
49940 + goto out_fail;
49941
49942 retval = copy_strings(bprm->argc, argv, bprm);
49943 if (retval < 0)
49944 - goto out;
49945 + goto out_fail;
49946 +
49947 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
49948 +
49949 + gr_handle_exec_args(bprm, argv);
49950
49951 retval = search_binary_handler(bprm);
49952 if (retval < 0)
49953 - goto out;
49954 + goto out_fail;
49955 +#ifdef CONFIG_GRKERNSEC
49956 + if (old_exec_file)
49957 + fput(old_exec_file);
49958 +#endif
49959
49960 /* execve succeeded */
49961 +
49962 + increment_exec_counter();
49963 current->fs->in_exec = 0;
49964 current->in_execve = 0;
49965 acct_update_integrals(current);
49966 @@ -1549,6 +1699,14 @@ static int do_execve_common(const char *filename,
49967 put_files_struct(displaced);
49968 return retval;
49969
49970 +out_fail:
49971 +#ifdef CONFIG_GRKERNSEC
49972 + current->acl = old_acl;
49973 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
49974 + fput(current->exec_file);
49975 + current->exec_file = old_exec_file;
49976 +#endif
49977 +
49978 out:
49979 if (bprm->mm) {
49980 acct_arg_size(bprm, 0);
49981 @@ -1697,3 +1855,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
49982 return error;
49983 }
49984 #endif
49985 +
49986 +int pax_check_flags(unsigned long *flags)
49987 +{
49988 + int retval = 0;
49989 +
49990 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
49991 + if (*flags & MF_PAX_SEGMEXEC)
49992 + {
49993 + *flags &= ~MF_PAX_SEGMEXEC;
49994 + retval = -EINVAL;
49995 + }
49996 +#endif
49997 +
49998 + if ((*flags & MF_PAX_PAGEEXEC)
49999 +
50000 +#ifdef CONFIG_PAX_PAGEEXEC
50001 + && (*flags & MF_PAX_SEGMEXEC)
50002 +#endif
50003 +
50004 + )
50005 + {
50006 + *flags &= ~MF_PAX_PAGEEXEC;
50007 + retval = -EINVAL;
50008 + }
50009 +
50010 + if ((*flags & MF_PAX_MPROTECT)
50011 +
50012 +#ifdef CONFIG_PAX_MPROTECT
50013 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50014 +#endif
50015 +
50016 + )
50017 + {
50018 + *flags &= ~MF_PAX_MPROTECT;
50019 + retval = -EINVAL;
50020 + }
50021 +
50022 + if ((*flags & MF_PAX_EMUTRAMP)
50023 +
50024 +#ifdef CONFIG_PAX_EMUTRAMP
50025 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50026 +#endif
50027 +
50028 + )
50029 + {
50030 + *flags &= ~MF_PAX_EMUTRAMP;
50031 + retval = -EINVAL;
50032 + }
50033 +
50034 + return retval;
50035 +}
50036 +
50037 +EXPORT_SYMBOL(pax_check_flags);
50038 +
50039 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50040 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
50041 +{
50042 + struct task_struct *tsk = current;
50043 + struct mm_struct *mm = current->mm;
50044 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
50045 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
50046 + char *path_exec = NULL;
50047 + char *path_fault = NULL;
50048 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
50049 + siginfo_t info = { };
50050 +
50051 + if (buffer_exec && buffer_fault) {
50052 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
50053 +
50054 + down_read(&mm->mmap_sem);
50055 + vma = mm->mmap;
50056 + while (vma && (!vma_exec || !vma_fault)) {
50057 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
50058 + vma_exec = vma;
50059 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
50060 + vma_fault = vma;
50061 + vma = vma->vm_next;
50062 + }
50063 + if (vma_exec) {
50064 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
50065 + if (IS_ERR(path_exec))
50066 + path_exec = "<path too long>";
50067 + else {
50068 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
50069 + if (path_exec) {
50070 + *path_exec = 0;
50071 + path_exec = buffer_exec;
50072 + } else
50073 + path_exec = "<path too long>";
50074 + }
50075 + }
50076 + if (vma_fault) {
50077 + start = vma_fault->vm_start;
50078 + end = vma_fault->vm_end;
50079 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
50080 + if (vma_fault->vm_file) {
50081 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
50082 + if (IS_ERR(path_fault))
50083 + path_fault = "<path too long>";
50084 + else {
50085 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
50086 + if (path_fault) {
50087 + *path_fault = 0;
50088 + path_fault = buffer_fault;
50089 + } else
50090 + path_fault = "<path too long>";
50091 + }
50092 + } else
50093 + path_fault = "<anonymous mapping>";
50094 + }
50095 + up_read(&mm->mmap_sem);
50096 + }
50097 + if (tsk->signal->curr_ip)
50098 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
50099 + else
50100 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
50101 + 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),
50102 + from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
50103 + free_page((unsigned long)buffer_exec);
50104 + free_page((unsigned long)buffer_fault);
50105 + pax_report_insns(regs, pc, sp);
50106 + info.si_signo = SIGKILL;
50107 + info.si_errno = 0;
50108 + info.si_code = SI_KERNEL;
50109 + info.si_pid = 0;
50110 + info.si_uid = 0;
50111 + do_coredump(&info);
50112 +}
50113 +#endif
50114 +
50115 +#ifdef CONFIG_PAX_REFCOUNT
50116 +void pax_report_refcount_overflow(struct pt_regs *regs)
50117 +{
50118 + if (current->signal->curr_ip)
50119 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
50120 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
50121 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
50122 + else
50123 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
50124 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
50125 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
50126 + show_regs(regs);
50127 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
50128 +}
50129 +#endif
50130 +
50131 +#ifdef CONFIG_PAX_USERCOPY
50132 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
50133 +static noinline int check_stack_object(const void *obj, unsigned long len)
50134 +{
50135 + const void * const stack = task_stack_page(current);
50136 + const void * const stackend = stack + THREAD_SIZE;
50137 +
50138 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50139 + const void *frame = NULL;
50140 + const void *oldframe;
50141 +#endif
50142 +
50143 + if (obj + len < obj)
50144 + return -1;
50145 +
50146 + if (obj + len <= stack || stackend <= obj)
50147 + return 0;
50148 +
50149 + if (obj < stack || stackend < obj + len)
50150 + return -1;
50151 +
50152 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50153 + oldframe = __builtin_frame_address(1);
50154 + if (oldframe)
50155 + frame = __builtin_frame_address(2);
50156 + /*
50157 + low ----------------------------------------------> high
50158 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
50159 + ^----------------^
50160 + allow copies only within here
50161 + */
50162 + while (stack <= frame && frame < stackend) {
50163 + /* if obj + len extends past the last frame, this
50164 + check won't pass and the next frame will be 0,
50165 + causing us to bail out and correctly report
50166 + the copy as invalid
50167 + */
50168 + if (obj + len <= frame)
50169 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
50170 + oldframe = frame;
50171 + frame = *(const void * const *)frame;
50172 + }
50173 + return -1;
50174 +#else
50175 + return 1;
50176 +#endif
50177 +}
50178 +
50179 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
50180 +{
50181 + if (current->signal->curr_ip)
50182 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50183 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50184 + else
50185 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50186 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50187 + dump_stack();
50188 + gr_handle_kernel_exploit();
50189 + do_group_exit(SIGKILL);
50190 +}
50191 +#endif
50192 +
50193 +void __check_object_size(const void *ptr, unsigned long n, bool to)
50194 +{
50195 +
50196 +#ifdef CONFIG_PAX_USERCOPY
50197 + const char *type;
50198 +
50199 + if (!n)
50200 + return;
50201 +
50202 + type = check_heap_object(ptr, n);
50203 + if (!type) {
50204 + if (check_stack_object(ptr, n) != -1)
50205 + return;
50206 + type = "<process stack>";
50207 + }
50208 +
50209 + pax_report_usercopy(ptr, n, to, type);
50210 +#endif
50211 +
50212 +}
50213 +EXPORT_SYMBOL(__check_object_size);
50214 +
50215 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
50216 +void pax_track_stack(void)
50217 +{
50218 + unsigned long sp = (unsigned long)&sp;
50219 + if (sp < current_thread_info()->lowest_stack &&
50220 + sp > (unsigned long)task_stack_page(current))
50221 + current_thread_info()->lowest_stack = sp;
50222 +}
50223 +EXPORT_SYMBOL(pax_track_stack);
50224 +#endif
50225 +
50226 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
50227 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
50228 +{
50229 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
50230 + dump_stack();
50231 + do_group_exit(SIGKILL);
50232 +}
50233 +EXPORT_SYMBOL(report_size_overflow);
50234 +#endif
50235 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
50236 index 2616d0e..2ffdec9 100644
50237 --- a/fs/ext2/balloc.c
50238 +++ b/fs/ext2/balloc.c
50239 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
50240
50241 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50242 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50243 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50244 + if (free_blocks < root_blocks + 1 &&
50245 !uid_eq(sbi->s_resuid, current_fsuid()) &&
50246 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50247 - !in_group_p (sbi->s_resgid))) {
50248 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50249 return 0;
50250 }
50251 return 1;
50252 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
50253 index 22548f5..41521d8 100644
50254 --- a/fs/ext3/balloc.c
50255 +++ b/fs/ext3/balloc.c
50256 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
50257
50258 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50259 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50260 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50261 + if (free_blocks < root_blocks + 1 &&
50262 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
50263 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50264 - !in_group_p (sbi->s_resgid))) {
50265 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50266 return 0;
50267 }
50268 return 1;
50269 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
50270 index 92e68b3..115d987 100644
50271 --- a/fs/ext4/balloc.c
50272 +++ b/fs/ext4/balloc.c
50273 @@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
50274 /* Hm, nope. Are (enough) root reserved clusters available? */
50275 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
50276 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
50277 - capable(CAP_SYS_RESOURCE) ||
50278 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
50279 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
50280 + capable_nolog(CAP_SYS_RESOURCE)) {
50281
50282 if (free_clusters >= (nclusters + dirty_clusters))
50283 return 1;
50284 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
50285 index 8462eb3..4a71af6 100644
50286 --- a/fs/ext4/ext4.h
50287 +++ b/fs/ext4/ext4.h
50288 @@ -1265,19 +1265,19 @@ struct ext4_sb_info {
50289 unsigned long s_mb_last_start;
50290
50291 /* stats for buddy allocator */
50292 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
50293 - atomic_t s_bal_success; /* we found long enough chunks */
50294 - atomic_t s_bal_allocated; /* in blocks */
50295 - atomic_t s_bal_ex_scanned; /* total extents scanned */
50296 - atomic_t s_bal_goals; /* goal hits */
50297 - atomic_t s_bal_breaks; /* too long searches */
50298 - atomic_t s_bal_2orders; /* 2^order hits */
50299 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
50300 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
50301 + atomic_unchecked_t s_bal_allocated; /* in blocks */
50302 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
50303 + atomic_unchecked_t s_bal_goals; /* goal hits */
50304 + atomic_unchecked_t s_bal_breaks; /* too long searches */
50305 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
50306 spinlock_t s_bal_lock;
50307 unsigned long s_mb_buddies_generated;
50308 unsigned long long s_mb_generation_time;
50309 - atomic_t s_mb_lost_chunks;
50310 - atomic_t s_mb_preallocated;
50311 - atomic_t s_mb_discarded;
50312 + atomic_unchecked_t s_mb_lost_chunks;
50313 + atomic_unchecked_t s_mb_preallocated;
50314 + atomic_unchecked_t s_mb_discarded;
50315 atomic_t s_lock_busy;
50316
50317 /* locality groups */
50318 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
50319 index 28bbf9b..75ca7c1 100644
50320 --- a/fs/ext4/mballoc.c
50321 +++ b/fs/ext4/mballoc.c
50322 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
50323 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
50324
50325 if (EXT4_SB(sb)->s_mb_stats)
50326 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
50327 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
50328
50329 break;
50330 }
50331 @@ -2044,7 +2044,7 @@ repeat:
50332 ac->ac_status = AC_STATUS_CONTINUE;
50333 ac->ac_flags |= EXT4_MB_HINT_FIRST;
50334 cr = 3;
50335 - atomic_inc(&sbi->s_mb_lost_chunks);
50336 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
50337 goto repeat;
50338 }
50339 }
50340 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
50341 if (sbi->s_mb_stats) {
50342 ext4_msg(sb, KERN_INFO,
50343 "mballoc: %u blocks %u reqs (%u success)",
50344 - atomic_read(&sbi->s_bal_allocated),
50345 - atomic_read(&sbi->s_bal_reqs),
50346 - atomic_read(&sbi->s_bal_success));
50347 + atomic_read_unchecked(&sbi->s_bal_allocated),
50348 + atomic_read_unchecked(&sbi->s_bal_reqs),
50349 + atomic_read_unchecked(&sbi->s_bal_success));
50350 ext4_msg(sb, KERN_INFO,
50351 "mballoc: %u extents scanned, %u goal hits, "
50352 "%u 2^N hits, %u breaks, %u lost",
50353 - atomic_read(&sbi->s_bal_ex_scanned),
50354 - atomic_read(&sbi->s_bal_goals),
50355 - atomic_read(&sbi->s_bal_2orders),
50356 - atomic_read(&sbi->s_bal_breaks),
50357 - atomic_read(&sbi->s_mb_lost_chunks));
50358 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
50359 + atomic_read_unchecked(&sbi->s_bal_goals),
50360 + atomic_read_unchecked(&sbi->s_bal_2orders),
50361 + atomic_read_unchecked(&sbi->s_bal_breaks),
50362 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
50363 ext4_msg(sb, KERN_INFO,
50364 "mballoc: %lu generated and it took %Lu",
50365 sbi->s_mb_buddies_generated,
50366 sbi->s_mb_generation_time);
50367 ext4_msg(sb, KERN_INFO,
50368 "mballoc: %u preallocated, %u discarded",
50369 - atomic_read(&sbi->s_mb_preallocated),
50370 - atomic_read(&sbi->s_mb_discarded));
50371 + atomic_read_unchecked(&sbi->s_mb_preallocated),
50372 + atomic_read_unchecked(&sbi->s_mb_discarded));
50373 }
50374
50375 free_percpu(sbi->s_locality_groups);
50376 @@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
50377 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
50378
50379 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
50380 - atomic_inc(&sbi->s_bal_reqs);
50381 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50382 + atomic_inc_unchecked(&sbi->s_bal_reqs);
50383 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50384 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
50385 - atomic_inc(&sbi->s_bal_success);
50386 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
50387 + atomic_inc_unchecked(&sbi->s_bal_success);
50388 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
50389 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
50390 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
50391 - atomic_inc(&sbi->s_bal_goals);
50392 + atomic_inc_unchecked(&sbi->s_bal_goals);
50393 if (ac->ac_found > sbi->s_mb_max_to_scan)
50394 - atomic_inc(&sbi->s_bal_breaks);
50395 + atomic_inc_unchecked(&sbi->s_bal_breaks);
50396 }
50397
50398 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
50399 @@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
50400 trace_ext4_mb_new_inode_pa(ac, pa);
50401
50402 ext4_mb_use_inode_pa(ac, pa);
50403 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
50404 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
50405
50406 ei = EXT4_I(ac->ac_inode);
50407 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50408 @@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
50409 trace_ext4_mb_new_group_pa(ac, pa);
50410
50411 ext4_mb_use_group_pa(ac, pa);
50412 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50413 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50414
50415 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50416 lg = ac->ac_lg;
50417 @@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
50418 * from the bitmap and continue.
50419 */
50420 }
50421 - atomic_add(free, &sbi->s_mb_discarded);
50422 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
50423
50424 return err;
50425 }
50426 @@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
50427 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
50428 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
50429 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
50430 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50431 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50432 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
50433
50434 return 0;
50435 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
50436 index 5fa223d..12fa738 100644
50437 --- a/fs/ext4/super.c
50438 +++ b/fs/ext4/super.c
50439 @@ -2429,7 +2429,7 @@ struct ext4_attr {
50440 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
50441 const char *, size_t);
50442 int offset;
50443 -};
50444 +} __do_const;
50445
50446 static int parse_strtoul(const char *buf,
50447 unsigned long max, unsigned long *value)
50448 diff --git a/fs/fcntl.c b/fs/fcntl.c
50449 index 71a600a..20d87b1 100644
50450 --- a/fs/fcntl.c
50451 +++ b/fs/fcntl.c
50452 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
50453 if (err)
50454 return err;
50455
50456 + if (gr_handle_chroot_fowner(pid, type))
50457 + return -ENOENT;
50458 + if (gr_check_protected_task_fowner(pid, type))
50459 + return -EACCES;
50460 +
50461 f_modown(filp, pid, type, force);
50462 return 0;
50463 }
50464 diff --git a/fs/fhandle.c b/fs/fhandle.c
50465 index 999ff5c..41f4109 100644
50466 --- a/fs/fhandle.c
50467 +++ b/fs/fhandle.c
50468 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
50469 } else
50470 retval = 0;
50471 /* copy the mount id */
50472 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
50473 - sizeof(*mnt_id)) ||
50474 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
50475 copy_to_user(ufh, handle,
50476 sizeof(struct file_handle) + handle_bytes))
50477 retval = -EFAULT;
50478 diff --git a/fs/fifo.c b/fs/fifo.c
50479 index cf6f434..3d7942c 100644
50480 --- a/fs/fifo.c
50481 +++ b/fs/fifo.c
50482 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
50483 */
50484 filp->f_op = &read_pipefifo_fops;
50485 pipe->r_counter++;
50486 - if (pipe->readers++ == 0)
50487 + if (atomic_inc_return(&pipe->readers) == 1)
50488 wake_up_partner(inode);
50489
50490 - if (!pipe->writers) {
50491 + if (!atomic_read(&pipe->writers)) {
50492 if ((filp->f_flags & O_NONBLOCK)) {
50493 /* suppress POLLHUP until we have
50494 * seen a writer */
50495 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
50496 * errno=ENXIO when there is no process reading the FIFO.
50497 */
50498 ret = -ENXIO;
50499 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
50500 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
50501 goto err;
50502
50503 filp->f_op = &write_pipefifo_fops;
50504 pipe->w_counter++;
50505 - if (!pipe->writers++)
50506 + if (atomic_inc_return(&pipe->writers) == 1)
50507 wake_up_partner(inode);
50508
50509 - if (!pipe->readers) {
50510 + if (!atomic_read(&pipe->readers)) {
50511 if (wait_for_partner(inode, &pipe->r_counter))
50512 goto err_wr;
50513 }
50514 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
50515 */
50516 filp->f_op = &rdwr_pipefifo_fops;
50517
50518 - pipe->readers++;
50519 - pipe->writers++;
50520 + atomic_inc(&pipe->readers);
50521 + atomic_inc(&pipe->writers);
50522 pipe->r_counter++;
50523 pipe->w_counter++;
50524 - if (pipe->readers == 1 || pipe->writers == 1)
50525 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
50526 wake_up_partner(inode);
50527 break;
50528
50529 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
50530 return 0;
50531
50532 err_rd:
50533 - if (!--pipe->readers)
50534 + if (atomic_dec_and_test(&pipe->readers))
50535 wake_up_interruptible(&pipe->wait);
50536 ret = -ERESTARTSYS;
50537 goto err;
50538
50539 err_wr:
50540 - if (!--pipe->writers)
50541 + if (atomic_dec_and_test(&pipe->writers))
50542 wake_up_interruptible(&pipe->wait);
50543 ret = -ERESTARTSYS;
50544 goto err;
50545
50546 err:
50547 - if (!pipe->readers && !pipe->writers)
50548 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
50549 free_pipe_info(inode);
50550
50551 err_nocleanup:
50552 diff --git a/fs/file.c b/fs/file.c
50553 index 2b3570b..c57924b 100644
50554 --- a/fs/file.c
50555 +++ b/fs/file.c
50556 @@ -16,6 +16,7 @@
50557 #include <linux/slab.h>
50558 #include <linux/vmalloc.h>
50559 #include <linux/file.h>
50560 +#include <linux/security.h>
50561 #include <linux/fdtable.h>
50562 #include <linux/bitops.h>
50563 #include <linux/interrupt.h>
50564 @@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
50565 if (!file)
50566 return __close_fd(files, fd);
50567
50568 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
50569 if (fd >= rlimit(RLIMIT_NOFILE))
50570 return -EBADF;
50571
50572 @@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
50573 if (unlikely(oldfd == newfd))
50574 return -EINVAL;
50575
50576 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
50577 if (newfd >= rlimit(RLIMIT_NOFILE))
50578 return -EBADF;
50579
50580 @@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
50581 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
50582 {
50583 int err;
50584 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
50585 if (from >= rlimit(RLIMIT_NOFILE))
50586 return -EINVAL;
50587 err = alloc_fd(from, flags);
50588 diff --git a/fs/filesystems.c b/fs/filesystems.c
50589 index da165f6..3671bdb 100644
50590 --- a/fs/filesystems.c
50591 +++ b/fs/filesystems.c
50592 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
50593 int len = dot ? dot - name : strlen(name);
50594
50595 fs = __get_fs_type(name, len);
50596 +
50597 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
50598 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
50599 +#else
50600 if (!fs && (request_module("%.*s", len, name) == 0))
50601 +#endif
50602 fs = __get_fs_type(name, len);
50603
50604 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
50605 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
50606 index fe6ca58..65318cf 100644
50607 --- a/fs/fs_struct.c
50608 +++ b/fs/fs_struct.c
50609 @@ -4,6 +4,7 @@
50610 #include <linux/path.h>
50611 #include <linux/slab.h>
50612 #include <linux/fs_struct.h>
50613 +#include <linux/grsecurity.h>
50614 #include "internal.h"
50615
50616 /*
50617 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
50618 write_seqcount_begin(&fs->seq);
50619 old_root = fs->root;
50620 fs->root = *path;
50621 + gr_set_chroot_entries(current, path);
50622 write_seqcount_end(&fs->seq);
50623 spin_unlock(&fs->lock);
50624 if (old_root.dentry)
50625 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
50626 return 1;
50627 }
50628
50629 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
50630 +{
50631 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
50632 + return 0;
50633 + *p = *new;
50634 +
50635 + /* This function is only called from pivot_root(). Leave our
50636 + gr_chroot_dentry and is_chrooted flags as-is, so that a
50637 + pivoted root isn't treated as a chroot
50638 + */
50639 + //gr_set_chroot_entries(task, new);
50640 +
50641 + return 1;
50642 +}
50643 +
50644 void chroot_fs_refs(struct path *old_root, struct path *new_root)
50645 {
50646 struct task_struct *g, *p;
50647 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
50648 int hits = 0;
50649 spin_lock(&fs->lock);
50650 write_seqcount_begin(&fs->seq);
50651 - hits += replace_path(&fs->root, old_root, new_root);
50652 + hits += replace_root_path(p, &fs->root, old_root, new_root);
50653 hits += replace_path(&fs->pwd, old_root, new_root);
50654 write_seqcount_end(&fs->seq);
50655 while (hits--) {
50656 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
50657 task_lock(tsk);
50658 spin_lock(&fs->lock);
50659 tsk->fs = NULL;
50660 - kill = !--fs->users;
50661 + gr_clear_chroot_entries(tsk);
50662 + kill = !atomic_dec_return(&fs->users);
50663 spin_unlock(&fs->lock);
50664 task_unlock(tsk);
50665 if (kill)
50666 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
50667 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
50668 /* We don't need to lock fs - think why ;-) */
50669 if (fs) {
50670 - fs->users = 1;
50671 + atomic_set(&fs->users, 1);
50672 fs->in_exec = 0;
50673 spin_lock_init(&fs->lock);
50674 seqcount_init(&fs->seq);
50675 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
50676 spin_lock(&old->lock);
50677 fs->root = old->root;
50678 path_get(&fs->root);
50679 + /* instead of calling gr_set_chroot_entries here,
50680 + we call it from every caller of this function
50681 + */
50682 fs->pwd = old->pwd;
50683 path_get(&fs->pwd);
50684 spin_unlock(&old->lock);
50685 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
50686
50687 task_lock(current);
50688 spin_lock(&fs->lock);
50689 - kill = !--fs->users;
50690 + kill = !atomic_dec_return(&fs->users);
50691 current->fs = new_fs;
50692 + gr_set_chroot_entries(current, &new_fs->root);
50693 spin_unlock(&fs->lock);
50694 task_unlock(current);
50695
50696 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
50697
50698 int current_umask(void)
50699 {
50700 - return current->fs->umask;
50701 + return current->fs->umask | gr_acl_umask();
50702 }
50703 EXPORT_SYMBOL(current_umask);
50704
50705 /* to be mentioned only in INIT_TASK */
50706 struct fs_struct init_fs = {
50707 - .users = 1,
50708 + .users = ATOMIC_INIT(1),
50709 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
50710 .seq = SEQCNT_ZERO,
50711 .umask = 0022,
50712 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
50713 index 8dcb114..b1072e2 100644
50714 --- a/fs/fscache/cookie.c
50715 +++ b/fs/fscache/cookie.c
50716 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
50717 parent ? (char *) parent->def->name : "<no-parent>",
50718 def->name, netfs_data);
50719
50720 - fscache_stat(&fscache_n_acquires);
50721 + fscache_stat_unchecked(&fscache_n_acquires);
50722
50723 /* if there's no parent cookie, then we don't create one here either */
50724 if (!parent) {
50725 - fscache_stat(&fscache_n_acquires_null);
50726 + fscache_stat_unchecked(&fscache_n_acquires_null);
50727 _leave(" [no parent]");
50728 return NULL;
50729 }
50730 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
50731 /* allocate and initialise a cookie */
50732 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
50733 if (!cookie) {
50734 - fscache_stat(&fscache_n_acquires_oom);
50735 + fscache_stat_unchecked(&fscache_n_acquires_oom);
50736 _leave(" [ENOMEM]");
50737 return NULL;
50738 }
50739 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
50740
50741 switch (cookie->def->type) {
50742 case FSCACHE_COOKIE_TYPE_INDEX:
50743 - fscache_stat(&fscache_n_cookie_index);
50744 + fscache_stat_unchecked(&fscache_n_cookie_index);
50745 break;
50746 case FSCACHE_COOKIE_TYPE_DATAFILE:
50747 - fscache_stat(&fscache_n_cookie_data);
50748 + fscache_stat_unchecked(&fscache_n_cookie_data);
50749 break;
50750 default:
50751 - fscache_stat(&fscache_n_cookie_special);
50752 + fscache_stat_unchecked(&fscache_n_cookie_special);
50753 break;
50754 }
50755
50756 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
50757 if (fscache_acquire_non_index_cookie(cookie) < 0) {
50758 atomic_dec(&parent->n_children);
50759 __fscache_cookie_put(cookie);
50760 - fscache_stat(&fscache_n_acquires_nobufs);
50761 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
50762 _leave(" = NULL");
50763 return NULL;
50764 }
50765 }
50766
50767 - fscache_stat(&fscache_n_acquires_ok);
50768 + fscache_stat_unchecked(&fscache_n_acquires_ok);
50769 _leave(" = %p", cookie);
50770 return cookie;
50771 }
50772 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
50773 cache = fscache_select_cache_for_object(cookie->parent);
50774 if (!cache) {
50775 up_read(&fscache_addremove_sem);
50776 - fscache_stat(&fscache_n_acquires_no_cache);
50777 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
50778 _leave(" = -ENOMEDIUM [no cache]");
50779 return -ENOMEDIUM;
50780 }
50781 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
50782 object = cache->ops->alloc_object(cache, cookie);
50783 fscache_stat_d(&fscache_n_cop_alloc_object);
50784 if (IS_ERR(object)) {
50785 - fscache_stat(&fscache_n_object_no_alloc);
50786 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
50787 ret = PTR_ERR(object);
50788 goto error;
50789 }
50790
50791 - fscache_stat(&fscache_n_object_alloc);
50792 + fscache_stat_unchecked(&fscache_n_object_alloc);
50793
50794 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
50795
50796 @@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
50797
50798 _enter("{%s}", cookie->def->name);
50799
50800 - fscache_stat(&fscache_n_invalidates);
50801 + fscache_stat_unchecked(&fscache_n_invalidates);
50802
50803 /* Only permit invalidation of data files. Invalidating an index will
50804 * require the caller to release all its attachments to the tree rooted
50805 @@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
50806 struct fscache_object *object;
50807 struct hlist_node *_p;
50808
50809 - fscache_stat(&fscache_n_updates);
50810 + fscache_stat_unchecked(&fscache_n_updates);
50811
50812 if (!cookie) {
50813 - fscache_stat(&fscache_n_updates_null);
50814 + fscache_stat_unchecked(&fscache_n_updates_null);
50815 _leave(" [no cookie]");
50816 return;
50817 }
50818 @@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
50819 struct fscache_object *object;
50820 unsigned long event;
50821
50822 - fscache_stat(&fscache_n_relinquishes);
50823 + fscache_stat_unchecked(&fscache_n_relinquishes);
50824 if (retire)
50825 - fscache_stat(&fscache_n_relinquishes_retire);
50826 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
50827
50828 if (!cookie) {
50829 - fscache_stat(&fscache_n_relinquishes_null);
50830 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
50831 _leave(" [no cookie]");
50832 return;
50833 }
50834 @@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
50835
50836 /* wait for the cookie to finish being instantiated (or to fail) */
50837 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
50838 - fscache_stat(&fscache_n_relinquishes_waitcrt);
50839 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
50840 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
50841 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
50842 }
50843 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
50844 index ee38fef..0a326d4 100644
50845 --- a/fs/fscache/internal.h
50846 +++ b/fs/fscache/internal.h
50847 @@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
50848 * stats.c
50849 */
50850 #ifdef CONFIG_FSCACHE_STATS
50851 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
50852 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
50853 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
50854 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
50855
50856 -extern atomic_t fscache_n_op_pend;
50857 -extern atomic_t fscache_n_op_run;
50858 -extern atomic_t fscache_n_op_enqueue;
50859 -extern atomic_t fscache_n_op_deferred_release;
50860 -extern atomic_t fscache_n_op_release;
50861 -extern atomic_t fscache_n_op_gc;
50862 -extern atomic_t fscache_n_op_cancelled;
50863 -extern atomic_t fscache_n_op_rejected;
50864 +extern atomic_unchecked_t fscache_n_op_pend;
50865 +extern atomic_unchecked_t fscache_n_op_run;
50866 +extern atomic_unchecked_t fscache_n_op_enqueue;
50867 +extern atomic_unchecked_t fscache_n_op_deferred_release;
50868 +extern atomic_unchecked_t fscache_n_op_release;
50869 +extern atomic_unchecked_t fscache_n_op_gc;
50870 +extern atomic_unchecked_t fscache_n_op_cancelled;
50871 +extern atomic_unchecked_t fscache_n_op_rejected;
50872
50873 -extern atomic_t fscache_n_attr_changed;
50874 -extern atomic_t fscache_n_attr_changed_ok;
50875 -extern atomic_t fscache_n_attr_changed_nobufs;
50876 -extern atomic_t fscache_n_attr_changed_nomem;
50877 -extern atomic_t fscache_n_attr_changed_calls;
50878 +extern atomic_unchecked_t fscache_n_attr_changed;
50879 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
50880 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
50881 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
50882 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
50883
50884 -extern atomic_t fscache_n_allocs;
50885 -extern atomic_t fscache_n_allocs_ok;
50886 -extern atomic_t fscache_n_allocs_wait;
50887 -extern atomic_t fscache_n_allocs_nobufs;
50888 -extern atomic_t fscache_n_allocs_intr;
50889 -extern atomic_t fscache_n_allocs_object_dead;
50890 -extern atomic_t fscache_n_alloc_ops;
50891 -extern atomic_t fscache_n_alloc_op_waits;
50892 +extern atomic_unchecked_t fscache_n_allocs;
50893 +extern atomic_unchecked_t fscache_n_allocs_ok;
50894 +extern atomic_unchecked_t fscache_n_allocs_wait;
50895 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
50896 +extern atomic_unchecked_t fscache_n_allocs_intr;
50897 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
50898 +extern atomic_unchecked_t fscache_n_alloc_ops;
50899 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
50900
50901 -extern atomic_t fscache_n_retrievals;
50902 -extern atomic_t fscache_n_retrievals_ok;
50903 -extern atomic_t fscache_n_retrievals_wait;
50904 -extern atomic_t fscache_n_retrievals_nodata;
50905 -extern atomic_t fscache_n_retrievals_nobufs;
50906 -extern atomic_t fscache_n_retrievals_intr;
50907 -extern atomic_t fscache_n_retrievals_nomem;
50908 -extern atomic_t fscache_n_retrievals_object_dead;
50909 -extern atomic_t fscache_n_retrieval_ops;
50910 -extern atomic_t fscache_n_retrieval_op_waits;
50911 +extern atomic_unchecked_t fscache_n_retrievals;
50912 +extern atomic_unchecked_t fscache_n_retrievals_ok;
50913 +extern atomic_unchecked_t fscache_n_retrievals_wait;
50914 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
50915 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
50916 +extern atomic_unchecked_t fscache_n_retrievals_intr;
50917 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
50918 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
50919 +extern atomic_unchecked_t fscache_n_retrieval_ops;
50920 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
50921
50922 -extern atomic_t fscache_n_stores;
50923 -extern atomic_t fscache_n_stores_ok;
50924 -extern atomic_t fscache_n_stores_again;
50925 -extern atomic_t fscache_n_stores_nobufs;
50926 -extern atomic_t fscache_n_stores_oom;
50927 -extern atomic_t fscache_n_store_ops;
50928 -extern atomic_t fscache_n_store_calls;
50929 -extern atomic_t fscache_n_store_pages;
50930 -extern atomic_t fscache_n_store_radix_deletes;
50931 -extern atomic_t fscache_n_store_pages_over_limit;
50932 +extern atomic_unchecked_t fscache_n_stores;
50933 +extern atomic_unchecked_t fscache_n_stores_ok;
50934 +extern atomic_unchecked_t fscache_n_stores_again;
50935 +extern atomic_unchecked_t fscache_n_stores_nobufs;
50936 +extern atomic_unchecked_t fscache_n_stores_oom;
50937 +extern atomic_unchecked_t fscache_n_store_ops;
50938 +extern atomic_unchecked_t fscache_n_store_calls;
50939 +extern atomic_unchecked_t fscache_n_store_pages;
50940 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
50941 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
50942
50943 -extern atomic_t fscache_n_store_vmscan_not_storing;
50944 -extern atomic_t fscache_n_store_vmscan_gone;
50945 -extern atomic_t fscache_n_store_vmscan_busy;
50946 -extern atomic_t fscache_n_store_vmscan_cancelled;
50947 -extern atomic_t fscache_n_store_vmscan_wait;
50948 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
50949 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
50950 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
50951 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
50952 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
50953
50954 -extern atomic_t fscache_n_marks;
50955 -extern atomic_t fscache_n_uncaches;
50956 +extern atomic_unchecked_t fscache_n_marks;
50957 +extern atomic_unchecked_t fscache_n_uncaches;
50958
50959 -extern atomic_t fscache_n_acquires;
50960 -extern atomic_t fscache_n_acquires_null;
50961 -extern atomic_t fscache_n_acquires_no_cache;
50962 -extern atomic_t fscache_n_acquires_ok;
50963 -extern atomic_t fscache_n_acquires_nobufs;
50964 -extern atomic_t fscache_n_acquires_oom;
50965 +extern atomic_unchecked_t fscache_n_acquires;
50966 +extern atomic_unchecked_t fscache_n_acquires_null;
50967 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
50968 +extern atomic_unchecked_t fscache_n_acquires_ok;
50969 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
50970 +extern atomic_unchecked_t fscache_n_acquires_oom;
50971
50972 -extern atomic_t fscache_n_invalidates;
50973 -extern atomic_t fscache_n_invalidates_run;
50974 +extern atomic_unchecked_t fscache_n_invalidates;
50975 +extern atomic_unchecked_t fscache_n_invalidates_run;
50976
50977 -extern atomic_t fscache_n_updates;
50978 -extern atomic_t fscache_n_updates_null;
50979 -extern atomic_t fscache_n_updates_run;
50980 +extern atomic_unchecked_t fscache_n_updates;
50981 +extern atomic_unchecked_t fscache_n_updates_null;
50982 +extern atomic_unchecked_t fscache_n_updates_run;
50983
50984 -extern atomic_t fscache_n_relinquishes;
50985 -extern atomic_t fscache_n_relinquishes_null;
50986 -extern atomic_t fscache_n_relinquishes_waitcrt;
50987 -extern atomic_t fscache_n_relinquishes_retire;
50988 +extern atomic_unchecked_t fscache_n_relinquishes;
50989 +extern atomic_unchecked_t fscache_n_relinquishes_null;
50990 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
50991 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
50992
50993 -extern atomic_t fscache_n_cookie_index;
50994 -extern atomic_t fscache_n_cookie_data;
50995 -extern atomic_t fscache_n_cookie_special;
50996 +extern atomic_unchecked_t fscache_n_cookie_index;
50997 +extern atomic_unchecked_t fscache_n_cookie_data;
50998 +extern atomic_unchecked_t fscache_n_cookie_special;
50999
51000 -extern atomic_t fscache_n_object_alloc;
51001 -extern atomic_t fscache_n_object_no_alloc;
51002 -extern atomic_t fscache_n_object_lookups;
51003 -extern atomic_t fscache_n_object_lookups_negative;
51004 -extern atomic_t fscache_n_object_lookups_positive;
51005 -extern atomic_t fscache_n_object_lookups_timed_out;
51006 -extern atomic_t fscache_n_object_created;
51007 -extern atomic_t fscache_n_object_avail;
51008 -extern atomic_t fscache_n_object_dead;
51009 +extern atomic_unchecked_t fscache_n_object_alloc;
51010 +extern atomic_unchecked_t fscache_n_object_no_alloc;
51011 +extern atomic_unchecked_t fscache_n_object_lookups;
51012 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
51013 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
51014 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
51015 +extern atomic_unchecked_t fscache_n_object_created;
51016 +extern atomic_unchecked_t fscache_n_object_avail;
51017 +extern atomic_unchecked_t fscache_n_object_dead;
51018
51019 -extern atomic_t fscache_n_checkaux_none;
51020 -extern atomic_t fscache_n_checkaux_okay;
51021 -extern atomic_t fscache_n_checkaux_update;
51022 -extern atomic_t fscache_n_checkaux_obsolete;
51023 +extern atomic_unchecked_t fscache_n_checkaux_none;
51024 +extern atomic_unchecked_t fscache_n_checkaux_okay;
51025 +extern atomic_unchecked_t fscache_n_checkaux_update;
51026 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
51027
51028 extern atomic_t fscache_n_cop_alloc_object;
51029 extern atomic_t fscache_n_cop_lookup_object;
51030 @@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
51031 atomic_inc(stat);
51032 }
51033
51034 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
51035 +{
51036 + atomic_inc_unchecked(stat);
51037 +}
51038 +
51039 static inline void fscache_stat_d(atomic_t *stat)
51040 {
51041 atomic_dec(stat);
51042 @@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
51043
51044 #define __fscache_stat(stat) (NULL)
51045 #define fscache_stat(stat) do {} while (0)
51046 +#define fscache_stat_unchecked(stat) do {} while (0)
51047 #define fscache_stat_d(stat) do {} while (0)
51048 #endif
51049
51050 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
51051 index 50d41c1..10ee117 100644
51052 --- a/fs/fscache/object.c
51053 +++ b/fs/fscache/object.c
51054 @@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51055 /* Invalidate an object on disk */
51056 case FSCACHE_OBJECT_INVALIDATING:
51057 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
51058 - fscache_stat(&fscache_n_invalidates_run);
51059 + fscache_stat_unchecked(&fscache_n_invalidates_run);
51060 fscache_stat(&fscache_n_cop_invalidate_object);
51061 fscache_invalidate_object(object);
51062 fscache_stat_d(&fscache_n_cop_invalidate_object);
51063 @@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51064 /* update the object metadata on disk */
51065 case FSCACHE_OBJECT_UPDATING:
51066 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
51067 - fscache_stat(&fscache_n_updates_run);
51068 + fscache_stat_unchecked(&fscache_n_updates_run);
51069 fscache_stat(&fscache_n_cop_update_object);
51070 object->cache->ops->update_object(object);
51071 fscache_stat_d(&fscache_n_cop_update_object);
51072 @@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51073 spin_lock(&object->lock);
51074 object->state = FSCACHE_OBJECT_DEAD;
51075 spin_unlock(&object->lock);
51076 - fscache_stat(&fscache_n_object_dead);
51077 + fscache_stat_unchecked(&fscache_n_object_dead);
51078 goto terminal_transit;
51079
51080 /* handle the parent cache of this object being withdrawn from
51081 @@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51082 spin_lock(&object->lock);
51083 object->state = FSCACHE_OBJECT_DEAD;
51084 spin_unlock(&object->lock);
51085 - fscache_stat(&fscache_n_object_dead);
51086 + fscache_stat_unchecked(&fscache_n_object_dead);
51087 goto terminal_transit;
51088
51089 /* complain about the object being woken up once it is
51090 @@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51091 parent->cookie->def->name, cookie->def->name,
51092 object->cache->tag->name);
51093
51094 - fscache_stat(&fscache_n_object_lookups);
51095 + fscache_stat_unchecked(&fscache_n_object_lookups);
51096 fscache_stat(&fscache_n_cop_lookup_object);
51097 ret = object->cache->ops->lookup_object(object);
51098 fscache_stat_d(&fscache_n_cop_lookup_object);
51099 @@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51100 if (ret == -ETIMEDOUT) {
51101 /* probably stuck behind another object, so move this one to
51102 * the back of the queue */
51103 - fscache_stat(&fscache_n_object_lookups_timed_out);
51104 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
51105 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51106 }
51107
51108 @@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
51109
51110 spin_lock(&object->lock);
51111 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51112 - fscache_stat(&fscache_n_object_lookups_negative);
51113 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
51114
51115 /* transit here to allow write requests to begin stacking up
51116 * and read requests to begin returning ENODATA */
51117 @@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
51118 * result, in which case there may be data available */
51119 spin_lock(&object->lock);
51120 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51121 - fscache_stat(&fscache_n_object_lookups_positive);
51122 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
51123
51124 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
51125
51126 @@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
51127 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51128 } else {
51129 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
51130 - fscache_stat(&fscache_n_object_created);
51131 + fscache_stat_unchecked(&fscache_n_object_created);
51132
51133 object->state = FSCACHE_OBJECT_AVAILABLE;
51134 spin_unlock(&object->lock);
51135 @@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
51136 fscache_enqueue_dependents(object);
51137
51138 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
51139 - fscache_stat(&fscache_n_object_avail);
51140 + fscache_stat_unchecked(&fscache_n_object_avail);
51141
51142 _leave("");
51143 }
51144 @@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51145 enum fscache_checkaux result;
51146
51147 if (!object->cookie->def->check_aux) {
51148 - fscache_stat(&fscache_n_checkaux_none);
51149 + fscache_stat_unchecked(&fscache_n_checkaux_none);
51150 return FSCACHE_CHECKAUX_OKAY;
51151 }
51152
51153 @@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51154 switch (result) {
51155 /* entry okay as is */
51156 case FSCACHE_CHECKAUX_OKAY:
51157 - fscache_stat(&fscache_n_checkaux_okay);
51158 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
51159 break;
51160
51161 /* entry requires update */
51162 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
51163 - fscache_stat(&fscache_n_checkaux_update);
51164 + fscache_stat_unchecked(&fscache_n_checkaux_update);
51165 break;
51166
51167 /* entry requires deletion */
51168 case FSCACHE_CHECKAUX_OBSOLETE:
51169 - fscache_stat(&fscache_n_checkaux_obsolete);
51170 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
51171 break;
51172
51173 default:
51174 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
51175 index 762a9ec..2023284 100644
51176 --- a/fs/fscache/operation.c
51177 +++ b/fs/fscache/operation.c
51178 @@ -17,7 +17,7 @@
51179 #include <linux/slab.h>
51180 #include "internal.h"
51181
51182 -atomic_t fscache_op_debug_id;
51183 +atomic_unchecked_t fscache_op_debug_id;
51184 EXPORT_SYMBOL(fscache_op_debug_id);
51185
51186 /**
51187 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
51188 ASSERTCMP(atomic_read(&op->usage), >, 0);
51189 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
51190
51191 - fscache_stat(&fscache_n_op_enqueue);
51192 + fscache_stat_unchecked(&fscache_n_op_enqueue);
51193 switch (op->flags & FSCACHE_OP_TYPE) {
51194 case FSCACHE_OP_ASYNC:
51195 _debug("queue async");
51196 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
51197 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
51198 if (op->processor)
51199 fscache_enqueue_operation(op);
51200 - fscache_stat(&fscache_n_op_run);
51201 + fscache_stat_unchecked(&fscache_n_op_run);
51202 }
51203
51204 /*
51205 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51206 if (object->n_in_progress > 0) {
51207 atomic_inc(&op->usage);
51208 list_add_tail(&op->pend_link, &object->pending_ops);
51209 - fscache_stat(&fscache_n_op_pend);
51210 + fscache_stat_unchecked(&fscache_n_op_pend);
51211 } else if (!list_empty(&object->pending_ops)) {
51212 atomic_inc(&op->usage);
51213 list_add_tail(&op->pend_link, &object->pending_ops);
51214 - fscache_stat(&fscache_n_op_pend);
51215 + fscache_stat_unchecked(&fscache_n_op_pend);
51216 fscache_start_operations(object);
51217 } else {
51218 ASSERTCMP(object->n_in_progress, ==, 0);
51219 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51220 object->n_exclusive++; /* reads and writes must wait */
51221 atomic_inc(&op->usage);
51222 list_add_tail(&op->pend_link, &object->pending_ops);
51223 - fscache_stat(&fscache_n_op_pend);
51224 + fscache_stat_unchecked(&fscache_n_op_pend);
51225 ret = 0;
51226 } else {
51227 /* If we're in any other state, there must have been an I/O
51228 @@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
51229 if (object->n_exclusive > 0) {
51230 atomic_inc(&op->usage);
51231 list_add_tail(&op->pend_link, &object->pending_ops);
51232 - fscache_stat(&fscache_n_op_pend);
51233 + fscache_stat_unchecked(&fscache_n_op_pend);
51234 } else if (!list_empty(&object->pending_ops)) {
51235 atomic_inc(&op->usage);
51236 list_add_tail(&op->pend_link, &object->pending_ops);
51237 - fscache_stat(&fscache_n_op_pend);
51238 + fscache_stat_unchecked(&fscache_n_op_pend);
51239 fscache_start_operations(object);
51240 } else {
51241 ASSERTCMP(object->n_exclusive, ==, 0);
51242 @@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
51243 object->n_ops++;
51244 atomic_inc(&op->usage);
51245 list_add_tail(&op->pend_link, &object->pending_ops);
51246 - fscache_stat(&fscache_n_op_pend);
51247 + fscache_stat_unchecked(&fscache_n_op_pend);
51248 ret = 0;
51249 } else if (object->state == FSCACHE_OBJECT_DYING ||
51250 object->state == FSCACHE_OBJECT_LC_DYING ||
51251 object->state == FSCACHE_OBJECT_WITHDRAWING) {
51252 - fscache_stat(&fscache_n_op_rejected);
51253 + fscache_stat_unchecked(&fscache_n_op_rejected);
51254 op->state = FSCACHE_OP_ST_CANCELLED;
51255 ret = -ENOBUFS;
51256 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
51257 @@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
51258 ret = -EBUSY;
51259 if (op->state == FSCACHE_OP_ST_PENDING) {
51260 ASSERT(!list_empty(&op->pend_link));
51261 - fscache_stat(&fscache_n_op_cancelled);
51262 + fscache_stat_unchecked(&fscache_n_op_cancelled);
51263 list_del_init(&op->pend_link);
51264 if (do_cancel)
51265 do_cancel(op);
51266 @@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
51267 while (!list_empty(&object->pending_ops)) {
51268 op = list_entry(object->pending_ops.next,
51269 struct fscache_operation, pend_link);
51270 - fscache_stat(&fscache_n_op_cancelled);
51271 + fscache_stat_unchecked(&fscache_n_op_cancelled);
51272 list_del_init(&op->pend_link);
51273
51274 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
51275 @@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
51276 op->state, ==, FSCACHE_OP_ST_CANCELLED);
51277 op->state = FSCACHE_OP_ST_DEAD;
51278
51279 - fscache_stat(&fscache_n_op_release);
51280 + fscache_stat_unchecked(&fscache_n_op_release);
51281
51282 if (op->release) {
51283 op->release(op);
51284 @@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
51285 * lock, and defer it otherwise */
51286 if (!spin_trylock(&object->lock)) {
51287 _debug("defer put");
51288 - fscache_stat(&fscache_n_op_deferred_release);
51289 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
51290
51291 cache = object->cache;
51292 spin_lock(&cache->op_gc_list_lock);
51293 @@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
51294
51295 _debug("GC DEFERRED REL OBJ%x OP%x",
51296 object->debug_id, op->debug_id);
51297 - fscache_stat(&fscache_n_op_gc);
51298 + fscache_stat_unchecked(&fscache_n_op_gc);
51299
51300 ASSERTCMP(atomic_read(&op->usage), ==, 0);
51301 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
51302 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
51303 index ff000e5..c44ec6d 100644
51304 --- a/fs/fscache/page.c
51305 +++ b/fs/fscache/page.c
51306 @@ -61,7 +61,7 @@ try_again:
51307 val = radix_tree_lookup(&cookie->stores, page->index);
51308 if (!val) {
51309 rcu_read_unlock();
51310 - fscache_stat(&fscache_n_store_vmscan_not_storing);
51311 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
51312 __fscache_uncache_page(cookie, page);
51313 return true;
51314 }
51315 @@ -91,11 +91,11 @@ try_again:
51316 spin_unlock(&cookie->stores_lock);
51317
51318 if (xpage) {
51319 - fscache_stat(&fscache_n_store_vmscan_cancelled);
51320 - fscache_stat(&fscache_n_store_radix_deletes);
51321 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
51322 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51323 ASSERTCMP(xpage, ==, page);
51324 } else {
51325 - fscache_stat(&fscache_n_store_vmscan_gone);
51326 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
51327 }
51328
51329 wake_up_bit(&cookie->flags, 0);
51330 @@ -110,11 +110,11 @@ page_busy:
51331 * sleeping on memory allocation, so we may need to impose a timeout
51332 * too. */
51333 if (!(gfp & __GFP_WAIT)) {
51334 - fscache_stat(&fscache_n_store_vmscan_busy);
51335 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
51336 return false;
51337 }
51338
51339 - fscache_stat(&fscache_n_store_vmscan_wait);
51340 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
51341 __fscache_wait_on_page_write(cookie, page);
51342 gfp &= ~__GFP_WAIT;
51343 goto try_again;
51344 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
51345 FSCACHE_COOKIE_STORING_TAG);
51346 if (!radix_tree_tag_get(&cookie->stores, page->index,
51347 FSCACHE_COOKIE_PENDING_TAG)) {
51348 - fscache_stat(&fscache_n_store_radix_deletes);
51349 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51350 xpage = radix_tree_delete(&cookie->stores, page->index);
51351 }
51352 spin_unlock(&cookie->stores_lock);
51353 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
51354
51355 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
51356
51357 - fscache_stat(&fscache_n_attr_changed_calls);
51358 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
51359
51360 if (fscache_object_is_active(object)) {
51361 fscache_stat(&fscache_n_cop_attr_changed);
51362 @@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51363
51364 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51365
51366 - fscache_stat(&fscache_n_attr_changed);
51367 + fscache_stat_unchecked(&fscache_n_attr_changed);
51368
51369 op = kzalloc(sizeof(*op), GFP_KERNEL);
51370 if (!op) {
51371 - fscache_stat(&fscache_n_attr_changed_nomem);
51372 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
51373 _leave(" = -ENOMEM");
51374 return -ENOMEM;
51375 }
51376 @@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51377 if (fscache_submit_exclusive_op(object, op) < 0)
51378 goto nobufs;
51379 spin_unlock(&cookie->lock);
51380 - fscache_stat(&fscache_n_attr_changed_ok);
51381 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
51382 fscache_put_operation(op);
51383 _leave(" = 0");
51384 return 0;
51385 @@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51386 nobufs:
51387 spin_unlock(&cookie->lock);
51388 kfree(op);
51389 - fscache_stat(&fscache_n_attr_changed_nobufs);
51390 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
51391 _leave(" = %d", -ENOBUFS);
51392 return -ENOBUFS;
51393 }
51394 @@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
51395 /* allocate a retrieval operation and attempt to submit it */
51396 op = kzalloc(sizeof(*op), GFP_NOIO);
51397 if (!op) {
51398 - fscache_stat(&fscache_n_retrievals_nomem);
51399 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51400 return NULL;
51401 }
51402
51403 @@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
51404 return 0;
51405 }
51406
51407 - fscache_stat(&fscache_n_retrievals_wait);
51408 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
51409
51410 jif = jiffies;
51411 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
51412 fscache_wait_bit_interruptible,
51413 TASK_INTERRUPTIBLE) != 0) {
51414 - fscache_stat(&fscache_n_retrievals_intr);
51415 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
51416 _leave(" = -ERESTARTSYS");
51417 return -ERESTARTSYS;
51418 }
51419 @@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
51420 */
51421 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51422 struct fscache_retrieval *op,
51423 - atomic_t *stat_op_waits,
51424 - atomic_t *stat_object_dead)
51425 + atomic_unchecked_t *stat_op_waits,
51426 + atomic_unchecked_t *stat_object_dead)
51427 {
51428 int ret;
51429
51430 @@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51431 goto check_if_dead;
51432
51433 _debug(">>> WT");
51434 - fscache_stat(stat_op_waits);
51435 + fscache_stat_unchecked(stat_op_waits);
51436 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
51437 fscache_wait_bit_interruptible,
51438 TASK_INTERRUPTIBLE) != 0) {
51439 @@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51440
51441 check_if_dead:
51442 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
51443 - fscache_stat(stat_object_dead);
51444 + fscache_stat_unchecked(stat_object_dead);
51445 _leave(" = -ENOBUFS [cancelled]");
51446 return -ENOBUFS;
51447 }
51448 if (unlikely(fscache_object_is_dead(object))) {
51449 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
51450 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
51451 - fscache_stat(stat_object_dead);
51452 + fscache_stat_unchecked(stat_object_dead);
51453 return -ENOBUFS;
51454 }
51455 return 0;
51456 @@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51457
51458 _enter("%p,%p,,,", cookie, page);
51459
51460 - fscache_stat(&fscache_n_retrievals);
51461 + fscache_stat_unchecked(&fscache_n_retrievals);
51462
51463 if (hlist_empty(&cookie->backing_objects))
51464 goto nobufs;
51465 @@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51466 goto nobufs_unlock_dec;
51467 spin_unlock(&cookie->lock);
51468
51469 - fscache_stat(&fscache_n_retrieval_ops);
51470 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
51471
51472 /* pin the netfs read context in case we need to do the actual netfs
51473 * read because we've encountered a cache read failure */
51474 @@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51475
51476 error:
51477 if (ret == -ENOMEM)
51478 - fscache_stat(&fscache_n_retrievals_nomem);
51479 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51480 else if (ret == -ERESTARTSYS)
51481 - fscache_stat(&fscache_n_retrievals_intr);
51482 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
51483 else if (ret == -ENODATA)
51484 - fscache_stat(&fscache_n_retrievals_nodata);
51485 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51486 else if (ret < 0)
51487 - fscache_stat(&fscache_n_retrievals_nobufs);
51488 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51489 else
51490 - fscache_stat(&fscache_n_retrievals_ok);
51491 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
51492
51493 fscache_put_retrieval(op);
51494 _leave(" = %d", ret);
51495 @@ -467,7 +467,7 @@ nobufs_unlock:
51496 spin_unlock(&cookie->lock);
51497 kfree(op);
51498 nobufs:
51499 - fscache_stat(&fscache_n_retrievals_nobufs);
51500 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51501 _leave(" = -ENOBUFS");
51502 return -ENOBUFS;
51503 }
51504 @@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51505
51506 _enter("%p,,%d,,,", cookie, *nr_pages);
51507
51508 - fscache_stat(&fscache_n_retrievals);
51509 + fscache_stat_unchecked(&fscache_n_retrievals);
51510
51511 if (hlist_empty(&cookie->backing_objects))
51512 goto nobufs;
51513 @@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51514 goto nobufs_unlock_dec;
51515 spin_unlock(&cookie->lock);
51516
51517 - fscache_stat(&fscache_n_retrieval_ops);
51518 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
51519
51520 /* pin the netfs read context in case we need to do the actual netfs
51521 * read because we've encountered a cache read failure */
51522 @@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51523
51524 error:
51525 if (ret == -ENOMEM)
51526 - fscache_stat(&fscache_n_retrievals_nomem);
51527 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51528 else if (ret == -ERESTARTSYS)
51529 - fscache_stat(&fscache_n_retrievals_intr);
51530 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
51531 else if (ret == -ENODATA)
51532 - fscache_stat(&fscache_n_retrievals_nodata);
51533 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51534 else if (ret < 0)
51535 - fscache_stat(&fscache_n_retrievals_nobufs);
51536 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51537 else
51538 - fscache_stat(&fscache_n_retrievals_ok);
51539 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
51540
51541 fscache_put_retrieval(op);
51542 _leave(" = %d", ret);
51543 @@ -591,7 +591,7 @@ nobufs_unlock:
51544 spin_unlock(&cookie->lock);
51545 kfree(op);
51546 nobufs:
51547 - fscache_stat(&fscache_n_retrievals_nobufs);
51548 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51549 _leave(" = -ENOBUFS");
51550 return -ENOBUFS;
51551 }
51552 @@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51553
51554 _enter("%p,%p,,,", cookie, page);
51555
51556 - fscache_stat(&fscache_n_allocs);
51557 + fscache_stat_unchecked(&fscache_n_allocs);
51558
51559 if (hlist_empty(&cookie->backing_objects))
51560 goto nobufs;
51561 @@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51562 goto nobufs_unlock;
51563 spin_unlock(&cookie->lock);
51564
51565 - fscache_stat(&fscache_n_alloc_ops);
51566 + fscache_stat_unchecked(&fscache_n_alloc_ops);
51567
51568 ret = fscache_wait_for_retrieval_activation(
51569 object, op,
51570 @@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51571
51572 error:
51573 if (ret == -ERESTARTSYS)
51574 - fscache_stat(&fscache_n_allocs_intr);
51575 + fscache_stat_unchecked(&fscache_n_allocs_intr);
51576 else if (ret < 0)
51577 - fscache_stat(&fscache_n_allocs_nobufs);
51578 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
51579 else
51580 - fscache_stat(&fscache_n_allocs_ok);
51581 + fscache_stat_unchecked(&fscache_n_allocs_ok);
51582
51583 fscache_put_retrieval(op);
51584 _leave(" = %d", ret);
51585 @@ -677,7 +677,7 @@ nobufs_unlock:
51586 spin_unlock(&cookie->lock);
51587 kfree(op);
51588 nobufs:
51589 - fscache_stat(&fscache_n_allocs_nobufs);
51590 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
51591 _leave(" = -ENOBUFS");
51592 return -ENOBUFS;
51593 }
51594 @@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51595
51596 spin_lock(&cookie->stores_lock);
51597
51598 - fscache_stat(&fscache_n_store_calls);
51599 + fscache_stat_unchecked(&fscache_n_store_calls);
51600
51601 /* find a page to store */
51602 page = NULL;
51603 @@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51604 page = results[0];
51605 _debug("gang %d [%lx]", n, page->index);
51606 if (page->index > op->store_limit) {
51607 - fscache_stat(&fscache_n_store_pages_over_limit);
51608 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
51609 goto superseded;
51610 }
51611
51612 @@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51613 spin_unlock(&cookie->stores_lock);
51614 spin_unlock(&object->lock);
51615
51616 - fscache_stat(&fscache_n_store_pages);
51617 + fscache_stat_unchecked(&fscache_n_store_pages);
51618 fscache_stat(&fscache_n_cop_write_page);
51619 ret = object->cache->ops->write_page(op, page);
51620 fscache_stat_d(&fscache_n_cop_write_page);
51621 @@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51622 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51623 ASSERT(PageFsCache(page));
51624
51625 - fscache_stat(&fscache_n_stores);
51626 + fscache_stat_unchecked(&fscache_n_stores);
51627
51628 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
51629 _leave(" = -ENOBUFS [invalidating]");
51630 @@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51631 spin_unlock(&cookie->stores_lock);
51632 spin_unlock(&object->lock);
51633
51634 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
51635 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
51636 op->store_limit = object->store_limit;
51637
51638 if (fscache_submit_op(object, &op->op) < 0)
51639 @@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51640
51641 spin_unlock(&cookie->lock);
51642 radix_tree_preload_end();
51643 - fscache_stat(&fscache_n_store_ops);
51644 - fscache_stat(&fscache_n_stores_ok);
51645 + fscache_stat_unchecked(&fscache_n_store_ops);
51646 + fscache_stat_unchecked(&fscache_n_stores_ok);
51647
51648 /* the work queue now carries its own ref on the object */
51649 fscache_put_operation(&op->op);
51650 @@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51651 return 0;
51652
51653 already_queued:
51654 - fscache_stat(&fscache_n_stores_again);
51655 + fscache_stat_unchecked(&fscache_n_stores_again);
51656 already_pending:
51657 spin_unlock(&cookie->stores_lock);
51658 spin_unlock(&object->lock);
51659 spin_unlock(&cookie->lock);
51660 radix_tree_preload_end();
51661 kfree(op);
51662 - fscache_stat(&fscache_n_stores_ok);
51663 + fscache_stat_unchecked(&fscache_n_stores_ok);
51664 _leave(" = 0");
51665 return 0;
51666
51667 @@ -959,14 +959,14 @@ nobufs:
51668 spin_unlock(&cookie->lock);
51669 radix_tree_preload_end();
51670 kfree(op);
51671 - fscache_stat(&fscache_n_stores_nobufs);
51672 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
51673 _leave(" = -ENOBUFS");
51674 return -ENOBUFS;
51675
51676 nomem_free:
51677 kfree(op);
51678 nomem:
51679 - fscache_stat(&fscache_n_stores_oom);
51680 + fscache_stat_unchecked(&fscache_n_stores_oom);
51681 _leave(" = -ENOMEM");
51682 return -ENOMEM;
51683 }
51684 @@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
51685 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51686 ASSERTCMP(page, !=, NULL);
51687
51688 - fscache_stat(&fscache_n_uncaches);
51689 + fscache_stat_unchecked(&fscache_n_uncaches);
51690
51691 /* cache withdrawal may beat us to it */
51692 if (!PageFsCache(page))
51693 @@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
51694 struct fscache_cookie *cookie = op->op.object->cookie;
51695
51696 #ifdef CONFIG_FSCACHE_STATS
51697 - atomic_inc(&fscache_n_marks);
51698 + atomic_inc_unchecked(&fscache_n_marks);
51699 #endif
51700
51701 _debug("- mark %p{%lx}", page, page->index);
51702 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
51703 index 8179e8b..5072cc7 100644
51704 --- a/fs/fscache/stats.c
51705 +++ b/fs/fscache/stats.c
51706 @@ -18,99 +18,99 @@
51707 /*
51708 * operation counters
51709 */
51710 -atomic_t fscache_n_op_pend;
51711 -atomic_t fscache_n_op_run;
51712 -atomic_t fscache_n_op_enqueue;
51713 -atomic_t fscache_n_op_requeue;
51714 -atomic_t fscache_n_op_deferred_release;
51715 -atomic_t fscache_n_op_release;
51716 -atomic_t fscache_n_op_gc;
51717 -atomic_t fscache_n_op_cancelled;
51718 -atomic_t fscache_n_op_rejected;
51719 +atomic_unchecked_t fscache_n_op_pend;
51720 +atomic_unchecked_t fscache_n_op_run;
51721 +atomic_unchecked_t fscache_n_op_enqueue;
51722 +atomic_unchecked_t fscache_n_op_requeue;
51723 +atomic_unchecked_t fscache_n_op_deferred_release;
51724 +atomic_unchecked_t fscache_n_op_release;
51725 +atomic_unchecked_t fscache_n_op_gc;
51726 +atomic_unchecked_t fscache_n_op_cancelled;
51727 +atomic_unchecked_t fscache_n_op_rejected;
51728
51729 -atomic_t fscache_n_attr_changed;
51730 -atomic_t fscache_n_attr_changed_ok;
51731 -atomic_t fscache_n_attr_changed_nobufs;
51732 -atomic_t fscache_n_attr_changed_nomem;
51733 -atomic_t fscache_n_attr_changed_calls;
51734 +atomic_unchecked_t fscache_n_attr_changed;
51735 +atomic_unchecked_t fscache_n_attr_changed_ok;
51736 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
51737 +atomic_unchecked_t fscache_n_attr_changed_nomem;
51738 +atomic_unchecked_t fscache_n_attr_changed_calls;
51739
51740 -atomic_t fscache_n_allocs;
51741 -atomic_t fscache_n_allocs_ok;
51742 -atomic_t fscache_n_allocs_wait;
51743 -atomic_t fscache_n_allocs_nobufs;
51744 -atomic_t fscache_n_allocs_intr;
51745 -atomic_t fscache_n_allocs_object_dead;
51746 -atomic_t fscache_n_alloc_ops;
51747 -atomic_t fscache_n_alloc_op_waits;
51748 +atomic_unchecked_t fscache_n_allocs;
51749 +atomic_unchecked_t fscache_n_allocs_ok;
51750 +atomic_unchecked_t fscache_n_allocs_wait;
51751 +atomic_unchecked_t fscache_n_allocs_nobufs;
51752 +atomic_unchecked_t fscache_n_allocs_intr;
51753 +atomic_unchecked_t fscache_n_allocs_object_dead;
51754 +atomic_unchecked_t fscache_n_alloc_ops;
51755 +atomic_unchecked_t fscache_n_alloc_op_waits;
51756
51757 -atomic_t fscache_n_retrievals;
51758 -atomic_t fscache_n_retrievals_ok;
51759 -atomic_t fscache_n_retrievals_wait;
51760 -atomic_t fscache_n_retrievals_nodata;
51761 -atomic_t fscache_n_retrievals_nobufs;
51762 -atomic_t fscache_n_retrievals_intr;
51763 -atomic_t fscache_n_retrievals_nomem;
51764 -atomic_t fscache_n_retrievals_object_dead;
51765 -atomic_t fscache_n_retrieval_ops;
51766 -atomic_t fscache_n_retrieval_op_waits;
51767 +atomic_unchecked_t fscache_n_retrievals;
51768 +atomic_unchecked_t fscache_n_retrievals_ok;
51769 +atomic_unchecked_t fscache_n_retrievals_wait;
51770 +atomic_unchecked_t fscache_n_retrievals_nodata;
51771 +atomic_unchecked_t fscache_n_retrievals_nobufs;
51772 +atomic_unchecked_t fscache_n_retrievals_intr;
51773 +atomic_unchecked_t fscache_n_retrievals_nomem;
51774 +atomic_unchecked_t fscache_n_retrievals_object_dead;
51775 +atomic_unchecked_t fscache_n_retrieval_ops;
51776 +atomic_unchecked_t fscache_n_retrieval_op_waits;
51777
51778 -atomic_t fscache_n_stores;
51779 -atomic_t fscache_n_stores_ok;
51780 -atomic_t fscache_n_stores_again;
51781 -atomic_t fscache_n_stores_nobufs;
51782 -atomic_t fscache_n_stores_oom;
51783 -atomic_t fscache_n_store_ops;
51784 -atomic_t fscache_n_store_calls;
51785 -atomic_t fscache_n_store_pages;
51786 -atomic_t fscache_n_store_radix_deletes;
51787 -atomic_t fscache_n_store_pages_over_limit;
51788 +atomic_unchecked_t fscache_n_stores;
51789 +atomic_unchecked_t fscache_n_stores_ok;
51790 +atomic_unchecked_t fscache_n_stores_again;
51791 +atomic_unchecked_t fscache_n_stores_nobufs;
51792 +atomic_unchecked_t fscache_n_stores_oom;
51793 +atomic_unchecked_t fscache_n_store_ops;
51794 +atomic_unchecked_t fscache_n_store_calls;
51795 +atomic_unchecked_t fscache_n_store_pages;
51796 +atomic_unchecked_t fscache_n_store_radix_deletes;
51797 +atomic_unchecked_t fscache_n_store_pages_over_limit;
51798
51799 -atomic_t fscache_n_store_vmscan_not_storing;
51800 -atomic_t fscache_n_store_vmscan_gone;
51801 -atomic_t fscache_n_store_vmscan_busy;
51802 -atomic_t fscache_n_store_vmscan_cancelled;
51803 -atomic_t fscache_n_store_vmscan_wait;
51804 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
51805 +atomic_unchecked_t fscache_n_store_vmscan_gone;
51806 +atomic_unchecked_t fscache_n_store_vmscan_busy;
51807 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51808 +atomic_unchecked_t fscache_n_store_vmscan_wait;
51809
51810 -atomic_t fscache_n_marks;
51811 -atomic_t fscache_n_uncaches;
51812 +atomic_unchecked_t fscache_n_marks;
51813 +atomic_unchecked_t fscache_n_uncaches;
51814
51815 -atomic_t fscache_n_acquires;
51816 -atomic_t fscache_n_acquires_null;
51817 -atomic_t fscache_n_acquires_no_cache;
51818 -atomic_t fscache_n_acquires_ok;
51819 -atomic_t fscache_n_acquires_nobufs;
51820 -atomic_t fscache_n_acquires_oom;
51821 +atomic_unchecked_t fscache_n_acquires;
51822 +atomic_unchecked_t fscache_n_acquires_null;
51823 +atomic_unchecked_t fscache_n_acquires_no_cache;
51824 +atomic_unchecked_t fscache_n_acquires_ok;
51825 +atomic_unchecked_t fscache_n_acquires_nobufs;
51826 +atomic_unchecked_t fscache_n_acquires_oom;
51827
51828 -atomic_t fscache_n_invalidates;
51829 -atomic_t fscache_n_invalidates_run;
51830 +atomic_unchecked_t fscache_n_invalidates;
51831 +atomic_unchecked_t fscache_n_invalidates_run;
51832
51833 -atomic_t fscache_n_updates;
51834 -atomic_t fscache_n_updates_null;
51835 -atomic_t fscache_n_updates_run;
51836 +atomic_unchecked_t fscache_n_updates;
51837 +atomic_unchecked_t fscache_n_updates_null;
51838 +atomic_unchecked_t fscache_n_updates_run;
51839
51840 -atomic_t fscache_n_relinquishes;
51841 -atomic_t fscache_n_relinquishes_null;
51842 -atomic_t fscache_n_relinquishes_waitcrt;
51843 -atomic_t fscache_n_relinquishes_retire;
51844 +atomic_unchecked_t fscache_n_relinquishes;
51845 +atomic_unchecked_t fscache_n_relinquishes_null;
51846 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51847 +atomic_unchecked_t fscache_n_relinquishes_retire;
51848
51849 -atomic_t fscache_n_cookie_index;
51850 -atomic_t fscache_n_cookie_data;
51851 -atomic_t fscache_n_cookie_special;
51852 +atomic_unchecked_t fscache_n_cookie_index;
51853 +atomic_unchecked_t fscache_n_cookie_data;
51854 +atomic_unchecked_t fscache_n_cookie_special;
51855
51856 -atomic_t fscache_n_object_alloc;
51857 -atomic_t fscache_n_object_no_alloc;
51858 -atomic_t fscache_n_object_lookups;
51859 -atomic_t fscache_n_object_lookups_negative;
51860 -atomic_t fscache_n_object_lookups_positive;
51861 -atomic_t fscache_n_object_lookups_timed_out;
51862 -atomic_t fscache_n_object_created;
51863 -atomic_t fscache_n_object_avail;
51864 -atomic_t fscache_n_object_dead;
51865 +atomic_unchecked_t fscache_n_object_alloc;
51866 +atomic_unchecked_t fscache_n_object_no_alloc;
51867 +atomic_unchecked_t fscache_n_object_lookups;
51868 +atomic_unchecked_t fscache_n_object_lookups_negative;
51869 +atomic_unchecked_t fscache_n_object_lookups_positive;
51870 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
51871 +atomic_unchecked_t fscache_n_object_created;
51872 +atomic_unchecked_t fscache_n_object_avail;
51873 +atomic_unchecked_t fscache_n_object_dead;
51874
51875 -atomic_t fscache_n_checkaux_none;
51876 -atomic_t fscache_n_checkaux_okay;
51877 -atomic_t fscache_n_checkaux_update;
51878 -atomic_t fscache_n_checkaux_obsolete;
51879 +atomic_unchecked_t fscache_n_checkaux_none;
51880 +atomic_unchecked_t fscache_n_checkaux_okay;
51881 +atomic_unchecked_t fscache_n_checkaux_update;
51882 +atomic_unchecked_t fscache_n_checkaux_obsolete;
51883
51884 atomic_t fscache_n_cop_alloc_object;
51885 atomic_t fscache_n_cop_lookup_object;
51886 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
51887 seq_puts(m, "FS-Cache statistics\n");
51888
51889 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
51890 - atomic_read(&fscache_n_cookie_index),
51891 - atomic_read(&fscache_n_cookie_data),
51892 - atomic_read(&fscache_n_cookie_special));
51893 + atomic_read_unchecked(&fscache_n_cookie_index),
51894 + atomic_read_unchecked(&fscache_n_cookie_data),
51895 + atomic_read_unchecked(&fscache_n_cookie_special));
51896
51897 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
51898 - atomic_read(&fscache_n_object_alloc),
51899 - atomic_read(&fscache_n_object_no_alloc),
51900 - atomic_read(&fscache_n_object_avail),
51901 - atomic_read(&fscache_n_object_dead));
51902 + atomic_read_unchecked(&fscache_n_object_alloc),
51903 + atomic_read_unchecked(&fscache_n_object_no_alloc),
51904 + atomic_read_unchecked(&fscache_n_object_avail),
51905 + atomic_read_unchecked(&fscache_n_object_dead));
51906 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
51907 - atomic_read(&fscache_n_checkaux_none),
51908 - atomic_read(&fscache_n_checkaux_okay),
51909 - atomic_read(&fscache_n_checkaux_update),
51910 - atomic_read(&fscache_n_checkaux_obsolete));
51911 + atomic_read_unchecked(&fscache_n_checkaux_none),
51912 + atomic_read_unchecked(&fscache_n_checkaux_okay),
51913 + atomic_read_unchecked(&fscache_n_checkaux_update),
51914 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
51915
51916 seq_printf(m, "Pages : mrk=%u unc=%u\n",
51917 - atomic_read(&fscache_n_marks),
51918 - atomic_read(&fscache_n_uncaches));
51919 + atomic_read_unchecked(&fscache_n_marks),
51920 + atomic_read_unchecked(&fscache_n_uncaches));
51921
51922 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
51923 " oom=%u\n",
51924 - atomic_read(&fscache_n_acquires),
51925 - atomic_read(&fscache_n_acquires_null),
51926 - atomic_read(&fscache_n_acquires_no_cache),
51927 - atomic_read(&fscache_n_acquires_ok),
51928 - atomic_read(&fscache_n_acquires_nobufs),
51929 - atomic_read(&fscache_n_acquires_oom));
51930 + atomic_read_unchecked(&fscache_n_acquires),
51931 + atomic_read_unchecked(&fscache_n_acquires_null),
51932 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
51933 + atomic_read_unchecked(&fscache_n_acquires_ok),
51934 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
51935 + atomic_read_unchecked(&fscache_n_acquires_oom));
51936
51937 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
51938 - atomic_read(&fscache_n_object_lookups),
51939 - atomic_read(&fscache_n_object_lookups_negative),
51940 - atomic_read(&fscache_n_object_lookups_positive),
51941 - atomic_read(&fscache_n_object_created),
51942 - atomic_read(&fscache_n_object_lookups_timed_out));
51943 + atomic_read_unchecked(&fscache_n_object_lookups),
51944 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
51945 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
51946 + atomic_read_unchecked(&fscache_n_object_created),
51947 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
51948
51949 seq_printf(m, "Invals : n=%u run=%u\n",
51950 - atomic_read(&fscache_n_invalidates),
51951 - atomic_read(&fscache_n_invalidates_run));
51952 + atomic_read_unchecked(&fscache_n_invalidates),
51953 + atomic_read_unchecked(&fscache_n_invalidates_run));
51954
51955 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
51956 - atomic_read(&fscache_n_updates),
51957 - atomic_read(&fscache_n_updates_null),
51958 - atomic_read(&fscache_n_updates_run));
51959 + atomic_read_unchecked(&fscache_n_updates),
51960 + atomic_read_unchecked(&fscache_n_updates_null),
51961 + atomic_read_unchecked(&fscache_n_updates_run));
51962
51963 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
51964 - atomic_read(&fscache_n_relinquishes),
51965 - atomic_read(&fscache_n_relinquishes_null),
51966 - atomic_read(&fscache_n_relinquishes_waitcrt),
51967 - atomic_read(&fscache_n_relinquishes_retire));
51968 + atomic_read_unchecked(&fscache_n_relinquishes),
51969 + atomic_read_unchecked(&fscache_n_relinquishes_null),
51970 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
51971 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
51972
51973 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
51974 - atomic_read(&fscache_n_attr_changed),
51975 - atomic_read(&fscache_n_attr_changed_ok),
51976 - atomic_read(&fscache_n_attr_changed_nobufs),
51977 - atomic_read(&fscache_n_attr_changed_nomem),
51978 - atomic_read(&fscache_n_attr_changed_calls));
51979 + atomic_read_unchecked(&fscache_n_attr_changed),
51980 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
51981 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
51982 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
51983 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
51984
51985 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
51986 - atomic_read(&fscache_n_allocs),
51987 - atomic_read(&fscache_n_allocs_ok),
51988 - atomic_read(&fscache_n_allocs_wait),
51989 - atomic_read(&fscache_n_allocs_nobufs),
51990 - atomic_read(&fscache_n_allocs_intr));
51991 + atomic_read_unchecked(&fscache_n_allocs),
51992 + atomic_read_unchecked(&fscache_n_allocs_ok),
51993 + atomic_read_unchecked(&fscache_n_allocs_wait),
51994 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
51995 + atomic_read_unchecked(&fscache_n_allocs_intr));
51996 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
51997 - atomic_read(&fscache_n_alloc_ops),
51998 - atomic_read(&fscache_n_alloc_op_waits),
51999 - atomic_read(&fscache_n_allocs_object_dead));
52000 + atomic_read_unchecked(&fscache_n_alloc_ops),
52001 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
52002 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
52003
52004 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
52005 " int=%u oom=%u\n",
52006 - atomic_read(&fscache_n_retrievals),
52007 - atomic_read(&fscache_n_retrievals_ok),
52008 - atomic_read(&fscache_n_retrievals_wait),
52009 - atomic_read(&fscache_n_retrievals_nodata),
52010 - atomic_read(&fscache_n_retrievals_nobufs),
52011 - atomic_read(&fscache_n_retrievals_intr),
52012 - atomic_read(&fscache_n_retrievals_nomem));
52013 + atomic_read_unchecked(&fscache_n_retrievals),
52014 + atomic_read_unchecked(&fscache_n_retrievals_ok),
52015 + atomic_read_unchecked(&fscache_n_retrievals_wait),
52016 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
52017 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
52018 + atomic_read_unchecked(&fscache_n_retrievals_intr),
52019 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
52020 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
52021 - atomic_read(&fscache_n_retrieval_ops),
52022 - atomic_read(&fscache_n_retrieval_op_waits),
52023 - atomic_read(&fscache_n_retrievals_object_dead));
52024 + atomic_read_unchecked(&fscache_n_retrieval_ops),
52025 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
52026 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
52027
52028 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
52029 - atomic_read(&fscache_n_stores),
52030 - atomic_read(&fscache_n_stores_ok),
52031 - atomic_read(&fscache_n_stores_again),
52032 - atomic_read(&fscache_n_stores_nobufs),
52033 - atomic_read(&fscache_n_stores_oom));
52034 + atomic_read_unchecked(&fscache_n_stores),
52035 + atomic_read_unchecked(&fscache_n_stores_ok),
52036 + atomic_read_unchecked(&fscache_n_stores_again),
52037 + atomic_read_unchecked(&fscache_n_stores_nobufs),
52038 + atomic_read_unchecked(&fscache_n_stores_oom));
52039 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
52040 - atomic_read(&fscache_n_store_ops),
52041 - atomic_read(&fscache_n_store_calls),
52042 - atomic_read(&fscache_n_store_pages),
52043 - atomic_read(&fscache_n_store_radix_deletes),
52044 - atomic_read(&fscache_n_store_pages_over_limit));
52045 + atomic_read_unchecked(&fscache_n_store_ops),
52046 + atomic_read_unchecked(&fscache_n_store_calls),
52047 + atomic_read_unchecked(&fscache_n_store_pages),
52048 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
52049 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
52050
52051 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
52052 - atomic_read(&fscache_n_store_vmscan_not_storing),
52053 - atomic_read(&fscache_n_store_vmscan_gone),
52054 - atomic_read(&fscache_n_store_vmscan_busy),
52055 - atomic_read(&fscache_n_store_vmscan_cancelled),
52056 - atomic_read(&fscache_n_store_vmscan_wait));
52057 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
52058 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
52059 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
52060 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
52061 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
52062
52063 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
52064 - atomic_read(&fscache_n_op_pend),
52065 - atomic_read(&fscache_n_op_run),
52066 - atomic_read(&fscache_n_op_enqueue),
52067 - atomic_read(&fscache_n_op_cancelled),
52068 - atomic_read(&fscache_n_op_rejected));
52069 + atomic_read_unchecked(&fscache_n_op_pend),
52070 + atomic_read_unchecked(&fscache_n_op_run),
52071 + atomic_read_unchecked(&fscache_n_op_enqueue),
52072 + atomic_read_unchecked(&fscache_n_op_cancelled),
52073 + atomic_read_unchecked(&fscache_n_op_rejected));
52074 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
52075 - atomic_read(&fscache_n_op_deferred_release),
52076 - atomic_read(&fscache_n_op_release),
52077 - atomic_read(&fscache_n_op_gc));
52078 + atomic_read_unchecked(&fscache_n_op_deferred_release),
52079 + atomic_read_unchecked(&fscache_n_op_release),
52080 + atomic_read_unchecked(&fscache_n_op_gc));
52081
52082 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
52083 atomic_read(&fscache_n_cop_alloc_object),
52084 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
52085 index e397b67..b0d8709 100644
52086 --- a/fs/fuse/cuse.c
52087 +++ b/fs/fuse/cuse.c
52088 @@ -593,10 +593,12 @@ static int __init cuse_init(void)
52089 INIT_LIST_HEAD(&cuse_conntbl[i]);
52090
52091 /* inherit and extend fuse_dev_operations */
52092 - cuse_channel_fops = fuse_dev_operations;
52093 - cuse_channel_fops.owner = THIS_MODULE;
52094 - cuse_channel_fops.open = cuse_channel_open;
52095 - cuse_channel_fops.release = cuse_channel_release;
52096 + pax_open_kernel();
52097 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
52098 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
52099 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
52100 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
52101 + pax_close_kernel();
52102
52103 cuse_class = class_create(THIS_MODULE, "cuse");
52104 if (IS_ERR(cuse_class))
52105 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
52106 index e83351a..41e3c9c 100644
52107 --- a/fs/fuse/dev.c
52108 +++ b/fs/fuse/dev.c
52109 @@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
52110 ret = 0;
52111 pipe_lock(pipe);
52112
52113 - if (!pipe->readers) {
52114 + if (!atomic_read(&pipe->readers)) {
52115 send_sig(SIGPIPE, current, 0);
52116 if (!ret)
52117 ret = -EPIPE;
52118 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
52119 index 315e1f8..91f890c 100644
52120 --- a/fs/fuse/dir.c
52121 +++ b/fs/fuse/dir.c
52122 @@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
52123 return link;
52124 }
52125
52126 -static void free_link(char *link)
52127 +static void free_link(const char *link)
52128 {
52129 if (!IS_ERR(link))
52130 free_page((unsigned long) link);
52131 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
52132 index 2b6f569..fcb4d1f 100644
52133 --- a/fs/gfs2/inode.c
52134 +++ b/fs/gfs2/inode.c
52135 @@ -1499,7 +1499,7 @@ out:
52136
52137 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52138 {
52139 - char *s = nd_get_link(nd);
52140 + const char *s = nd_get_link(nd);
52141 if (!IS_ERR(s))
52142 kfree(s);
52143 }
52144 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
52145 index 78bde32..767e906 100644
52146 --- a/fs/hugetlbfs/inode.c
52147 +++ b/fs/hugetlbfs/inode.c
52148 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52149 struct mm_struct *mm = current->mm;
52150 struct vm_area_struct *vma;
52151 struct hstate *h = hstate_file(file);
52152 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
52153 struct vm_unmapped_area_info info;
52154
52155 if (len & ~huge_page_mask(h))
52156 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52157 return addr;
52158 }
52159
52160 +#ifdef CONFIG_PAX_RANDMMAP
52161 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
52162 +#endif
52163 +
52164 if (addr) {
52165 addr = ALIGN(addr, huge_page_size(h));
52166 vma = find_vma(mm, addr);
52167 - if (TASK_SIZE - len >= addr &&
52168 - (!vma || addr + len <= vma->vm_start))
52169 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
52170 return addr;
52171 }
52172
52173 info.flags = 0;
52174 info.length = len;
52175 info.low_limit = TASK_UNMAPPED_BASE;
52176 +
52177 +#ifdef CONFIG_PAX_RANDMMAP
52178 + if (mm->pax_flags & MF_PAX_RANDMMAP)
52179 + info.low_limit += mm->delta_mmap;
52180 +#endif
52181 +
52182 info.high_limit = TASK_SIZE;
52183 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
52184 info.align_offset = 0;
52185 @@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
52186 .kill_sb = kill_litter_super,
52187 };
52188
52189 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52190 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52191
52192 static int can_do_hugetlb_shm(void)
52193 {
52194 diff --git a/fs/inode.c b/fs/inode.c
52195 index 14084b7..29af1d9 100644
52196 --- a/fs/inode.c
52197 +++ b/fs/inode.c
52198 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
52199
52200 #ifdef CONFIG_SMP
52201 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
52202 - static atomic_t shared_last_ino;
52203 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
52204 + static atomic_unchecked_t shared_last_ino;
52205 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
52206
52207 res = next - LAST_INO_BATCH;
52208 }
52209 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
52210 index 4a6cf28..d3a29d3 100644
52211 --- a/fs/jffs2/erase.c
52212 +++ b/fs/jffs2/erase.c
52213 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
52214 struct jffs2_unknown_node marker = {
52215 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
52216 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52217 - .totlen = cpu_to_je32(c->cleanmarker_size)
52218 + .totlen = cpu_to_je32(c->cleanmarker_size),
52219 + .hdr_crc = cpu_to_je32(0)
52220 };
52221
52222 jffs2_prealloc_raw_node_refs(c, jeb, 1);
52223 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
52224 index a6597d6..41b30ec 100644
52225 --- a/fs/jffs2/wbuf.c
52226 +++ b/fs/jffs2/wbuf.c
52227 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
52228 {
52229 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
52230 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52231 - .totlen = constant_cpu_to_je32(8)
52232 + .totlen = constant_cpu_to_je32(8),
52233 + .hdr_crc = constant_cpu_to_je32(0)
52234 };
52235
52236 /*
52237 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
52238 index 1a543be..a4e1363 100644
52239 --- a/fs/jfs/super.c
52240 +++ b/fs/jfs/super.c
52241 @@ -225,7 +225,7 @@ static const match_table_t tokens = {
52242 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52243 int *flag)
52244 {
52245 - void *nls_map = (void *)-1; /* -1: no change; NULL: none */
52246 + const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
52247 char *p;
52248 struct jfs_sb_info *sbi = JFS_SBI(sb);
52249
52250 @@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52251 /* Don't do anything ;-) */
52252 break;
52253 case Opt_iocharset:
52254 - if (nls_map && nls_map != (void *) -1)
52255 + if (nls_map && nls_map != (const void *) -1)
52256 unload_nls(nls_map);
52257 if (!strcmp(args[0].from, "none"))
52258 nls_map = NULL;
52259 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
52260
52261 jfs_inode_cachep =
52262 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
52263 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
52264 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
52265 init_once);
52266 if (jfs_inode_cachep == NULL)
52267 return -ENOMEM;
52268 diff --git a/fs/libfs.c b/fs/libfs.c
52269 index 916da8c..1588998 100644
52270 --- a/fs/libfs.c
52271 +++ b/fs/libfs.c
52272 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52273
52274 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
52275 struct dentry *next;
52276 + char d_name[sizeof(next->d_iname)];
52277 + const unsigned char *name;
52278 +
52279 next = list_entry(p, struct dentry, d_u.d_child);
52280 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
52281 if (!simple_positive(next)) {
52282 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52283
52284 spin_unlock(&next->d_lock);
52285 spin_unlock(&dentry->d_lock);
52286 - if (filldir(dirent, next->d_name.name,
52287 + name = next->d_name.name;
52288 + if (name == next->d_iname) {
52289 + memcpy(d_name, name, next->d_name.len);
52290 + name = d_name;
52291 + }
52292 + if (filldir(dirent, name,
52293 next->d_name.len, filp->f_pos,
52294 next->d_inode->i_ino,
52295 dt_type(next->d_inode)) < 0)
52296 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
52297 index 52e5120..808936e 100644
52298 --- a/fs/lockd/clntproc.c
52299 +++ b/fs/lockd/clntproc.c
52300 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
52301 /*
52302 * Cookie counter for NLM requests
52303 */
52304 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
52305 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
52306
52307 void nlmclnt_next_cookie(struct nlm_cookie *c)
52308 {
52309 - u32 cookie = atomic_inc_return(&nlm_cookie);
52310 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
52311
52312 memcpy(c->data, &cookie, 4);
52313 c->len=4;
52314 diff --git a/fs/locks.c b/fs/locks.c
52315 index a94e331..060bce3 100644
52316 --- a/fs/locks.c
52317 +++ b/fs/locks.c
52318 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
52319 return;
52320
52321 if (filp->f_op && filp->f_op->flock) {
52322 - struct file_lock fl = {
52323 + struct file_lock flock = {
52324 .fl_pid = current->tgid,
52325 .fl_file = filp,
52326 .fl_flags = FL_FLOCK,
52327 .fl_type = F_UNLCK,
52328 .fl_end = OFFSET_MAX,
52329 };
52330 - filp->f_op->flock(filp, F_SETLKW, &fl);
52331 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
52332 - fl.fl_ops->fl_release_private(&fl);
52333 + filp->f_op->flock(filp, F_SETLKW, &flock);
52334 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
52335 + flock.fl_ops->fl_release_private(&flock);
52336 }
52337
52338 lock_flocks();
52339 diff --git a/fs/namei.c b/fs/namei.c
52340 index ec97aef..eedf4fe 100644
52341 --- a/fs/namei.c
52342 +++ b/fs/namei.c
52343 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
52344 if (ret != -EACCES)
52345 return ret;
52346
52347 +#ifdef CONFIG_GRKERNSEC
52348 + /* we'll block if we have to log due to a denied capability use */
52349 + if (mask & MAY_NOT_BLOCK)
52350 + return -ECHILD;
52351 +#endif
52352 +
52353 if (S_ISDIR(inode->i_mode)) {
52354 /* DACs are overridable for directories */
52355 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
52356 - return 0;
52357 if (!(mask & MAY_WRITE))
52358 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52359 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52360 + inode_capable(inode, CAP_DAC_READ_SEARCH))
52361 return 0;
52362 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
52363 + return 0;
52364 return -EACCES;
52365 }
52366 /*
52367 + * Searching includes executable on directories, else just read.
52368 + */
52369 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52370 + if (mask == MAY_READ)
52371 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52372 + inode_capable(inode, CAP_DAC_READ_SEARCH))
52373 + return 0;
52374 +
52375 + /*
52376 * Read/write DACs are always overridable.
52377 * Executable DACs are overridable when there is
52378 * at least one exec bit set.
52379 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
52380 if (inode_capable(inode, CAP_DAC_OVERRIDE))
52381 return 0;
52382
52383 - /*
52384 - * Searching includes executable on directories, else just read.
52385 - */
52386 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52387 - if (mask == MAY_READ)
52388 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52389 - return 0;
52390 -
52391 return -EACCES;
52392 }
52393
52394 @@ -824,7 +832,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52395 {
52396 struct dentry *dentry = link->dentry;
52397 int error;
52398 - char *s;
52399 + const char *s;
52400
52401 BUG_ON(nd->flags & LOOKUP_RCU);
52402
52403 @@ -845,6 +853,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52404 if (error)
52405 goto out_put_nd_path;
52406
52407 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
52408 + dentry->d_inode, dentry, nd->path.mnt)) {
52409 + error = -EACCES;
52410 + goto out_put_nd_path;
52411 + }
52412 +
52413 nd->last_type = LAST_BIND;
52414 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
52415 error = PTR_ERR(*p);
52416 @@ -1594,6 +1608,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
52417 break;
52418 res = walk_component(nd, path, &nd->last,
52419 nd->last_type, LOOKUP_FOLLOW);
52420 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
52421 + res = -EACCES;
52422 put_link(nd, &link, cookie);
52423 } while (res > 0);
52424
52425 @@ -1692,7 +1708,7 @@ EXPORT_SYMBOL(full_name_hash);
52426 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
52427 {
52428 unsigned long a, b, adata, bdata, mask, hash, len;
52429 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52430 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52431
52432 hash = a = 0;
52433 len = -sizeof(unsigned long);
52434 @@ -1977,6 +1993,8 @@ static int path_lookupat(int dfd, const char *name,
52435 if (err)
52436 break;
52437 err = lookup_last(nd, &path);
52438 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
52439 + err = -EACCES;
52440 put_link(nd, &link, cookie);
52441 }
52442 }
52443 @@ -1984,6 +2002,19 @@ static int path_lookupat(int dfd, const char *name,
52444 if (!err)
52445 err = complete_walk(nd);
52446
52447 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
52448 +#ifdef CONFIG_GRKERNSEC
52449 + if (flags & LOOKUP_RCU) {
52450 + path_put(&nd->path);
52451 + err = -ECHILD;
52452 + } else
52453 +#endif
52454 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52455 + path_put(&nd->path);
52456 + err = -ENOENT;
52457 + }
52458 + }
52459 +
52460 if (!err && nd->flags & LOOKUP_DIRECTORY) {
52461 if (!nd->inode->i_op->lookup) {
52462 path_put(&nd->path);
52463 @@ -2011,8 +2042,17 @@ static int filename_lookup(int dfd, struct filename *name,
52464 retval = path_lookupat(dfd, name->name,
52465 flags | LOOKUP_REVAL, nd);
52466
52467 - if (likely(!retval))
52468 + if (likely(!retval)) {
52469 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
52470 +#ifdef CONFIG_GRKERNSEC
52471 + if (flags & LOOKUP_RCU)
52472 + return -ECHILD;
52473 +#endif
52474 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
52475 + return -ENOENT;
52476 + }
52477 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
52478 + }
52479 return retval;
52480 }
52481
52482 @@ -2390,6 +2430,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
52483 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
52484 return -EPERM;
52485
52486 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
52487 + return -EPERM;
52488 + if (gr_handle_rawio(inode))
52489 + return -EPERM;
52490 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
52491 + return -EACCES;
52492 +
52493 return 0;
52494 }
52495
52496 @@ -2611,7 +2658,7 @@ looked_up:
52497 * cleared otherwise prior to returning.
52498 */
52499 static int lookup_open(struct nameidata *nd, struct path *path,
52500 - struct file *file,
52501 + struct path *link, struct file *file,
52502 const struct open_flags *op,
52503 bool got_write, int *opened)
52504 {
52505 @@ -2646,6 +2693,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52506 /* Negative dentry, just create the file */
52507 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
52508 umode_t mode = op->mode;
52509 +
52510 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
52511 + error = -EACCES;
52512 + goto out_dput;
52513 + }
52514 +
52515 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
52516 + error = -EACCES;
52517 + goto out_dput;
52518 + }
52519 +
52520 if (!IS_POSIXACL(dir->d_inode))
52521 mode &= ~current_umask();
52522 /*
52523 @@ -2667,6 +2725,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52524 nd->flags & LOOKUP_EXCL);
52525 if (error)
52526 goto out_dput;
52527 + else
52528 + gr_handle_create(dentry, nd->path.mnt);
52529 }
52530 out_no_open:
52531 path->dentry = dentry;
52532 @@ -2681,7 +2741,7 @@ out_dput:
52533 /*
52534 * Handle the last step of open()
52535 */
52536 -static int do_last(struct nameidata *nd, struct path *path,
52537 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
52538 struct file *file, const struct open_flags *op,
52539 int *opened, struct filename *name)
52540 {
52541 @@ -2710,16 +2770,44 @@ static int do_last(struct nameidata *nd, struct path *path,
52542 error = complete_walk(nd);
52543 if (error)
52544 return error;
52545 +#ifdef CONFIG_GRKERNSEC
52546 + if (nd->flags & LOOKUP_RCU) {
52547 + error = -ECHILD;
52548 + goto out;
52549 + }
52550 +#endif
52551 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52552 + error = -ENOENT;
52553 + goto out;
52554 + }
52555 audit_inode(name, nd->path.dentry, 0);
52556 if (open_flag & O_CREAT) {
52557 error = -EISDIR;
52558 goto out;
52559 }
52560 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
52561 + error = -EACCES;
52562 + goto out;
52563 + }
52564 goto finish_open;
52565 case LAST_BIND:
52566 error = complete_walk(nd);
52567 if (error)
52568 return error;
52569 +#ifdef CONFIG_GRKERNSEC
52570 + if (nd->flags & LOOKUP_RCU) {
52571 + error = -ECHILD;
52572 + goto out;
52573 + }
52574 +#endif
52575 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
52576 + error = -ENOENT;
52577 + goto out;
52578 + }
52579 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
52580 + error = -EACCES;
52581 + goto out;
52582 + }
52583 audit_inode(name, dir, 0);
52584 goto finish_open;
52585 }
52586 @@ -2768,7 +2856,7 @@ retry_lookup:
52587 */
52588 }
52589 mutex_lock(&dir->d_inode->i_mutex);
52590 - error = lookup_open(nd, path, file, op, got_write, opened);
52591 + error = lookup_open(nd, path, link, file, op, got_write, opened);
52592 mutex_unlock(&dir->d_inode->i_mutex);
52593
52594 if (error <= 0) {
52595 @@ -2792,11 +2880,28 @@ retry_lookup:
52596 goto finish_open_created;
52597 }
52598
52599 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
52600 + error = -ENOENT;
52601 + goto exit_dput;
52602 + }
52603 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
52604 + error = -EACCES;
52605 + goto exit_dput;
52606 + }
52607 +
52608 /*
52609 * create/update audit record if it already exists.
52610 */
52611 - if (path->dentry->d_inode)
52612 + if (path->dentry->d_inode) {
52613 + /* only check if O_CREAT is specified, all other checks need to go
52614 + into may_open */
52615 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
52616 + error = -EACCES;
52617 + goto exit_dput;
52618 + }
52619 +
52620 audit_inode(name, path->dentry, 0);
52621 + }
52622
52623 /*
52624 * If atomic_open() acquired write access it is dropped now due to
52625 @@ -2837,6 +2942,11 @@ finish_lookup:
52626 }
52627 }
52628 BUG_ON(inode != path->dentry->d_inode);
52629 + /* if we're resolving a symlink to another symlink */
52630 + if (link && gr_handle_symlink_owner(link, inode)) {
52631 + error = -EACCES;
52632 + goto out;
52633 + }
52634 return 1;
52635 }
52636
52637 @@ -2846,7 +2956,6 @@ finish_lookup:
52638 save_parent.dentry = nd->path.dentry;
52639 save_parent.mnt = mntget(path->mnt);
52640 nd->path.dentry = path->dentry;
52641 -
52642 }
52643 nd->inode = inode;
52644 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
52645 @@ -2855,6 +2964,22 @@ finish_lookup:
52646 path_put(&save_parent);
52647 return error;
52648 }
52649 +
52650 +#ifdef CONFIG_GRKERNSEC
52651 + if (nd->flags & LOOKUP_RCU) {
52652 + error = -ECHILD;
52653 + goto out;
52654 + }
52655 +#endif
52656 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52657 + error = -ENOENT;
52658 + goto out;
52659 + }
52660 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
52661 + error = -EACCES;
52662 + goto out;
52663 + }
52664 +
52665 error = -EISDIR;
52666 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
52667 goto out;
52668 @@ -2953,7 +3078,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
52669 if (unlikely(error))
52670 goto out;
52671
52672 - error = do_last(nd, &path, file, op, &opened, pathname);
52673 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
52674 while (unlikely(error > 0)) { /* trailing symlink */
52675 struct path link = path;
52676 void *cookie;
52677 @@ -2971,7 +3096,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
52678 error = follow_link(&link, nd, &cookie);
52679 if (unlikely(error))
52680 break;
52681 - error = do_last(nd, &path, file, op, &opened, pathname);
52682 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
52683 put_link(nd, &link, cookie);
52684 }
52685 out:
52686 @@ -3071,8 +3196,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
52687 goto unlock;
52688
52689 error = -EEXIST;
52690 - if (dentry->d_inode)
52691 + if (dentry->d_inode) {
52692 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
52693 + error = -ENOENT;
52694 + }
52695 goto fail;
52696 + }
52697 /*
52698 * Special case - lookup gave negative, but... we had foo/bar/
52699 * From the vfs_mknod() POV we just have a negative dentry -
52700 @@ -3124,6 +3253,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
52701 }
52702 EXPORT_SYMBOL(user_path_create);
52703
52704 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
52705 +{
52706 + struct filename *tmp = getname(pathname);
52707 + struct dentry *res;
52708 + if (IS_ERR(tmp))
52709 + return ERR_CAST(tmp);
52710 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
52711 + if (IS_ERR(res))
52712 + putname(tmp);
52713 + else
52714 + *to = tmp;
52715 + return res;
52716 +}
52717 +
52718 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
52719 {
52720 int error = may_create(dir, dentry);
52721 @@ -3186,6 +3329,17 @@ retry:
52722
52723 if (!IS_POSIXACL(path.dentry->d_inode))
52724 mode &= ~current_umask();
52725 +
52726 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
52727 + error = -EPERM;
52728 + goto out;
52729 + }
52730 +
52731 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
52732 + error = -EACCES;
52733 + goto out;
52734 + }
52735 +
52736 error = security_path_mknod(&path, dentry, mode, dev);
52737 if (error)
52738 goto out;
52739 @@ -3202,6 +3356,8 @@ retry:
52740 break;
52741 }
52742 out:
52743 + if (!error)
52744 + gr_handle_create(dentry, path.mnt);
52745 done_path_create(&path, dentry);
52746 if (retry_estale(error, lookup_flags)) {
52747 lookup_flags |= LOOKUP_REVAL;
52748 @@ -3254,9 +3410,16 @@ retry:
52749
52750 if (!IS_POSIXACL(path.dentry->d_inode))
52751 mode &= ~current_umask();
52752 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
52753 + error = -EACCES;
52754 + goto out;
52755 + }
52756 error = security_path_mkdir(&path, dentry, mode);
52757 if (!error)
52758 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
52759 + if (!error)
52760 + gr_handle_create(dentry, path.mnt);
52761 +out:
52762 done_path_create(&path, dentry);
52763 if (retry_estale(error, lookup_flags)) {
52764 lookup_flags |= LOOKUP_REVAL;
52765 @@ -3337,6 +3500,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
52766 struct filename *name;
52767 struct dentry *dentry;
52768 struct nameidata nd;
52769 + ino_t saved_ino = 0;
52770 + dev_t saved_dev = 0;
52771 unsigned int lookup_flags = 0;
52772 retry:
52773 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
52774 @@ -3369,10 +3534,21 @@ retry:
52775 error = -ENOENT;
52776 goto exit3;
52777 }
52778 +
52779 + saved_ino = dentry->d_inode->i_ino;
52780 + saved_dev = gr_get_dev_from_dentry(dentry);
52781 +
52782 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
52783 + error = -EACCES;
52784 + goto exit3;
52785 + }
52786 +
52787 error = security_path_rmdir(&nd.path, dentry);
52788 if (error)
52789 goto exit3;
52790 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
52791 + if (!error && (saved_dev || saved_ino))
52792 + gr_handle_delete(saved_ino, saved_dev);
52793 exit3:
52794 dput(dentry);
52795 exit2:
52796 @@ -3438,6 +3614,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
52797 struct dentry *dentry;
52798 struct nameidata nd;
52799 struct inode *inode = NULL;
52800 + ino_t saved_ino = 0;
52801 + dev_t saved_dev = 0;
52802 unsigned int lookup_flags = 0;
52803 retry:
52804 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
52805 @@ -3464,10 +3642,22 @@ retry:
52806 if (!inode)
52807 goto slashes;
52808 ihold(inode);
52809 +
52810 + if (inode->i_nlink <= 1) {
52811 + saved_ino = inode->i_ino;
52812 + saved_dev = gr_get_dev_from_dentry(dentry);
52813 + }
52814 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
52815 + error = -EACCES;
52816 + goto exit2;
52817 + }
52818 +
52819 error = security_path_unlink(&nd.path, dentry);
52820 if (error)
52821 goto exit2;
52822 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
52823 + if (!error && (saved_ino || saved_dev))
52824 + gr_handle_delete(saved_ino, saved_dev);
52825 exit2:
52826 dput(dentry);
52827 }
52828 @@ -3545,9 +3735,17 @@ retry:
52829 if (IS_ERR(dentry))
52830 goto out_putname;
52831
52832 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
52833 + error = -EACCES;
52834 + goto out;
52835 + }
52836 +
52837 error = security_path_symlink(&path, dentry, from->name);
52838 if (!error)
52839 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
52840 + if (!error)
52841 + gr_handle_create(dentry, path.mnt);
52842 +out:
52843 done_path_create(&path, dentry);
52844 if (retry_estale(error, lookup_flags)) {
52845 lookup_flags |= LOOKUP_REVAL;
52846 @@ -3621,6 +3819,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
52847 {
52848 struct dentry *new_dentry;
52849 struct path old_path, new_path;
52850 + struct filename *to = NULL;
52851 int how = 0;
52852 int error;
52853
52854 @@ -3644,7 +3843,7 @@ retry:
52855 if (error)
52856 return error;
52857
52858 - new_dentry = user_path_create(newdfd, newname, &new_path,
52859 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
52860 (how & LOOKUP_REVAL));
52861 error = PTR_ERR(new_dentry);
52862 if (IS_ERR(new_dentry))
52863 @@ -3656,11 +3855,28 @@ retry:
52864 error = may_linkat(&old_path);
52865 if (unlikely(error))
52866 goto out_dput;
52867 +
52868 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
52869 + old_path.dentry->d_inode,
52870 + old_path.dentry->d_inode->i_mode, to)) {
52871 + error = -EACCES;
52872 + goto out_dput;
52873 + }
52874 +
52875 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
52876 + old_path.dentry, old_path.mnt, to)) {
52877 + error = -EACCES;
52878 + goto out_dput;
52879 + }
52880 +
52881 error = security_path_link(old_path.dentry, &new_path, new_dentry);
52882 if (error)
52883 goto out_dput;
52884 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
52885 + if (!error)
52886 + gr_handle_create(new_dentry, new_path.mnt);
52887 out_dput:
52888 + putname(to);
52889 done_path_create(&new_path, new_dentry);
52890 if (retry_estale(error, how)) {
52891 how |= LOOKUP_REVAL;
52892 @@ -3906,12 +4122,21 @@ retry:
52893 if (new_dentry == trap)
52894 goto exit5;
52895
52896 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
52897 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
52898 + to);
52899 + if (error)
52900 + goto exit5;
52901 +
52902 error = security_path_rename(&oldnd.path, old_dentry,
52903 &newnd.path, new_dentry);
52904 if (error)
52905 goto exit5;
52906 error = vfs_rename(old_dir->d_inode, old_dentry,
52907 new_dir->d_inode, new_dentry);
52908 + if (!error)
52909 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
52910 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
52911 exit5:
52912 dput(new_dentry);
52913 exit4:
52914 @@ -3943,6 +4168,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
52915
52916 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
52917 {
52918 + char tmpbuf[64];
52919 + const char *newlink;
52920 int len;
52921
52922 len = PTR_ERR(link);
52923 @@ -3952,7 +4179,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
52924 len = strlen(link);
52925 if (len > (unsigned) buflen)
52926 len = buflen;
52927 - if (copy_to_user(buffer, link, len))
52928 +
52929 + if (len < sizeof(tmpbuf)) {
52930 + memcpy(tmpbuf, link, len);
52931 + newlink = tmpbuf;
52932 + } else
52933 + newlink = link;
52934 +
52935 + if (copy_to_user(buffer, newlink, len))
52936 len = -EFAULT;
52937 out:
52938 return len;
52939 diff --git a/fs/namespace.c b/fs/namespace.c
52940 index a51054f..f9b53e5 100644
52941 --- a/fs/namespace.c
52942 +++ b/fs/namespace.c
52943 @@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
52944 if (!(sb->s_flags & MS_RDONLY))
52945 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
52946 up_write(&sb->s_umount);
52947 +
52948 + gr_log_remount(mnt->mnt_devname, retval);
52949 +
52950 return retval;
52951 }
52952
52953 @@ -1234,6 +1237,9 @@ static int do_umount(struct mount *mnt, int flags)
52954 br_write_unlock(&vfsmount_lock);
52955 up_write(&namespace_sem);
52956 release_mounts(&umount_list);
52957 +
52958 + gr_log_unmount(mnt->mnt_devname, retval);
52959 +
52960 return retval;
52961 }
52962
52963 @@ -2287,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
52964 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
52965 MS_STRICTATIME);
52966
52967 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
52968 + retval = -EPERM;
52969 + goto dput_out;
52970 + }
52971 +
52972 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
52973 + retval = -EPERM;
52974 + goto dput_out;
52975 + }
52976 +
52977 if (flags & MS_REMOUNT)
52978 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
52979 data_page);
52980 @@ -2301,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
52981 dev_name, data_page);
52982 dput_out:
52983 path_put(&path);
52984 +
52985 + gr_log_mount(dev_name, dir_name, retval);
52986 +
52987 return retval;
52988 }
52989
52990 @@ -2587,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
52991 if (error)
52992 goto out2;
52993
52994 + if (gr_handle_chroot_pivot()) {
52995 + error = -EPERM;
52996 + goto out2;
52997 + }
52998 +
52999 get_fs_root(current->fs, &root);
53000 error = lock_mount(&old);
53001 if (error)
53002 @@ -2790,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
53003 !nsown_capable(CAP_SYS_ADMIN))
53004 return -EPERM;
53005
53006 - if (fs->users != 1)
53007 + if (atomic_read(&fs->users) != 1)
53008 return -EINVAL;
53009
53010 get_mnt_ns(mnt_ns);
53011 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
53012 index 59461c9..b17c57e 100644
53013 --- a/fs/nfs/callback_xdr.c
53014 +++ b/fs/nfs/callback_xdr.c
53015 @@ -51,7 +51,7 @@ struct callback_op {
53016 callback_decode_arg_t decode_args;
53017 callback_encode_res_t encode_res;
53018 long res_maxsize;
53019 -};
53020 +} __do_const;
53021
53022 static struct callback_op callback_ops[];
53023
53024 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
53025 index ebeb94c..ff35337 100644
53026 --- a/fs/nfs/inode.c
53027 +++ b/fs/nfs/inode.c
53028 @@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
53029 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
53030 }
53031
53032 -static atomic_long_t nfs_attr_generation_counter;
53033 +static atomic_long_unchecked_t nfs_attr_generation_counter;
53034
53035 static unsigned long nfs_read_attr_generation_counter(void)
53036 {
53037 - return atomic_long_read(&nfs_attr_generation_counter);
53038 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
53039 }
53040
53041 unsigned long nfs_inc_attr_generation_counter(void)
53042 {
53043 - return atomic_long_inc_return(&nfs_attr_generation_counter);
53044 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
53045 }
53046
53047 void nfs_fattr_init(struct nfs_fattr *fattr)
53048 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
53049 index 9d1c5db..1e13db8 100644
53050 --- a/fs/nfsd/nfs4proc.c
53051 +++ b/fs/nfsd/nfs4proc.c
53052 @@ -1097,7 +1097,7 @@ struct nfsd4_operation {
53053 nfsd4op_rsize op_rsize_bop;
53054 stateid_getter op_get_currentstateid;
53055 stateid_setter op_set_currentstateid;
53056 -};
53057 +} __do_const;
53058
53059 static struct nfsd4_operation nfsd4_ops[];
53060
53061 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
53062 index 0dc1158..ccf0338 100644
53063 --- a/fs/nfsd/nfs4xdr.c
53064 +++ b/fs/nfsd/nfs4xdr.c
53065 @@ -1456,7 +1456,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
53066
53067 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
53068
53069 -static nfsd4_dec nfsd4_dec_ops[] = {
53070 +static const nfsd4_dec nfsd4_dec_ops[] = {
53071 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53072 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53073 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53074 @@ -1496,7 +1496,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
53075 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
53076 };
53077
53078 -static nfsd4_dec nfsd41_dec_ops[] = {
53079 +static const nfsd4_dec nfsd41_dec_ops[] = {
53080 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53081 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53082 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53083 @@ -1558,7 +1558,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
53084 };
53085
53086 struct nfsd4_minorversion_ops {
53087 - nfsd4_dec *decoders;
53088 + const nfsd4_dec *decoders;
53089 int nops;
53090 };
53091
53092 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
53093 index d586117..143d568 100644
53094 --- a/fs/nfsd/vfs.c
53095 +++ b/fs/nfsd/vfs.c
53096 @@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53097 } else {
53098 oldfs = get_fs();
53099 set_fs(KERNEL_DS);
53100 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
53101 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
53102 set_fs(oldfs);
53103 }
53104
53105 @@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53106
53107 /* Write the data. */
53108 oldfs = get_fs(); set_fs(KERNEL_DS);
53109 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
53110 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
53111 set_fs(oldfs);
53112 if (host_err < 0)
53113 goto out_nfserr;
53114 @@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
53115 */
53116
53117 oldfs = get_fs(); set_fs(KERNEL_DS);
53118 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
53119 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
53120 set_fs(oldfs);
53121
53122 if (host_err < 0)
53123 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
53124 index fea6bd5..8ee9d81 100644
53125 --- a/fs/nls/nls_base.c
53126 +++ b/fs/nls/nls_base.c
53127 @@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
53128
53129 int register_nls(struct nls_table * nls)
53130 {
53131 - struct nls_table ** tmp = &tables;
53132 + struct nls_table *tmp = tables;
53133
53134 if (nls->next)
53135 return -EBUSY;
53136
53137 spin_lock(&nls_lock);
53138 - while (*tmp) {
53139 - if (nls == *tmp) {
53140 + while (tmp) {
53141 + if (nls == tmp) {
53142 spin_unlock(&nls_lock);
53143 return -EBUSY;
53144 }
53145 - tmp = &(*tmp)->next;
53146 + tmp = tmp->next;
53147 }
53148 - nls->next = tables;
53149 + pax_open_kernel();
53150 + *(struct nls_table **)&nls->next = tables;
53151 + pax_close_kernel();
53152 tables = nls;
53153 spin_unlock(&nls_lock);
53154 return 0;
53155 @@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
53156
53157 int unregister_nls(struct nls_table * nls)
53158 {
53159 - struct nls_table ** tmp = &tables;
53160 + struct nls_table * const * tmp = &tables;
53161
53162 spin_lock(&nls_lock);
53163 while (*tmp) {
53164 if (nls == *tmp) {
53165 - *tmp = nls->next;
53166 + pax_open_kernel();
53167 + *(struct nls_table **)tmp = nls->next;
53168 + pax_close_kernel();
53169 spin_unlock(&nls_lock);
53170 return 0;
53171 }
53172 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
53173 index 7424929..35f6be5 100644
53174 --- a/fs/nls/nls_euc-jp.c
53175 +++ b/fs/nls/nls_euc-jp.c
53176 @@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
53177 p_nls = load_nls("cp932");
53178
53179 if (p_nls) {
53180 - table.charset2upper = p_nls->charset2upper;
53181 - table.charset2lower = p_nls->charset2lower;
53182 + pax_open_kernel();
53183 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53184 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53185 + pax_close_kernel();
53186 return register_nls(&table);
53187 }
53188
53189 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
53190 index e7bc1d7..06bd4bb 100644
53191 --- a/fs/nls/nls_koi8-ru.c
53192 +++ b/fs/nls/nls_koi8-ru.c
53193 @@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
53194 p_nls = load_nls("koi8-u");
53195
53196 if (p_nls) {
53197 - table.charset2upper = p_nls->charset2upper;
53198 - table.charset2lower = p_nls->charset2lower;
53199 + pax_open_kernel();
53200 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53201 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53202 + pax_close_kernel();
53203 return register_nls(&table);
53204 }
53205
53206 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
53207 index 9ff4a5e..deb1f0f 100644
53208 --- a/fs/notify/fanotify/fanotify_user.c
53209 +++ b/fs/notify/fanotify/fanotify_user.c
53210 @@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
53211
53212 fd = fanotify_event_metadata.fd;
53213 ret = -EFAULT;
53214 - if (copy_to_user(buf, &fanotify_event_metadata,
53215 - fanotify_event_metadata.event_len))
53216 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
53217 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
53218 goto out_close_fd;
53219
53220 ret = prepare_for_access_response(group, event, fd);
53221 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
53222 index 7b51b05..5ea5ef6 100644
53223 --- a/fs/notify/notification.c
53224 +++ b/fs/notify/notification.c
53225 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
53226 * get set to 0 so it will never get 'freed'
53227 */
53228 static struct fsnotify_event *q_overflow_event;
53229 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53230 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53231
53232 /**
53233 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
53234 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53235 */
53236 u32 fsnotify_get_cookie(void)
53237 {
53238 - return atomic_inc_return(&fsnotify_sync_cookie);
53239 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
53240 }
53241 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
53242
53243 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
53244 index 99e3610..02c1068 100644
53245 --- a/fs/ntfs/dir.c
53246 +++ b/fs/ntfs/dir.c
53247 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
53248 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
53249 ~(s64)(ndir->itype.index.block_size - 1)));
53250 /* Bounds checks. */
53251 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53252 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53253 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
53254 "inode 0x%lx or driver bug.", vdir->i_ino);
53255 goto err_out;
53256 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
53257 index 5b2d4f0..c6de396 100644
53258 --- a/fs/ntfs/file.c
53259 +++ b/fs/ntfs/file.c
53260 @@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
53261 #endif /* NTFS_RW */
53262 };
53263
53264 -const struct file_operations ntfs_empty_file_ops = {};
53265 +const struct file_operations ntfs_empty_file_ops __read_only;
53266
53267 -const struct inode_operations ntfs_empty_inode_ops = {};
53268 +const struct inode_operations ntfs_empty_inode_ops __read_only;
53269 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
53270 index a9f78c7..ed8a381 100644
53271 --- a/fs/ocfs2/localalloc.c
53272 +++ b/fs/ocfs2/localalloc.c
53273 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
53274 goto bail;
53275 }
53276
53277 - atomic_inc(&osb->alloc_stats.moves);
53278 + atomic_inc_unchecked(&osb->alloc_stats.moves);
53279
53280 bail:
53281 if (handle)
53282 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
53283 index d355e6e..578d905 100644
53284 --- a/fs/ocfs2/ocfs2.h
53285 +++ b/fs/ocfs2/ocfs2.h
53286 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
53287
53288 struct ocfs2_alloc_stats
53289 {
53290 - atomic_t moves;
53291 - atomic_t local_data;
53292 - atomic_t bitmap_data;
53293 - atomic_t bg_allocs;
53294 - atomic_t bg_extends;
53295 + atomic_unchecked_t moves;
53296 + atomic_unchecked_t local_data;
53297 + atomic_unchecked_t bitmap_data;
53298 + atomic_unchecked_t bg_allocs;
53299 + atomic_unchecked_t bg_extends;
53300 };
53301
53302 enum ocfs2_local_alloc_state
53303 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
53304 index b7e74b5..19c6536 100644
53305 --- a/fs/ocfs2/suballoc.c
53306 +++ b/fs/ocfs2/suballoc.c
53307 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
53308 mlog_errno(status);
53309 goto bail;
53310 }
53311 - atomic_inc(&osb->alloc_stats.bg_extends);
53312 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
53313
53314 /* You should never ask for this much metadata */
53315 BUG_ON(bits_wanted >
53316 @@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
53317 mlog_errno(status);
53318 goto bail;
53319 }
53320 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53321 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53322
53323 *suballoc_loc = res.sr_bg_blkno;
53324 *suballoc_bit_start = res.sr_bit_offset;
53325 @@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
53326 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
53327 res->sr_bits);
53328
53329 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53330 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53331
53332 BUG_ON(res->sr_bits != 1);
53333
53334 @@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
53335 mlog_errno(status);
53336 goto bail;
53337 }
53338 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53339 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53340
53341 BUG_ON(res.sr_bits != 1);
53342
53343 @@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53344 cluster_start,
53345 num_clusters);
53346 if (!status)
53347 - atomic_inc(&osb->alloc_stats.local_data);
53348 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
53349 } else {
53350 if (min_clusters > (osb->bitmap_cpg - 1)) {
53351 /* The only paths asking for contiguousness
53352 @@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53353 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
53354 res.sr_bg_blkno,
53355 res.sr_bit_offset);
53356 - atomic_inc(&osb->alloc_stats.bitmap_data);
53357 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
53358 *num_clusters = res.sr_bits;
53359 }
53360 }
53361 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
53362 index 0e91ec2..f4b3fc6 100644
53363 --- a/fs/ocfs2/super.c
53364 +++ b/fs/ocfs2/super.c
53365 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
53366 "%10s => GlobalAllocs: %d LocalAllocs: %d "
53367 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
53368 "Stats",
53369 - atomic_read(&osb->alloc_stats.bitmap_data),
53370 - atomic_read(&osb->alloc_stats.local_data),
53371 - atomic_read(&osb->alloc_stats.bg_allocs),
53372 - atomic_read(&osb->alloc_stats.moves),
53373 - atomic_read(&osb->alloc_stats.bg_extends));
53374 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
53375 + atomic_read_unchecked(&osb->alloc_stats.local_data),
53376 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
53377 + atomic_read_unchecked(&osb->alloc_stats.moves),
53378 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
53379
53380 out += snprintf(buf + out, len - out,
53381 "%10s => State: %u Descriptor: %llu Size: %u bits "
53382 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
53383 spin_lock_init(&osb->osb_xattr_lock);
53384 ocfs2_init_steal_slots(osb);
53385
53386 - atomic_set(&osb->alloc_stats.moves, 0);
53387 - atomic_set(&osb->alloc_stats.local_data, 0);
53388 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
53389 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
53390 - atomic_set(&osb->alloc_stats.bg_extends, 0);
53391 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
53392 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
53393 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
53394 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
53395 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
53396
53397 /* Copy the blockcheck stats from the superblock probe */
53398 osb->osb_ecc_stats = *stats;
53399 diff --git a/fs/open.c b/fs/open.c
53400 index 9b33c0c..2ffcca2 100644
53401 --- a/fs/open.c
53402 +++ b/fs/open.c
53403 @@ -31,6 +31,8 @@
53404 #include <linux/ima.h>
53405 #include <linux/dnotify.h>
53406
53407 +#define CREATE_TRACE_POINTS
53408 +#include <trace/events/fs.h>
53409 #include "internal.h"
53410
53411 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
53412 @@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
53413 error = locks_verify_truncate(inode, NULL, length);
53414 if (!error)
53415 error = security_path_truncate(path);
53416 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
53417 + error = -EACCES;
53418 if (!error)
53419 error = do_truncate(path->dentry, length, 0, NULL);
53420
53421 @@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
53422 error = locks_verify_truncate(inode, f.file, length);
53423 if (!error)
53424 error = security_path_truncate(&f.file->f_path);
53425 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
53426 + error = -EACCES;
53427 if (!error)
53428 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
53429 sb_end_write(inode->i_sb);
53430 @@ -373,6 +379,9 @@ retry:
53431 if (__mnt_is_readonly(path.mnt))
53432 res = -EROFS;
53433
53434 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
53435 + res = -EACCES;
53436 +
53437 out_path_release:
53438 path_put(&path);
53439 if (retry_estale(res, lookup_flags)) {
53440 @@ -404,6 +413,8 @@ retry:
53441 if (error)
53442 goto dput_and_out;
53443
53444 + gr_log_chdir(path.dentry, path.mnt);
53445 +
53446 set_fs_pwd(current->fs, &path);
53447
53448 dput_and_out:
53449 @@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
53450 goto out_putf;
53451
53452 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
53453 +
53454 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
53455 + error = -EPERM;
53456 +
53457 + if (!error)
53458 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
53459 +
53460 if (!error)
53461 set_fs_pwd(current->fs, &f.file->f_path);
53462 out_putf:
53463 @@ -462,7 +480,13 @@ retry:
53464 if (error)
53465 goto dput_and_out;
53466
53467 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
53468 + goto dput_and_out;
53469 +
53470 set_fs_root(current->fs, &path);
53471 +
53472 + gr_handle_chroot_chdir(&path);
53473 +
53474 error = 0;
53475 dput_and_out:
53476 path_put(&path);
53477 @@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
53478 if (error)
53479 return error;
53480 mutex_lock(&inode->i_mutex);
53481 +
53482 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
53483 + error = -EACCES;
53484 + goto out_unlock;
53485 + }
53486 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
53487 + error = -EACCES;
53488 + goto out_unlock;
53489 + }
53490 +
53491 error = security_path_chmod(path, mode);
53492 if (error)
53493 goto out_unlock;
53494 @@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
53495 uid = make_kuid(current_user_ns(), user);
53496 gid = make_kgid(current_user_ns(), group);
53497
53498 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
53499 + return -EACCES;
53500 +
53501 newattrs.ia_valid = ATTR_CTIME;
53502 if (user != (uid_t) -1) {
53503 if (!uid_valid(uid))
53504 @@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
53505 } else {
53506 fsnotify_open(f);
53507 fd_install(fd, f);
53508 + trace_do_sys_open(tmp->name, flags, mode);
53509 }
53510 }
53511 putname(tmp);
53512 diff --git a/fs/pipe.c b/fs/pipe.c
53513 index 8e2e73f..1ef1048 100644
53514 --- a/fs/pipe.c
53515 +++ b/fs/pipe.c
53516 @@ -438,9 +438,9 @@ redo:
53517 }
53518 if (bufs) /* More to do? */
53519 continue;
53520 - if (!pipe->writers)
53521 + if (!atomic_read(&pipe->writers))
53522 break;
53523 - if (!pipe->waiting_writers) {
53524 + if (!atomic_read(&pipe->waiting_writers)) {
53525 /* syscall merging: Usually we must not sleep
53526 * if O_NONBLOCK is set, or if we got some data.
53527 * But if a writer sleeps in kernel space, then
53528 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
53529 mutex_lock(&inode->i_mutex);
53530 pipe = inode->i_pipe;
53531
53532 - if (!pipe->readers) {
53533 + if (!atomic_read(&pipe->readers)) {
53534 send_sig(SIGPIPE, current, 0);
53535 ret = -EPIPE;
53536 goto out;
53537 @@ -553,7 +553,7 @@ redo1:
53538 for (;;) {
53539 int bufs;
53540
53541 - if (!pipe->readers) {
53542 + if (!atomic_read(&pipe->readers)) {
53543 send_sig(SIGPIPE, current, 0);
53544 if (!ret)
53545 ret = -EPIPE;
53546 @@ -644,9 +644,9 @@ redo2:
53547 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
53548 do_wakeup = 0;
53549 }
53550 - pipe->waiting_writers++;
53551 + atomic_inc(&pipe->waiting_writers);
53552 pipe_wait(pipe);
53553 - pipe->waiting_writers--;
53554 + atomic_dec(&pipe->waiting_writers);
53555 }
53556 out:
53557 mutex_unlock(&inode->i_mutex);
53558 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
53559 mask = 0;
53560 if (filp->f_mode & FMODE_READ) {
53561 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
53562 - if (!pipe->writers && filp->f_version != pipe->w_counter)
53563 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
53564 mask |= POLLHUP;
53565 }
53566
53567 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
53568 * Most Unices do not set POLLERR for FIFOs but on Linux they
53569 * behave exactly like pipes for poll().
53570 */
53571 - if (!pipe->readers)
53572 + if (!atomic_read(&pipe->readers))
53573 mask |= POLLERR;
53574 }
53575
53576 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
53577
53578 mutex_lock(&inode->i_mutex);
53579 pipe = inode->i_pipe;
53580 - pipe->readers -= decr;
53581 - pipe->writers -= decw;
53582 + atomic_sub(decr, &pipe->readers);
53583 + atomic_sub(decw, &pipe->writers);
53584
53585 - if (!pipe->readers && !pipe->writers) {
53586 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
53587 free_pipe_info(inode);
53588 } else {
53589 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
53590 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
53591
53592 if (inode->i_pipe) {
53593 ret = 0;
53594 - inode->i_pipe->readers++;
53595 + atomic_inc(&inode->i_pipe->readers);
53596 }
53597
53598 mutex_unlock(&inode->i_mutex);
53599 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
53600
53601 if (inode->i_pipe) {
53602 ret = 0;
53603 - inode->i_pipe->writers++;
53604 + atomic_inc(&inode->i_pipe->writers);
53605 }
53606
53607 mutex_unlock(&inode->i_mutex);
53608 @@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
53609 if (inode->i_pipe) {
53610 ret = 0;
53611 if (filp->f_mode & FMODE_READ)
53612 - inode->i_pipe->readers++;
53613 + atomic_inc(&inode->i_pipe->readers);
53614 if (filp->f_mode & FMODE_WRITE)
53615 - inode->i_pipe->writers++;
53616 + atomic_inc(&inode->i_pipe->writers);
53617 }
53618
53619 mutex_unlock(&inode->i_mutex);
53620 @@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
53621 inode->i_pipe = NULL;
53622 }
53623
53624 -static struct vfsmount *pipe_mnt __read_mostly;
53625 +struct vfsmount *pipe_mnt __read_mostly;
53626
53627 /*
53628 * pipefs_dname() is called from d_path().
53629 @@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
53630 goto fail_iput;
53631 inode->i_pipe = pipe;
53632
53633 - pipe->readers = pipe->writers = 1;
53634 + atomic_set(&pipe->readers, 1);
53635 + atomic_set(&pipe->writers, 1);
53636 inode->i_fop = &rdwr_pipefifo_fops;
53637
53638 /*
53639 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
53640 index 15af622..0e9f4467 100644
53641 --- a/fs/proc/Kconfig
53642 +++ b/fs/proc/Kconfig
53643 @@ -30,12 +30,12 @@ config PROC_FS
53644
53645 config PROC_KCORE
53646 bool "/proc/kcore support" if !ARM
53647 - depends on PROC_FS && MMU
53648 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
53649
53650 config PROC_VMCORE
53651 bool "/proc/vmcore support"
53652 - depends on PROC_FS && CRASH_DUMP
53653 - default y
53654 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
53655 + default n
53656 help
53657 Exports the dump image of crashed kernel in ELF format.
53658
53659 @@ -59,8 +59,8 @@ config PROC_SYSCTL
53660 limited in memory.
53661
53662 config PROC_PAGE_MONITOR
53663 - default y
53664 - depends on PROC_FS && MMU
53665 + default n
53666 + depends on PROC_FS && MMU && !GRKERNSEC
53667 bool "Enable /proc page monitoring" if EXPERT
53668 help
53669 Various /proc files exist to monitor process memory utilization:
53670 diff --git a/fs/proc/array.c b/fs/proc/array.c
53671 index 6a91e6f..e54dbc14 100644
53672 --- a/fs/proc/array.c
53673 +++ b/fs/proc/array.c
53674 @@ -60,6 +60,7 @@
53675 #include <linux/tty.h>
53676 #include <linux/string.h>
53677 #include <linux/mman.h>
53678 +#include <linux/grsecurity.h>
53679 #include <linux/proc_fs.h>
53680 #include <linux/ioport.h>
53681 #include <linux/uaccess.h>
53682 @@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
53683 seq_putc(m, '\n');
53684 }
53685
53686 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53687 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
53688 +{
53689 + if (p->mm)
53690 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
53691 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
53692 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
53693 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
53694 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
53695 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
53696 + else
53697 + seq_printf(m, "PaX:\t-----\n");
53698 +}
53699 +#endif
53700 +
53701 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
53702 struct pid *pid, struct task_struct *task)
53703 {
53704 @@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
53705 task_cpus_allowed(m, task);
53706 cpuset_task_status_allowed(m, task);
53707 task_context_switch_counts(m, task);
53708 +
53709 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53710 + task_pax(m, task);
53711 +#endif
53712 +
53713 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
53714 + task_grsec_rbac(m, task);
53715 +#endif
53716 +
53717 return 0;
53718 }
53719
53720 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53721 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53722 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
53723 + _mm->pax_flags & MF_PAX_SEGMEXEC))
53724 +#endif
53725 +
53726 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53727 struct pid *pid, struct task_struct *task, int whole)
53728 {
53729 @@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53730 char tcomm[sizeof(task->comm)];
53731 unsigned long flags;
53732
53733 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53734 + if (current->exec_id != m->exec_id) {
53735 + gr_log_badprocpid("stat");
53736 + return 0;
53737 + }
53738 +#endif
53739 +
53740 state = *get_task_state(task);
53741 vsize = eip = esp = 0;
53742 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
53743 @@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53744 gtime = task->gtime;
53745 }
53746
53747 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53748 + if (PAX_RAND_FLAGS(mm)) {
53749 + eip = 0;
53750 + esp = 0;
53751 + wchan = 0;
53752 + }
53753 +#endif
53754 +#ifdef CONFIG_GRKERNSEC_HIDESYM
53755 + wchan = 0;
53756 + eip =0;
53757 + esp =0;
53758 +#endif
53759 +
53760 /* scale priority and nice values from timeslices to -20..20 */
53761 /* to make it look like a "normal" Unix priority/nice value */
53762 priority = task_prio(task);
53763 @@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53764 seq_put_decimal_ull(m, ' ', vsize);
53765 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
53766 seq_put_decimal_ull(m, ' ', rsslim);
53767 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53768 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
53769 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
53770 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
53771 +#else
53772 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
53773 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
53774 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
53775 +#endif
53776 seq_put_decimal_ull(m, ' ', esp);
53777 seq_put_decimal_ull(m, ' ', eip);
53778 /* The signal information here is obsolete.
53779 @@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53780 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
53781 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
53782
53783 - if (mm && permitted) {
53784 + if (mm && permitted
53785 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53786 + && !PAX_RAND_FLAGS(mm)
53787 +#endif
53788 + ) {
53789 seq_put_decimal_ull(m, ' ', mm->start_data);
53790 seq_put_decimal_ull(m, ' ', mm->end_data);
53791 seq_put_decimal_ull(m, ' ', mm->start_brk);
53792 @@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
53793 struct pid *pid, struct task_struct *task)
53794 {
53795 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
53796 - struct mm_struct *mm = get_task_mm(task);
53797 + struct mm_struct *mm;
53798
53799 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53800 + if (current->exec_id != m->exec_id) {
53801 + gr_log_badprocpid("statm");
53802 + return 0;
53803 + }
53804 +#endif
53805 + mm = get_task_mm(task);
53806 if (mm) {
53807 size = task_statm(mm, &shared, &text, &data, &resident);
53808 mmput(mm);
53809 @@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
53810 return 0;
53811 }
53812
53813 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
53814 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
53815 +{
53816 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
53817 +}
53818 +#endif
53819 +
53820 #ifdef CONFIG_CHECKPOINT_RESTORE
53821 static struct pid *
53822 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
53823 diff --git a/fs/proc/base.c b/fs/proc/base.c
53824 index 9b43ff77..ba3e990 100644
53825 --- a/fs/proc/base.c
53826 +++ b/fs/proc/base.c
53827 @@ -111,6 +111,14 @@ struct pid_entry {
53828 union proc_op op;
53829 };
53830
53831 +struct getdents_callback {
53832 + struct linux_dirent __user * current_dir;
53833 + struct linux_dirent __user * previous;
53834 + struct file * file;
53835 + int count;
53836 + int error;
53837 +};
53838 +
53839 #define NOD(NAME, MODE, IOP, FOP, OP) { \
53840 .name = (NAME), \
53841 .len = sizeof(NAME) - 1, \
53842 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
53843 if (!mm->arg_end)
53844 goto out_mm; /* Shh! No looking before we're done */
53845
53846 + if (gr_acl_handle_procpidmem(task))
53847 + goto out_mm;
53848 +
53849 len = mm->arg_end - mm->arg_start;
53850
53851 if (len > PAGE_SIZE)
53852 @@ -235,12 +246,28 @@ out:
53853 return res;
53854 }
53855
53856 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53857 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53858 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
53859 + _mm->pax_flags & MF_PAX_SEGMEXEC))
53860 +#endif
53861 +
53862 static int proc_pid_auxv(struct task_struct *task, char *buffer)
53863 {
53864 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
53865 int res = PTR_ERR(mm);
53866 if (mm && !IS_ERR(mm)) {
53867 unsigned int nwords = 0;
53868 +
53869 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53870 + /* allow if we're currently ptracing this task */
53871 + if (PAX_RAND_FLAGS(mm) &&
53872 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
53873 + mmput(mm);
53874 + return 0;
53875 + }
53876 +#endif
53877 +
53878 do {
53879 nwords += 2;
53880 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
53881 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
53882 }
53883
53884
53885 -#ifdef CONFIG_KALLSYMS
53886 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53887 /*
53888 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
53889 * Returns the resolved symbol. If that fails, simply return the address.
53890 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
53891 mutex_unlock(&task->signal->cred_guard_mutex);
53892 }
53893
53894 -#ifdef CONFIG_STACKTRACE
53895 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53896
53897 #define MAX_STACK_TRACE_DEPTH 64
53898
53899 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
53900 return count;
53901 }
53902
53903 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
53904 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
53905 static int proc_pid_syscall(struct task_struct *task, char *buffer)
53906 {
53907 long nr;
53908 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
53909 /************************************************************************/
53910
53911 /* permission checks */
53912 -static int proc_fd_access_allowed(struct inode *inode)
53913 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
53914 {
53915 struct task_struct *task;
53916 int allowed = 0;
53917 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
53918 */
53919 task = get_proc_task(inode);
53920 if (task) {
53921 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
53922 + if (log)
53923 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
53924 + else
53925 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
53926 put_task_struct(task);
53927 }
53928 return allowed;
53929 @@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
53930 struct task_struct *task,
53931 int hide_pid_min)
53932 {
53933 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
53934 + return false;
53935 +
53936 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53937 + rcu_read_lock();
53938 + {
53939 + const struct cred *tmpcred = current_cred();
53940 + const struct cred *cred = __task_cred(task);
53941 +
53942 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
53943 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
53944 + || in_group_p(grsec_proc_gid)
53945 +#endif
53946 + ) {
53947 + rcu_read_unlock();
53948 + return true;
53949 + }
53950 + }
53951 + rcu_read_unlock();
53952 +
53953 + if (!pid->hide_pid)
53954 + return false;
53955 +#endif
53956 +
53957 if (pid->hide_pid < hide_pid_min)
53958 return true;
53959 if (in_group_p(pid->pid_gid))
53960 return true;
53961 +
53962 return ptrace_may_access(task, PTRACE_MODE_READ);
53963 }
53964
53965 @@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
53966 put_task_struct(task);
53967
53968 if (!has_perms) {
53969 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53970 + {
53971 +#else
53972 if (pid->hide_pid == 2) {
53973 +#endif
53974 /*
53975 * Let's make getdents(), stat(), and open()
53976 * consistent with each other. If a process
53977 @@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
53978 if (!task)
53979 return -ESRCH;
53980
53981 + if (gr_acl_handle_procpidmem(task)) {
53982 + put_task_struct(task);
53983 + return -EPERM;
53984 + }
53985 +
53986 mm = mm_access(task, mode);
53987 put_task_struct(task);
53988
53989 @@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
53990
53991 file->private_data = mm;
53992
53993 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53994 + file->f_version = current->exec_id;
53995 +#endif
53996 +
53997 return 0;
53998 }
53999
54000 @@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
54001 ssize_t copied;
54002 char *page;
54003
54004 +#ifdef CONFIG_GRKERNSEC
54005 + if (write)
54006 + return -EPERM;
54007 +#endif
54008 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54009 + if (file->f_version != current->exec_id) {
54010 + gr_log_badprocpid("mem");
54011 + return 0;
54012 + }
54013 +#endif
54014 +
54015 if (!mm)
54016 return 0;
54017
54018 @@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
54019 if (!mm)
54020 return 0;
54021
54022 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54023 + if (file->f_version != current->exec_id) {
54024 + gr_log_badprocpid("environ");
54025 + return 0;
54026 + }
54027 +#endif
54028 +
54029 page = (char *)__get_free_page(GFP_TEMPORARY);
54030 if (!page)
54031 return -ENOMEM;
54032 @@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
54033 int error = -EACCES;
54034
54035 /* Are we allowed to snoop on the tasks file descriptors? */
54036 - if (!proc_fd_access_allowed(inode))
54037 + if (!proc_fd_access_allowed(inode, 0))
54038 goto out;
54039
54040 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54041 @@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
54042 struct path path;
54043
54044 /* Are we allowed to snoop on the tasks file descriptors? */
54045 - if (!proc_fd_access_allowed(inode))
54046 - goto out;
54047 + /* logging this is needed for learning on chromium to work properly,
54048 + but we don't want to flood the logs from 'ps' which does a readlink
54049 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
54050 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
54051 + */
54052 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
54053 + if (!proc_fd_access_allowed(inode,0))
54054 + goto out;
54055 + } else {
54056 + if (!proc_fd_access_allowed(inode,1))
54057 + goto out;
54058 + }
54059
54060 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54061 if (error)
54062 @@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
54063 rcu_read_lock();
54064 cred = __task_cred(task);
54065 inode->i_uid = cred->euid;
54066 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54067 + inode->i_gid = grsec_proc_gid;
54068 +#else
54069 inode->i_gid = cred->egid;
54070 +#endif
54071 rcu_read_unlock();
54072 }
54073 security_task_to_inode(task, inode);
54074 @@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
54075 return -ENOENT;
54076 }
54077 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54078 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54079 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54080 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54081 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54082 +#endif
54083 task_dumpable(task)) {
54084 cred = __task_cred(task);
54085 stat->uid = cred->euid;
54086 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54087 + stat->gid = grsec_proc_gid;
54088 +#else
54089 stat->gid = cred->egid;
54090 +#endif
54091 }
54092 }
54093 rcu_read_unlock();
54094 @@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
54095
54096 if (task) {
54097 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54098 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54099 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54100 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54101 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54102 +#endif
54103 task_dumpable(task)) {
54104 rcu_read_lock();
54105 cred = __task_cred(task);
54106 inode->i_uid = cred->euid;
54107 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54108 + inode->i_gid = grsec_proc_gid;
54109 +#else
54110 inode->i_gid = cred->egid;
54111 +#endif
54112 rcu_read_unlock();
54113 } else {
54114 inode->i_uid = GLOBAL_ROOT_UID;
54115 @@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
54116 if (!task)
54117 goto out_no_task;
54118
54119 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54120 + goto out;
54121 +
54122 /*
54123 * Yes, it does not scale. And it should not. Don't add
54124 * new entries into /proc/<tgid>/ without very good reasons.
54125 @@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
54126 if (!task)
54127 goto out_no_task;
54128
54129 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54130 + goto out;
54131 +
54132 ret = 0;
54133 i = filp->f_pos;
54134 switch (i) {
54135 @@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
54136 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
54137 #endif
54138 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54139 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54140 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54141 INF("syscall", S_IRUGO, proc_pid_syscall),
54142 #endif
54143 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54144 @@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
54145 #ifdef CONFIG_SECURITY
54146 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54147 #endif
54148 -#ifdef CONFIG_KALLSYMS
54149 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54150 INF("wchan", S_IRUGO, proc_pid_wchan),
54151 #endif
54152 -#ifdef CONFIG_STACKTRACE
54153 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54154 ONE("stack", S_IRUGO, proc_pid_stack),
54155 #endif
54156 #ifdef CONFIG_SCHEDSTATS
54157 @@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
54158 #ifdef CONFIG_HARDWALL
54159 INF("hardwall", S_IRUGO, proc_pid_hardwall),
54160 #endif
54161 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54162 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
54163 +#endif
54164 #ifdef CONFIG_USER_NS
54165 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
54166 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
54167 @@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
54168 if (!inode)
54169 goto out;
54170
54171 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54172 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
54173 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54174 + inode->i_gid = grsec_proc_gid;
54175 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
54176 +#else
54177 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
54178 +#endif
54179 inode->i_op = &proc_tgid_base_inode_operations;
54180 inode->i_fop = &proc_tgid_base_operations;
54181 inode->i_flags|=S_IMMUTABLE;
54182 @@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
54183 if (!task)
54184 goto out;
54185
54186 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54187 + goto out_put_task;
54188 +
54189 result = proc_pid_instantiate(dir, dentry, task, NULL);
54190 +out_put_task:
54191 put_task_struct(task);
54192 out:
54193 return result;
54194 @@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
54195 static int fake_filldir(void *buf, const char *name, int namelen,
54196 loff_t offset, u64 ino, unsigned d_type)
54197 {
54198 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
54199 + __buf->error = -EINVAL;
54200 return 0;
54201 }
54202
54203 @@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
54204 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
54205 #endif
54206 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54207 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54208 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54209 INF("syscall", S_IRUGO, proc_pid_syscall),
54210 #endif
54211 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54212 @@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
54213 #ifdef CONFIG_SECURITY
54214 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54215 #endif
54216 -#ifdef CONFIG_KALLSYMS
54217 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54218 INF("wchan", S_IRUGO, proc_pid_wchan),
54219 #endif
54220 -#ifdef CONFIG_STACKTRACE
54221 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54222 ONE("stack", S_IRUGO, proc_pid_stack),
54223 #endif
54224 #ifdef CONFIG_SCHEDSTATS
54225 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
54226 index 82676e3..5f8518a 100644
54227 --- a/fs/proc/cmdline.c
54228 +++ b/fs/proc/cmdline.c
54229 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
54230
54231 static int __init proc_cmdline_init(void)
54232 {
54233 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
54234 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
54235 +#else
54236 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
54237 +#endif
54238 return 0;
54239 }
54240 module_init(proc_cmdline_init);
54241 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
54242 index b143471..bb105e5 100644
54243 --- a/fs/proc/devices.c
54244 +++ b/fs/proc/devices.c
54245 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
54246
54247 static int __init proc_devices_init(void)
54248 {
54249 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
54250 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
54251 +#else
54252 proc_create("devices", 0, NULL, &proc_devinfo_operations);
54253 +#endif
54254 return 0;
54255 }
54256 module_init(proc_devices_init);
54257 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
54258 index d7a4a28..0201742 100644
54259 --- a/fs/proc/fd.c
54260 +++ b/fs/proc/fd.c
54261 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
54262 if (!task)
54263 return -ENOENT;
54264
54265 - files = get_files_struct(task);
54266 + if (!gr_acl_handle_procpidmem(task))
54267 + files = get_files_struct(task);
54268 put_task_struct(task);
54269
54270 if (files) {
54271 @@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
54272 */
54273 int proc_fd_permission(struct inode *inode, int mask)
54274 {
54275 + struct task_struct *task;
54276 int rv = generic_permission(inode, mask);
54277 - if (rv == 0)
54278 - return 0;
54279 +
54280 if (task_pid(current) == proc_pid(inode))
54281 rv = 0;
54282 +
54283 + task = get_proc_task(inode);
54284 + if (task == NULL)
54285 + return rv;
54286 +
54287 + if (gr_acl_handle_procpidmem(task))
54288 + rv = -EACCES;
54289 +
54290 + put_task_struct(task);
54291 +
54292 return rv;
54293 }
54294
54295 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
54296 index 439ae688..c21ac36 100644
54297 --- a/fs/proc/inode.c
54298 +++ b/fs/proc/inode.c
54299 @@ -21,11 +21,17 @@
54300 #include <linux/seq_file.h>
54301 #include <linux/slab.h>
54302 #include <linux/mount.h>
54303 +#include <linux/grsecurity.h>
54304
54305 #include <asm/uaccess.h>
54306
54307 #include "internal.h"
54308
54309 +#ifdef CONFIG_PROC_SYSCTL
54310 +extern const struct inode_operations proc_sys_inode_operations;
54311 +extern const struct inode_operations proc_sys_dir_operations;
54312 +#endif
54313 +
54314 static void proc_evict_inode(struct inode *inode)
54315 {
54316 struct proc_dir_entry *de;
54317 @@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
54318 ns = PROC_I(inode)->ns;
54319 if (ns_ops && ns)
54320 ns_ops->put(ns);
54321 +
54322 +#ifdef CONFIG_PROC_SYSCTL
54323 + if (inode->i_op == &proc_sys_inode_operations ||
54324 + inode->i_op == &proc_sys_dir_operations)
54325 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
54326 +#endif
54327 +
54328 }
54329
54330 static struct kmem_cache * proc_inode_cachep;
54331 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
54332 if (de->mode) {
54333 inode->i_mode = de->mode;
54334 inode->i_uid = de->uid;
54335 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54336 + inode->i_gid = grsec_proc_gid;
54337 +#else
54338 inode->i_gid = de->gid;
54339 +#endif
54340 }
54341 if (de->size)
54342 inode->i_size = de->size;
54343 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
54344 index 252544c..04395b9 100644
54345 --- a/fs/proc/internal.h
54346 +++ b/fs/proc/internal.h
54347 @@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54348 struct pid *pid, struct task_struct *task);
54349 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54350 struct pid *pid, struct task_struct *task);
54351 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54352 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
54353 +#endif
54354 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
54355
54356 extern const struct file_operations proc_tid_children_operations;
54357 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
54358 index e96d4f1..8b116ed 100644
54359 --- a/fs/proc/kcore.c
54360 +++ b/fs/proc/kcore.c
54361 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54362 * the addresses in the elf_phdr on our list.
54363 */
54364 start = kc_offset_to_vaddr(*fpos - elf_buflen);
54365 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
54366 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
54367 + if (tsz > buflen)
54368 tsz = buflen;
54369 -
54370 +
54371 while (buflen) {
54372 struct kcore_list *m;
54373
54374 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54375 kfree(elf_buf);
54376 } else {
54377 if (kern_addr_valid(start)) {
54378 - unsigned long n;
54379 + char *elf_buf;
54380 + mm_segment_t oldfs;
54381
54382 - n = copy_to_user(buffer, (char *)start, tsz);
54383 - /*
54384 - * We cannot distinguish between fault on source
54385 - * and fault on destination. When this happens
54386 - * we clear too and hope it will trigger the
54387 - * EFAULT again.
54388 - */
54389 - if (n) {
54390 - if (clear_user(buffer + tsz - n,
54391 - n))
54392 + elf_buf = kmalloc(tsz, GFP_KERNEL);
54393 + if (!elf_buf)
54394 + return -ENOMEM;
54395 + oldfs = get_fs();
54396 + set_fs(KERNEL_DS);
54397 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
54398 + set_fs(oldfs);
54399 + if (copy_to_user(buffer, elf_buf, tsz)) {
54400 + kfree(elf_buf);
54401 return -EFAULT;
54402 + }
54403 }
54404 + set_fs(oldfs);
54405 + kfree(elf_buf);
54406 } else {
54407 if (clear_user(buffer, tsz))
54408 return -EFAULT;
54409 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54410
54411 static int open_kcore(struct inode *inode, struct file *filp)
54412 {
54413 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
54414 + return -EPERM;
54415 +#endif
54416 if (!capable(CAP_SYS_RAWIO))
54417 return -EPERM;
54418 if (kcore_need_update)
54419 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
54420 index 80e4645..53e5fcf 100644
54421 --- a/fs/proc/meminfo.c
54422 +++ b/fs/proc/meminfo.c
54423 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
54424 vmi.used >> 10,
54425 vmi.largest_chunk >> 10
54426 #ifdef CONFIG_MEMORY_FAILURE
54427 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
54428 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
54429 #endif
54430 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
54431 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
54432 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
54433 index b1822dd..df622cb 100644
54434 --- a/fs/proc/nommu.c
54435 +++ b/fs/proc/nommu.c
54436 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
54437 if (len < 1)
54438 len = 1;
54439 seq_printf(m, "%*c", len, ' ');
54440 - seq_path(m, &file->f_path, "");
54441 + seq_path(m, &file->f_path, "\n\\");
54442 }
54443
54444 seq_putc(m, '\n');
54445 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
54446 index fe72cd0..21b52ff 100644
54447 --- a/fs/proc/proc_net.c
54448 +++ b/fs/proc/proc_net.c
54449 @@ -23,6 +23,7 @@
54450 #include <linux/nsproxy.h>
54451 #include <net/net_namespace.h>
54452 #include <linux/seq_file.h>
54453 +#include <linux/grsecurity.h>
54454
54455 #include "internal.h"
54456
54457 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
54458 struct task_struct *task;
54459 struct nsproxy *ns;
54460 struct net *net = NULL;
54461 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54462 + const struct cred *cred = current_cred();
54463 +#endif
54464 +
54465 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54466 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
54467 + return net;
54468 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54469 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
54470 + return net;
54471 +#endif
54472
54473 rcu_read_lock();
54474 task = pid_task(proc_pid(dir), PIDTYPE_PID);
54475 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
54476 index 1827d88..43b0279 100644
54477 --- a/fs/proc/proc_sysctl.c
54478 +++ b/fs/proc/proc_sysctl.c
54479 @@ -12,11 +12,15 @@
54480 #include <linux/module.h>
54481 #include "internal.h"
54482
54483 +extern int gr_handle_chroot_sysctl(const int op);
54484 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
54485 + const int op);
54486 +
54487 static const struct dentry_operations proc_sys_dentry_operations;
54488 static const struct file_operations proc_sys_file_operations;
54489 -static const struct inode_operations proc_sys_inode_operations;
54490 +const struct inode_operations proc_sys_inode_operations;
54491 static const struct file_operations proc_sys_dir_file_operations;
54492 -static const struct inode_operations proc_sys_dir_operations;
54493 +const struct inode_operations proc_sys_dir_operations;
54494
54495 void proc_sys_poll_notify(struct ctl_table_poll *poll)
54496 {
54497 @@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
54498
54499 err = NULL;
54500 d_set_d_op(dentry, &proc_sys_dentry_operations);
54501 +
54502 + gr_handle_proc_create(dentry, inode);
54503 +
54504 d_add(dentry, inode);
54505
54506 out:
54507 @@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54508 struct inode *inode = filp->f_path.dentry->d_inode;
54509 struct ctl_table_header *head = grab_header(inode);
54510 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
54511 + int op = write ? MAY_WRITE : MAY_READ;
54512 ssize_t error;
54513 size_t res;
54514
54515 @@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54516 * and won't be until we finish.
54517 */
54518 error = -EPERM;
54519 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
54520 + if (sysctl_perm(head, table, op))
54521 goto out;
54522
54523 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
54524 @@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54525 if (!table->proc_handler)
54526 goto out;
54527
54528 +#ifdef CONFIG_GRKERNSEC
54529 + error = -EPERM;
54530 + if (gr_handle_chroot_sysctl(op))
54531 + goto out;
54532 + dget(filp->f_path.dentry);
54533 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
54534 + dput(filp->f_path.dentry);
54535 + goto out;
54536 + }
54537 + dput(filp->f_path.dentry);
54538 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
54539 + goto out;
54540 + if (write && !capable(CAP_SYS_ADMIN))
54541 + goto out;
54542 +#endif
54543 +
54544 /* careful: calling conventions are nasty here */
54545 res = count;
54546 error = table->proc_handler(table, write, buf, &res, ppos);
54547 @@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
54548 return -ENOMEM;
54549 } else {
54550 d_set_d_op(child, &proc_sys_dentry_operations);
54551 +
54552 + gr_handle_proc_create(child, inode);
54553 +
54554 d_add(child, inode);
54555 }
54556 } else {
54557 @@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
54558 if ((*pos)++ < file->f_pos)
54559 return 0;
54560
54561 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
54562 + return 0;
54563 +
54564 if (unlikely(S_ISLNK(table->mode)))
54565 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
54566 else
54567 @@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
54568 if (IS_ERR(head))
54569 return PTR_ERR(head);
54570
54571 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
54572 + return -ENOENT;
54573 +
54574 generic_fillattr(inode, stat);
54575 if (table)
54576 stat->mode = (stat->mode & S_IFMT) | table->mode;
54577 @@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
54578 .llseek = generic_file_llseek,
54579 };
54580
54581 -static const struct inode_operations proc_sys_inode_operations = {
54582 +const struct inode_operations proc_sys_inode_operations = {
54583 .permission = proc_sys_permission,
54584 .setattr = proc_sys_setattr,
54585 .getattr = proc_sys_getattr,
54586 };
54587
54588 -static const struct inode_operations proc_sys_dir_operations = {
54589 +const struct inode_operations proc_sys_dir_operations = {
54590 .lookup = proc_sys_lookup,
54591 .permission = proc_sys_permission,
54592 .setattr = proc_sys_setattr,
54593 @@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
54594 static struct ctl_dir *new_dir(struct ctl_table_set *set,
54595 const char *name, int namelen)
54596 {
54597 - struct ctl_table *table;
54598 + ctl_table_no_const *table;
54599 struct ctl_dir *new;
54600 struct ctl_node *node;
54601 char *new_name;
54602 @@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
54603 return NULL;
54604
54605 node = (struct ctl_node *)(new + 1);
54606 - table = (struct ctl_table *)(node + 1);
54607 + table = (ctl_table_no_const *)(node + 1);
54608 new_name = (char *)(table + 2);
54609 memcpy(new_name, name, namelen);
54610 new_name[namelen] = '\0';
54611 @@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
54612 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
54613 struct ctl_table_root *link_root)
54614 {
54615 - struct ctl_table *link_table, *entry, *link;
54616 + ctl_table_no_const *link_table, *link;
54617 + struct ctl_table *entry;
54618 struct ctl_table_header *links;
54619 struct ctl_node *node;
54620 char *link_name;
54621 @@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
54622 return NULL;
54623
54624 node = (struct ctl_node *)(links + 1);
54625 - link_table = (struct ctl_table *)(node + nr_entries);
54626 + link_table = (ctl_table_no_const *)(node + nr_entries);
54627 link_name = (char *)&link_table[nr_entries + 1];
54628
54629 for (link = link_table, entry = table; entry->procname; link++, entry++) {
54630 @@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54631 struct ctl_table_header ***subheader, struct ctl_table_set *set,
54632 struct ctl_table *table)
54633 {
54634 - struct ctl_table *ctl_table_arg = NULL;
54635 - struct ctl_table *entry, *files;
54636 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
54637 + struct ctl_table *entry;
54638 int nr_files = 0;
54639 int nr_dirs = 0;
54640 int err = -ENOMEM;
54641 @@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54642 nr_files++;
54643 }
54644
54645 - files = table;
54646 /* If there are mixed files and directories we need a new table */
54647 if (nr_dirs && nr_files) {
54648 - struct ctl_table *new;
54649 + ctl_table_no_const *new;
54650 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
54651 GFP_KERNEL);
54652 if (!files)
54653 @@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54654 /* Register everything except a directory full of subdirectories */
54655 if (nr_files || !nr_dirs) {
54656 struct ctl_table_header *header;
54657 - header = __register_sysctl_table(set, path, files);
54658 + header = __register_sysctl_table(set, path, files ? files : table);
54659 if (!header) {
54660 kfree(ctl_table_arg);
54661 goto out;
54662 diff --git a/fs/proc/root.c b/fs/proc/root.c
54663 index c6e9fac..a740964 100644
54664 --- a/fs/proc/root.c
54665 +++ b/fs/proc/root.c
54666 @@ -176,7 +176,15 @@ void __init proc_root_init(void)
54667 #ifdef CONFIG_PROC_DEVICETREE
54668 proc_device_tree_init();
54669 #endif
54670 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
54671 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54672 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
54673 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54674 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
54675 +#endif
54676 +#else
54677 proc_mkdir("bus", NULL);
54678 +#endif
54679 proc_sys_init();
54680 }
54681
54682 diff --git a/fs/proc/self.c b/fs/proc/self.c
54683 index aa5cc3b..c91a5d0 100644
54684 --- a/fs/proc/self.c
54685 +++ b/fs/proc/self.c
54686 @@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
54687 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
54688 void *cookie)
54689 {
54690 - char *s = nd_get_link(nd);
54691 + const char *s = nd_get_link(nd);
54692 if (!IS_ERR(s))
54693 kfree(s);
54694 }
54695 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
54696 index ca5ce7f..02c1cf0 100644
54697 --- a/fs/proc/task_mmu.c
54698 +++ b/fs/proc/task_mmu.c
54699 @@ -11,12 +11,19 @@
54700 #include <linux/rmap.h>
54701 #include <linux/swap.h>
54702 #include <linux/swapops.h>
54703 +#include <linux/grsecurity.h>
54704
54705 #include <asm/elf.h>
54706 #include <asm/uaccess.h>
54707 #include <asm/tlbflush.h>
54708 #include "internal.h"
54709
54710 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54711 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54712 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
54713 + _mm->pax_flags & MF_PAX_SEGMEXEC))
54714 +#endif
54715 +
54716 void task_mem(struct seq_file *m, struct mm_struct *mm)
54717 {
54718 unsigned long data, text, lib, swap;
54719 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54720 "VmExe:\t%8lu kB\n"
54721 "VmLib:\t%8lu kB\n"
54722 "VmPTE:\t%8lu kB\n"
54723 - "VmSwap:\t%8lu kB\n",
54724 - hiwater_vm << (PAGE_SHIFT-10),
54725 + "VmSwap:\t%8lu kB\n"
54726 +
54727 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54728 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
54729 +#endif
54730 +
54731 + ,hiwater_vm << (PAGE_SHIFT-10),
54732 total_vm << (PAGE_SHIFT-10),
54733 mm->locked_vm << (PAGE_SHIFT-10),
54734 mm->pinned_vm << (PAGE_SHIFT-10),
54735 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54736 data << (PAGE_SHIFT-10),
54737 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
54738 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
54739 - swap << (PAGE_SHIFT-10));
54740 + swap << (PAGE_SHIFT-10)
54741 +
54742 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54743 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54744 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
54745 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
54746 +#else
54747 + , mm->context.user_cs_base
54748 + , mm->context.user_cs_limit
54749 +#endif
54750 +#endif
54751 +
54752 + );
54753 }
54754
54755 unsigned long task_vsize(struct mm_struct *mm)
54756 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54757 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
54758 }
54759
54760 - /* We don't show the stack guard page in /proc/maps */
54761 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54762 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
54763 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
54764 +#else
54765 start = vma->vm_start;
54766 - if (stack_guard_page_start(vma, start))
54767 - start += PAGE_SIZE;
54768 end = vma->vm_end;
54769 - if (stack_guard_page_end(vma, end))
54770 - end -= PAGE_SIZE;
54771 +#endif
54772
54773 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
54774 start,
54775 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54776 flags & VM_WRITE ? 'w' : '-',
54777 flags & VM_EXEC ? 'x' : '-',
54778 flags & VM_MAYSHARE ? 's' : 'p',
54779 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54780 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
54781 +#else
54782 pgoff,
54783 +#endif
54784 MAJOR(dev), MINOR(dev), ino, &len);
54785
54786 /*
54787 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54788 */
54789 if (file) {
54790 pad_len_spaces(m, len);
54791 - seq_path(m, &file->f_path, "\n");
54792 + seq_path(m, &file->f_path, "\n\\");
54793 goto done;
54794 }
54795
54796 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54797 * Thread stack in /proc/PID/task/TID/maps or
54798 * the main process stack.
54799 */
54800 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
54801 - vma->vm_end >= mm->start_stack)) {
54802 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
54803 + (vma->vm_start <= mm->start_stack &&
54804 + vma->vm_end >= mm->start_stack)) {
54805 name = "[stack]";
54806 } else {
54807 /* Thread stack in /proc/PID/maps */
54808 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
54809 struct proc_maps_private *priv = m->private;
54810 struct task_struct *task = priv->task;
54811
54812 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54813 + if (current->exec_id != m->exec_id) {
54814 + gr_log_badprocpid("maps");
54815 + return 0;
54816 + }
54817 +#endif
54818 +
54819 show_map_vma(m, vma, is_pid);
54820
54821 if (m->count < m->size) /* vma is copied successfully */
54822 @@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
54823 .private = &mss,
54824 };
54825
54826 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54827 + if (current->exec_id != m->exec_id) {
54828 + gr_log_badprocpid("smaps");
54829 + return 0;
54830 + }
54831 +#endif
54832 memset(&mss, 0, sizeof mss);
54833 - mss.vma = vma;
54834 - /* mmap_sem is held in m_start */
54835 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
54836 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
54837 -
54838 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54839 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
54840 +#endif
54841 + mss.vma = vma;
54842 + /* mmap_sem is held in m_start */
54843 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
54844 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
54845 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54846 + }
54847 +#endif
54848 show_map_vma(m, vma, is_pid);
54849
54850 seq_printf(m,
54851 @@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
54852 "KernelPageSize: %8lu kB\n"
54853 "MMUPageSize: %8lu kB\n"
54854 "Locked: %8lu kB\n",
54855 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54856 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
54857 +#else
54858 (vma->vm_end - vma->vm_start) >> 10,
54859 +#endif
54860 mss.resident >> 10,
54861 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
54862 mss.shared_clean >> 10,
54863 @@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
54864 int n;
54865 char buffer[50];
54866
54867 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54868 + if (current->exec_id != m->exec_id) {
54869 + gr_log_badprocpid("numa_maps");
54870 + return 0;
54871 + }
54872 +#endif
54873 +
54874 if (!mm)
54875 return 0;
54876
54877 @@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
54878 mpol_to_str(buffer, sizeof(buffer), pol);
54879 mpol_cond_put(pol);
54880
54881 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54882 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
54883 +#else
54884 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
54885 +#endif
54886
54887 if (file) {
54888 seq_printf(m, " file=");
54889 - seq_path(m, &file->f_path, "\n\t= ");
54890 + seq_path(m, &file->f_path, "\n\t\\= ");
54891 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
54892 seq_printf(m, " heap");
54893 } else {
54894 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
54895 index 1ccfa53..0848f95 100644
54896 --- a/fs/proc/task_nommu.c
54897 +++ b/fs/proc/task_nommu.c
54898 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54899 else
54900 bytes += kobjsize(mm);
54901
54902 - if (current->fs && current->fs->users > 1)
54903 + if (current->fs && atomic_read(&current->fs->users) > 1)
54904 sbytes += kobjsize(current->fs);
54905 else
54906 bytes += kobjsize(current->fs);
54907 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
54908
54909 if (file) {
54910 pad_len_spaces(m, len);
54911 - seq_path(m, &file->f_path, "");
54912 + seq_path(m, &file->f_path, "\n\\");
54913 } else if (mm) {
54914 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
54915
54916 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
54917 index 16e8abb..2dcf914 100644
54918 --- a/fs/quota/netlink.c
54919 +++ b/fs/quota/netlink.c
54920 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
54921 void quota_send_warning(struct kqid qid, dev_t dev,
54922 const char warntype)
54923 {
54924 - static atomic_t seq;
54925 + static atomic_unchecked_t seq;
54926 struct sk_buff *skb;
54927 void *msg_head;
54928 int ret;
54929 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
54930 "VFS: Not enough memory to send quota warning.\n");
54931 return;
54932 }
54933 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
54934 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
54935 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
54936 if (!msg_head) {
54937 printk(KERN_ERR
54938 diff --git a/fs/readdir.c b/fs/readdir.c
54939 index 5e69ef5..e5d9099 100644
54940 --- a/fs/readdir.c
54941 +++ b/fs/readdir.c
54942 @@ -17,6 +17,7 @@
54943 #include <linux/security.h>
54944 #include <linux/syscalls.h>
54945 #include <linux/unistd.h>
54946 +#include <linux/namei.h>
54947
54948 #include <asm/uaccess.h>
54949
54950 @@ -67,6 +68,7 @@ struct old_linux_dirent {
54951
54952 struct readdir_callback {
54953 struct old_linux_dirent __user * dirent;
54954 + struct file * file;
54955 int result;
54956 };
54957
54958 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
54959 buf->result = -EOVERFLOW;
54960 return -EOVERFLOW;
54961 }
54962 +
54963 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54964 + return 0;
54965 +
54966 buf->result++;
54967 dirent = buf->dirent;
54968 if (!access_ok(VERIFY_WRITE, dirent,
54969 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
54970
54971 buf.result = 0;
54972 buf.dirent = dirent;
54973 + buf.file = f.file;
54974
54975 error = vfs_readdir(f.file, fillonedir, &buf);
54976 if (buf.result)
54977 @@ -139,6 +146,7 @@ struct linux_dirent {
54978 struct getdents_callback {
54979 struct linux_dirent __user * current_dir;
54980 struct linux_dirent __user * previous;
54981 + struct file * file;
54982 int count;
54983 int error;
54984 };
54985 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
54986 buf->error = -EOVERFLOW;
54987 return -EOVERFLOW;
54988 }
54989 +
54990 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54991 + return 0;
54992 +
54993 dirent = buf->previous;
54994 if (dirent) {
54995 if (__put_user(offset, &dirent->d_off))
54996 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
54997 buf.previous = NULL;
54998 buf.count = count;
54999 buf.error = 0;
55000 + buf.file = f.file;
55001
55002 error = vfs_readdir(f.file, filldir, &buf);
55003 if (error >= 0)
55004 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55005 struct getdents_callback64 {
55006 struct linux_dirent64 __user * current_dir;
55007 struct linux_dirent64 __user * previous;
55008 + struct file *file;
55009 int count;
55010 int error;
55011 };
55012 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
55013 buf->error = -EINVAL; /* only used if we fail.. */
55014 if (reclen > buf->count)
55015 return -EINVAL;
55016 +
55017 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55018 + return 0;
55019 +
55020 dirent = buf->previous;
55021 if (dirent) {
55022 if (__put_user(offset, &dirent->d_off))
55023 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55024
55025 buf.current_dir = dirent;
55026 buf.previous = NULL;
55027 + buf.file = f.file;
55028 buf.count = count;
55029 buf.error = 0;
55030
55031 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55032 error = buf.error;
55033 lastdirent = buf.previous;
55034 if (lastdirent) {
55035 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
55036 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
55037 if (__put_user(d_off, &lastdirent->d_off))
55038 error = -EFAULT;
55039 else
55040 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
55041 index 2b7882b..1c5ef48 100644
55042 --- a/fs/reiserfs/do_balan.c
55043 +++ b/fs/reiserfs/do_balan.c
55044 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
55045 return;
55046 }
55047
55048 - atomic_inc(&(fs_generation(tb->tb_sb)));
55049 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
55050 do_balance_starts(tb);
55051
55052 /* balance leaf returns 0 except if combining L R and S into
55053 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
55054 index e60e870..f40ac16 100644
55055 --- a/fs/reiserfs/procfs.c
55056 +++ b/fs/reiserfs/procfs.c
55057 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
55058 "SMALL_TAILS " : "NO_TAILS ",
55059 replay_only(sb) ? "REPLAY_ONLY " : "",
55060 convert_reiserfs(sb) ? "CONV " : "",
55061 - atomic_read(&r->s_generation_counter),
55062 + atomic_read_unchecked(&r->s_generation_counter),
55063 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
55064 SF(s_do_balance), SF(s_unneeded_left_neighbor),
55065 SF(s_good_search_by_key_reada), SF(s_bmaps),
55066 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
55067 index 157e474..65a6114 100644
55068 --- a/fs/reiserfs/reiserfs.h
55069 +++ b/fs/reiserfs/reiserfs.h
55070 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
55071 /* Comment? -Hans */
55072 wait_queue_head_t s_wait;
55073 /* To be obsoleted soon by per buffer seals.. -Hans */
55074 - atomic_t s_generation_counter; // increased by one every time the
55075 + atomic_unchecked_t s_generation_counter; // increased by one every time the
55076 // tree gets re-balanced
55077 unsigned long s_properties; /* File system properties. Currently holds
55078 on-disk FS format */
55079 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
55080 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
55081
55082 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
55083 -#define get_generation(s) atomic_read (&fs_generation(s))
55084 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
55085 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
55086 #define __fs_changed(gen,s) (gen != get_generation (s))
55087 #define fs_changed(gen,s) \
55088 diff --git a/fs/select.c b/fs/select.c
55089 index 2ef72d9..f213b17 100644
55090 --- a/fs/select.c
55091 +++ b/fs/select.c
55092 @@ -20,6 +20,7 @@
55093 #include <linux/export.h>
55094 #include <linux/slab.h>
55095 #include <linux/poll.h>
55096 +#include <linux/security.h>
55097 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
55098 #include <linux/file.h>
55099 #include <linux/fdtable.h>
55100 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
55101 struct poll_list *walk = head;
55102 unsigned long todo = nfds;
55103
55104 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
55105 if (nfds > rlimit(RLIMIT_NOFILE))
55106 return -EINVAL;
55107
55108 diff --git a/fs/seq_file.c b/fs/seq_file.c
55109 index f2bc3df..239d4f6 100644
55110 --- a/fs/seq_file.c
55111 +++ b/fs/seq_file.c
55112 @@ -10,6 +10,7 @@
55113 #include <linux/seq_file.h>
55114 #include <linux/slab.h>
55115 #include <linux/cred.h>
55116 +#include <linux/sched.h>
55117
55118 #include <asm/uaccess.h>
55119 #include <asm/page.h>
55120 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
55121 #ifdef CONFIG_USER_NS
55122 p->user_ns = file->f_cred->user_ns;
55123 #endif
55124 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55125 + p->exec_id = current->exec_id;
55126 +#endif
55127
55128 /*
55129 * Wrappers around seq_open(e.g. swaps_open) need to be
55130 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55131 return 0;
55132 }
55133 if (!m->buf) {
55134 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55135 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55136 if (!m->buf)
55137 return -ENOMEM;
55138 }
55139 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55140 Eoverflow:
55141 m->op->stop(m, p);
55142 kfree(m->buf);
55143 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55144 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55145 return !m->buf ? -ENOMEM : -EAGAIN;
55146 }
55147
55148 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55149
55150 /* grab buffer if we didn't have one */
55151 if (!m->buf) {
55152 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55153 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55154 if (!m->buf)
55155 goto Enomem;
55156 }
55157 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55158 goto Fill;
55159 m->op->stop(m, p);
55160 kfree(m->buf);
55161 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55162 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55163 if (!m->buf)
55164 goto Enomem;
55165 m->count = 0;
55166 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
55167 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
55168 void *data)
55169 {
55170 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
55171 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
55172 int res = -ENOMEM;
55173
55174 if (op) {
55175 diff --git a/fs/splice.c b/fs/splice.c
55176 index 6909d89..5b2e8f9 100644
55177 --- a/fs/splice.c
55178 +++ b/fs/splice.c
55179 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55180 pipe_lock(pipe);
55181
55182 for (;;) {
55183 - if (!pipe->readers) {
55184 + if (!atomic_read(&pipe->readers)) {
55185 send_sig(SIGPIPE, current, 0);
55186 if (!ret)
55187 ret = -EPIPE;
55188 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55189 do_wakeup = 0;
55190 }
55191
55192 - pipe->waiting_writers++;
55193 + atomic_inc(&pipe->waiting_writers);
55194 pipe_wait(pipe);
55195 - pipe->waiting_writers--;
55196 + atomic_dec(&pipe->waiting_writers);
55197 }
55198
55199 pipe_unlock(pipe);
55200 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
55201 old_fs = get_fs();
55202 set_fs(get_ds());
55203 /* The cast to a user pointer is valid due to the set_fs() */
55204 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
55205 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
55206 set_fs(old_fs);
55207
55208 return res;
55209 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
55210 old_fs = get_fs();
55211 set_fs(get_ds());
55212 /* The cast to a user pointer is valid due to the set_fs() */
55213 - res = vfs_write(file, (const char __user *)buf, count, &pos);
55214 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
55215 set_fs(old_fs);
55216
55217 return res;
55218 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
55219 goto err;
55220
55221 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
55222 - vec[i].iov_base = (void __user *) page_address(page);
55223 + vec[i].iov_base = (void __force_user *) page_address(page);
55224 vec[i].iov_len = this_len;
55225 spd.pages[i] = page;
55226 spd.nr_pages++;
55227 @@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
55228 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
55229 {
55230 while (!pipe->nrbufs) {
55231 - if (!pipe->writers)
55232 + if (!atomic_read(&pipe->writers))
55233 return 0;
55234
55235 - if (!pipe->waiting_writers && sd->num_spliced)
55236 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
55237 return 0;
55238
55239 if (sd->flags & SPLICE_F_NONBLOCK)
55240 @@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
55241 * out of the pipe right after the splice_to_pipe(). So set
55242 * PIPE_READERS appropriately.
55243 */
55244 - pipe->readers = 1;
55245 + atomic_set(&pipe->readers, 1);
55246
55247 current->splice_pipe = pipe;
55248 }
55249 @@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55250 ret = -ERESTARTSYS;
55251 break;
55252 }
55253 - if (!pipe->writers)
55254 + if (!atomic_read(&pipe->writers))
55255 break;
55256 - if (!pipe->waiting_writers) {
55257 + if (!atomic_read(&pipe->waiting_writers)) {
55258 if (flags & SPLICE_F_NONBLOCK) {
55259 ret = -EAGAIN;
55260 break;
55261 @@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55262 pipe_lock(pipe);
55263
55264 while (pipe->nrbufs >= pipe->buffers) {
55265 - if (!pipe->readers) {
55266 + if (!atomic_read(&pipe->readers)) {
55267 send_sig(SIGPIPE, current, 0);
55268 ret = -EPIPE;
55269 break;
55270 @@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55271 ret = -ERESTARTSYS;
55272 break;
55273 }
55274 - pipe->waiting_writers++;
55275 + atomic_inc(&pipe->waiting_writers);
55276 pipe_wait(pipe);
55277 - pipe->waiting_writers--;
55278 + atomic_dec(&pipe->waiting_writers);
55279 }
55280
55281 pipe_unlock(pipe);
55282 @@ -1823,14 +1823,14 @@ retry:
55283 pipe_double_lock(ipipe, opipe);
55284
55285 do {
55286 - if (!opipe->readers) {
55287 + if (!atomic_read(&opipe->readers)) {
55288 send_sig(SIGPIPE, current, 0);
55289 if (!ret)
55290 ret = -EPIPE;
55291 break;
55292 }
55293
55294 - if (!ipipe->nrbufs && !ipipe->writers)
55295 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
55296 break;
55297
55298 /*
55299 @@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55300 pipe_double_lock(ipipe, opipe);
55301
55302 do {
55303 - if (!opipe->readers) {
55304 + if (!atomic_read(&opipe->readers)) {
55305 send_sig(SIGPIPE, current, 0);
55306 if (!ret)
55307 ret = -EPIPE;
55308 @@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55309 * return EAGAIN if we have the potential of some data in the
55310 * future, otherwise just return 0
55311 */
55312 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
55313 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
55314 ret = -EAGAIN;
55315
55316 pipe_unlock(ipipe);
55317 diff --git a/fs/stat.c b/fs/stat.c
55318 index 14f4545..9b7f55b 100644
55319 --- a/fs/stat.c
55320 +++ b/fs/stat.c
55321 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
55322 stat->gid = inode->i_gid;
55323 stat->rdev = inode->i_rdev;
55324 stat->size = i_size_read(inode);
55325 - stat->atime = inode->i_atime;
55326 - stat->mtime = inode->i_mtime;
55327 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55328 + stat->atime = inode->i_ctime;
55329 + stat->mtime = inode->i_ctime;
55330 + } else {
55331 + stat->atime = inode->i_atime;
55332 + stat->mtime = inode->i_mtime;
55333 + }
55334 stat->ctime = inode->i_ctime;
55335 stat->blksize = (1 << inode->i_blkbits);
55336 stat->blocks = inode->i_blocks;
55337 @@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55338 if (retval)
55339 return retval;
55340
55341 - if (inode->i_op->getattr)
55342 - return inode->i_op->getattr(mnt, dentry, stat);
55343 + if (inode->i_op->getattr) {
55344 + retval = inode->i_op->getattr(mnt, dentry, stat);
55345 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55346 + stat->atime = stat->ctime;
55347 + stat->mtime = stat->ctime;
55348 + }
55349 + return retval;
55350 + }
55351
55352 generic_fillattr(inode, stat);
55353 return 0;
55354 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
55355 index 2fbdff6..5530a61 100644
55356 --- a/fs/sysfs/dir.c
55357 +++ b/fs/sysfs/dir.c
55358 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
55359 struct sysfs_dirent *sd;
55360 int rc;
55361
55362 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55363 + const char *parent_name = parent_sd->s_name;
55364 +
55365 + mode = S_IFDIR | S_IRWXU;
55366 +
55367 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
55368 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
55369 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
55370 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
55371 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
55372 +#endif
55373 +
55374 /* allocate */
55375 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
55376 if (!sd)
55377 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
55378 index 602f56d..6853db8 100644
55379 --- a/fs/sysfs/file.c
55380 +++ b/fs/sysfs/file.c
55381 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
55382
55383 struct sysfs_open_dirent {
55384 atomic_t refcnt;
55385 - atomic_t event;
55386 + atomic_unchecked_t event;
55387 wait_queue_head_t poll;
55388 struct list_head buffers; /* goes through sysfs_buffer.list */
55389 };
55390 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
55391 if (!sysfs_get_active(attr_sd))
55392 return -ENODEV;
55393
55394 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
55395 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
55396 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
55397
55398 sysfs_put_active(attr_sd);
55399 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
55400 return -ENOMEM;
55401
55402 atomic_set(&new_od->refcnt, 0);
55403 - atomic_set(&new_od->event, 1);
55404 + atomic_set_unchecked(&new_od->event, 1);
55405 init_waitqueue_head(&new_od->poll);
55406 INIT_LIST_HEAD(&new_od->buffers);
55407 goto retry;
55408 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
55409
55410 sysfs_put_active(attr_sd);
55411
55412 - if (buffer->event != atomic_read(&od->event))
55413 + if (buffer->event != atomic_read_unchecked(&od->event))
55414 goto trigger;
55415
55416 return DEFAULT_POLLMASK;
55417 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
55418
55419 od = sd->s_attr.open;
55420 if (od) {
55421 - atomic_inc(&od->event);
55422 + atomic_inc_unchecked(&od->event);
55423 wake_up_interruptible(&od->poll);
55424 }
55425
55426 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
55427 index 3c9eb56..9dea5be 100644
55428 --- a/fs/sysfs/symlink.c
55429 +++ b/fs/sysfs/symlink.c
55430 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55431
55432 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
55433 {
55434 - char *page = nd_get_link(nd);
55435 + const char *page = nd_get_link(nd);
55436 if (!IS_ERR(page))
55437 free_page((unsigned long)page);
55438 }
55439 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
55440 index c175b4d..8f36a16 100644
55441 --- a/fs/udf/misc.c
55442 +++ b/fs/udf/misc.c
55443 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
55444
55445 u8 udf_tag_checksum(const struct tag *t)
55446 {
55447 - u8 *data = (u8 *)t;
55448 + const u8 *data = (const u8 *)t;
55449 u8 checksum = 0;
55450 int i;
55451 for (i = 0; i < sizeof(struct tag); ++i)
55452 diff --git a/fs/utimes.c b/fs/utimes.c
55453 index f4fb7ec..3fe03c0 100644
55454 --- a/fs/utimes.c
55455 +++ b/fs/utimes.c
55456 @@ -1,6 +1,7 @@
55457 #include <linux/compiler.h>
55458 #include <linux/file.h>
55459 #include <linux/fs.h>
55460 +#include <linux/security.h>
55461 #include <linux/linkage.h>
55462 #include <linux/mount.h>
55463 #include <linux/namei.h>
55464 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
55465 goto mnt_drop_write_and_out;
55466 }
55467 }
55468 +
55469 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
55470 + error = -EACCES;
55471 + goto mnt_drop_write_and_out;
55472 + }
55473 +
55474 mutex_lock(&inode->i_mutex);
55475 error = notify_change(path->dentry, &newattrs);
55476 mutex_unlock(&inode->i_mutex);
55477 diff --git a/fs/xattr.c b/fs/xattr.c
55478 index 3377dff..4feded6 100644
55479 --- a/fs/xattr.c
55480 +++ b/fs/xattr.c
55481 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
55482 * Extended attribute SET operations
55483 */
55484 static long
55485 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
55486 +setxattr(struct path *path, const char __user *name, const void __user *value,
55487 size_t size, int flags)
55488 {
55489 int error;
55490 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
55491 posix_acl_fix_xattr_from_user(kvalue, size);
55492 }
55493
55494 - error = vfs_setxattr(d, kname, kvalue, size, flags);
55495 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
55496 + error = -EACCES;
55497 + goto out;
55498 + }
55499 +
55500 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
55501 out:
55502 if (vvalue)
55503 vfree(vvalue);
55504 @@ -377,7 +382,7 @@ retry:
55505 return error;
55506 error = mnt_want_write(path.mnt);
55507 if (!error) {
55508 - error = setxattr(path.dentry, name, value, size, flags);
55509 + error = setxattr(&path, name, value, size, flags);
55510 mnt_drop_write(path.mnt);
55511 }
55512 path_put(&path);
55513 @@ -401,7 +406,7 @@ retry:
55514 return error;
55515 error = mnt_want_write(path.mnt);
55516 if (!error) {
55517 - error = setxattr(path.dentry, name, value, size, flags);
55518 + error = setxattr(&path, name, value, size, flags);
55519 mnt_drop_write(path.mnt);
55520 }
55521 path_put(&path);
55522 @@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
55523 const void __user *,value, size_t, size, int, flags)
55524 {
55525 struct fd f = fdget(fd);
55526 - struct dentry *dentry;
55527 int error = -EBADF;
55528
55529 if (!f.file)
55530 return error;
55531 - dentry = f.file->f_path.dentry;
55532 - audit_inode(NULL, dentry, 0);
55533 + audit_inode(NULL, f.file->f_path.dentry, 0);
55534 error = mnt_want_write_file(f.file);
55535 if (!error) {
55536 - error = setxattr(dentry, name, value, size, flags);
55537 + error = setxattr(&f.file->f_path, name, value, size, flags);
55538 mnt_drop_write_file(f.file);
55539 }
55540 fdput(f);
55541 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
55542 index 9fbea87..6b19972 100644
55543 --- a/fs/xattr_acl.c
55544 +++ b/fs/xattr_acl.c
55545 @@ -76,8 +76,8 @@ struct posix_acl *
55546 posix_acl_from_xattr(struct user_namespace *user_ns,
55547 const void *value, size_t size)
55548 {
55549 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
55550 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
55551 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
55552 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
55553 int count;
55554 struct posix_acl *acl;
55555 struct posix_acl_entry *acl_e;
55556 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
55557 index 572a858..12a9b0d 100644
55558 --- a/fs/xfs/xfs_bmap.c
55559 +++ b/fs/xfs/xfs_bmap.c
55560 @@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
55561 int nmap,
55562 int ret_nmap);
55563 #else
55564 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
55565 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
55566 #endif /* DEBUG */
55567
55568 STATIC int
55569 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
55570 index 1b9fc3e..e1bdde0 100644
55571 --- a/fs/xfs/xfs_dir2_sf.c
55572 +++ b/fs/xfs/xfs_dir2_sf.c
55573 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
55574 }
55575
55576 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
55577 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
55578 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
55579 + char name[sfep->namelen];
55580 + memcpy(name, sfep->name, sfep->namelen);
55581 + if (filldir(dirent, name, sfep->namelen,
55582 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
55583 + *offset = off & 0x7fffffff;
55584 + return 0;
55585 + }
55586 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
55587 off & 0x7fffffff, ino, DT_UNKNOWN)) {
55588 *offset = off & 0x7fffffff;
55589 return 0;
55590 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
55591 index c1c3ef8..0952438 100644
55592 --- a/fs/xfs/xfs_ioctl.c
55593 +++ b/fs/xfs/xfs_ioctl.c
55594 @@ -127,7 +127,7 @@ xfs_find_handle(
55595 }
55596
55597 error = -EFAULT;
55598 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
55599 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
55600 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
55601 goto out_put;
55602
55603 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
55604 index d82efaa..0904a8e 100644
55605 --- a/fs/xfs/xfs_iops.c
55606 +++ b/fs/xfs/xfs_iops.c
55607 @@ -395,7 +395,7 @@ xfs_vn_put_link(
55608 struct nameidata *nd,
55609 void *p)
55610 {
55611 - char *s = nd_get_link(nd);
55612 + const char *s = nd_get_link(nd);
55613
55614 if (!IS_ERR(s))
55615 kfree(s);
55616 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
55617 new file mode 100644
55618 index 0000000..92247e4
55619 --- /dev/null
55620 +++ b/grsecurity/Kconfig
55621 @@ -0,0 +1,1021 @@
55622 +#
55623 +# grecurity configuration
55624 +#
55625 +menu "Memory Protections"
55626 +depends on GRKERNSEC
55627 +
55628 +config GRKERNSEC_KMEM
55629 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
55630 + default y if GRKERNSEC_CONFIG_AUTO
55631 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
55632 + help
55633 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
55634 + be written to or read from to modify or leak the contents of the running
55635 + kernel. /dev/port will also not be allowed to be opened and support
55636 + for /dev/cpu/*/msr will be removed. If you have module
55637 + support disabled, enabling this will close up five ways that are
55638 + currently used to insert malicious code into the running kernel.
55639 +
55640 + Even with all these features enabled, we still highly recommend that
55641 + you use the RBAC system, as it is still possible for an attacker to
55642 + modify the running kernel through privileged I/O granted by ioperm/iopl.
55643 +
55644 + If you are not using XFree86, you may be able to stop this additional
55645 + case by enabling the 'Disable privileged I/O' option. Though nothing
55646 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
55647 + but only to video memory, which is the only writing we allow in this
55648 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
55649 + not be allowed to mprotect it with PROT_WRITE later.
55650 + Enabling this feature will prevent the "cpupower" and "powertop" tools
55651 + from working.
55652 +
55653 + It is highly recommended that you say Y here if you meet all the
55654 + conditions above.
55655 +
55656 +config GRKERNSEC_VM86
55657 + bool "Restrict VM86 mode"
55658 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
55659 + depends on X86_32
55660 +
55661 + help
55662 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
55663 + make use of a special execution mode on 32bit x86 processors called
55664 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
55665 + video cards and will still work with this option enabled. The purpose
55666 + of the option is to prevent exploitation of emulation errors in
55667 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
55668 + Nearly all users should be able to enable this option.
55669 +
55670 +config GRKERNSEC_IO
55671 + bool "Disable privileged I/O"
55672 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
55673 + depends on X86
55674 + select RTC_CLASS
55675 + select RTC_INTF_DEV
55676 + select RTC_DRV_CMOS
55677 +
55678 + help
55679 + If you say Y here, all ioperm and iopl calls will return an error.
55680 + Ioperm and iopl can be used to modify the running kernel.
55681 + Unfortunately, some programs need this access to operate properly,
55682 + the most notable of which are XFree86 and hwclock. hwclock can be
55683 + remedied by having RTC support in the kernel, so real-time
55684 + clock support is enabled if this option is enabled, to ensure
55685 + that hwclock operates correctly. XFree86 still will not
55686 + operate correctly with this option enabled, so DO NOT CHOOSE Y
55687 + IF YOU USE XFree86. If you use XFree86 and you still want to
55688 + protect your kernel against modification, use the RBAC system.
55689 +
55690 +config GRKERNSEC_JIT_HARDEN
55691 + bool "Harden BPF JIT against spray attacks"
55692 + default y if GRKERNSEC_CONFIG_AUTO
55693 + depends on BPF_JIT
55694 + help
55695 + If you say Y here, the native code generated by the kernel's Berkeley
55696 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
55697 + attacks that attempt to fit attacker-beneficial instructions in
55698 + 32bit immediate fields of JIT-generated native instructions. The
55699 + attacker will generally aim to cause an unintended instruction sequence
55700 + of JIT-generated native code to execute by jumping into the middle of
55701 + a generated instruction. This feature effectively randomizes the 32bit
55702 + immediate constants present in the generated code to thwart such attacks.
55703 +
55704 + If you're using KERNEXEC, it's recommended that you enable this option
55705 + to supplement the hardening of the kernel.
55706 +
55707 +config GRKERNSEC_RAND_THREADSTACK
55708 + bool "Insert random gaps between thread stacks"
55709 + default y if GRKERNSEC_CONFIG_AUTO
55710 + depends on PAX_RANDMMAP && !PPC
55711 + help
55712 + If you say Y here, a random-sized gap will be enforced between allocated
55713 + thread stacks. Glibc's NPTL and other threading libraries that
55714 + pass MAP_STACK to the kernel for thread stack allocation are supported.
55715 + The implementation currently provides 8 bits of entropy for the gap.
55716 +
55717 + Many distributions do not compile threaded remote services with the
55718 + -fstack-check argument to GCC, causing the variable-sized stack-based
55719 + allocator, alloca(), to not probe the stack on allocation. This
55720 + permits an unbounded alloca() to skip over any guard page and potentially
55721 + modify another thread's stack reliably. An enforced random gap
55722 + reduces the reliability of such an attack and increases the chance
55723 + that such a read/write to another thread's stack instead lands in
55724 + an unmapped area, causing a crash and triggering grsecurity's
55725 + anti-bruteforcing logic.
55726 +
55727 +config GRKERNSEC_PROC_MEMMAP
55728 + bool "Harden ASLR against information leaks and entropy reduction"
55729 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
55730 + depends on PAX_NOEXEC || PAX_ASLR
55731 + help
55732 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
55733 + give no information about the addresses of its mappings if
55734 + PaX features that rely on random addresses are enabled on the task.
55735 + In addition to sanitizing this information and disabling other
55736 + dangerous sources of information, this option causes reads of sensitive
55737 + /proc/<pid> entries where the file descriptor was opened in a different
55738 + task than the one performing the read. Such attempts are logged.
55739 + This option also limits argv/env strings for suid/sgid binaries
55740 + to 512KB to prevent a complete exhaustion of the stack entropy provided
55741 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
55742 + binaries to prevent alternative mmap layouts from being abused.
55743 +
55744 + If you use PaX it is essential that you say Y here as it closes up
55745 + several holes that make full ASLR useless locally.
55746 +
55747 +config GRKERNSEC_BRUTE
55748 + bool "Deter exploit bruteforcing"
55749 + default y if GRKERNSEC_CONFIG_AUTO
55750 + help
55751 + If you say Y here, attempts to bruteforce exploits against forking
55752 + daemons such as apache or sshd, as well as against suid/sgid binaries
55753 + will be deterred. When a child of a forking daemon is killed by PaX
55754 + or crashes due to an illegal instruction or other suspicious signal,
55755 + the parent process will be delayed 30 seconds upon every subsequent
55756 + fork until the administrator is able to assess the situation and
55757 + restart the daemon.
55758 + In the suid/sgid case, the attempt is logged, the user has all their
55759 + processes terminated, and they are prevented from executing any further
55760 + processes for 15 minutes.
55761 + It is recommended that you also enable signal logging in the auditing
55762 + section so that logs are generated when a process triggers a suspicious
55763 + signal.
55764 + If the sysctl option is enabled, a sysctl option with name
55765 + "deter_bruteforce" is created.
55766 +
55767 +
55768 +config GRKERNSEC_MODHARDEN
55769 + bool "Harden module auto-loading"
55770 + default y if GRKERNSEC_CONFIG_AUTO
55771 + depends on MODULES
55772 + help
55773 + If you say Y here, module auto-loading in response to use of some
55774 + feature implemented by an unloaded module will be restricted to
55775 + root users. Enabling this option helps defend against attacks
55776 + by unprivileged users who abuse the auto-loading behavior to
55777 + cause a vulnerable module to load that is then exploited.
55778 +
55779 + If this option prevents a legitimate use of auto-loading for a
55780 + non-root user, the administrator can execute modprobe manually
55781 + with the exact name of the module mentioned in the alert log.
55782 + Alternatively, the administrator can add the module to the list
55783 + of modules loaded at boot by modifying init scripts.
55784 +
55785 + Modification of init scripts will most likely be needed on
55786 + Ubuntu servers with encrypted home directory support enabled,
55787 + as the first non-root user logging in will cause the ecb(aes),
55788 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
55789 +
55790 +config GRKERNSEC_HIDESYM
55791 + bool "Hide kernel symbols"
55792 + default y if GRKERNSEC_CONFIG_AUTO
55793 + select PAX_USERCOPY_SLABS
55794 + help
55795 + If you say Y here, getting information on loaded modules, and
55796 + displaying all kernel symbols through a syscall will be restricted
55797 + to users with CAP_SYS_MODULE. For software compatibility reasons,
55798 + /proc/kallsyms will be restricted to the root user. The RBAC
55799 + system can hide that entry even from root.
55800 +
55801 + This option also prevents leaking of kernel addresses through
55802 + several /proc entries.
55803 +
55804 + Note that this option is only effective provided the following
55805 + conditions are met:
55806 + 1) The kernel using grsecurity is not precompiled by some distribution
55807 + 2) You have also enabled GRKERNSEC_DMESG
55808 + 3) You are using the RBAC system and hiding other files such as your
55809 + kernel image and System.map. Alternatively, enabling this option
55810 + causes the permissions on /boot, /lib/modules, and the kernel
55811 + source directory to change at compile time to prevent
55812 + reading by non-root users.
55813 + If the above conditions are met, this option will aid in providing a
55814 + useful protection against local kernel exploitation of overflows
55815 + and arbitrary read/write vulnerabilities.
55816 +
55817 +config GRKERNSEC_KERN_LOCKOUT
55818 + bool "Active kernel exploit response"
55819 + default y if GRKERNSEC_CONFIG_AUTO
55820 + depends on X86 || ARM || PPC || SPARC
55821 + help
55822 + If you say Y here, when a PaX alert is triggered due to suspicious
55823 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
55824 + or an OOPS occurs due to bad memory accesses, instead of just
55825 + terminating the offending process (and potentially allowing
55826 + a subsequent exploit from the same user), we will take one of two
55827 + actions:
55828 + If the user was root, we will panic the system
55829 + If the user was non-root, we will log the attempt, terminate
55830 + all processes owned by the user, then prevent them from creating
55831 + any new processes until the system is restarted
55832 + This deters repeated kernel exploitation/bruteforcing attempts
55833 + and is useful for later forensics.
55834 +
55835 +endmenu
55836 +menu "Role Based Access Control Options"
55837 +depends on GRKERNSEC
55838 +
55839 +config GRKERNSEC_RBAC_DEBUG
55840 + bool
55841 +
55842 +config GRKERNSEC_NO_RBAC
55843 + bool "Disable RBAC system"
55844 + help
55845 + If you say Y here, the /dev/grsec device will be removed from the kernel,
55846 + preventing the RBAC system from being enabled. You should only say Y
55847 + here if you have no intention of using the RBAC system, so as to prevent
55848 + an attacker with root access from misusing the RBAC system to hide files
55849 + and processes when loadable module support and /dev/[k]mem have been
55850 + locked down.
55851 +
55852 +config GRKERNSEC_ACL_HIDEKERN
55853 + bool "Hide kernel processes"
55854 + help
55855 + If you say Y here, all kernel threads will be hidden to all
55856 + processes but those whose subject has the "view hidden processes"
55857 + flag.
55858 +
55859 +config GRKERNSEC_ACL_MAXTRIES
55860 + int "Maximum tries before password lockout"
55861 + default 3
55862 + help
55863 + This option enforces the maximum number of times a user can attempt
55864 + to authorize themselves with the grsecurity RBAC system before being
55865 + denied the ability to attempt authorization again for a specified time.
55866 + The lower the number, the harder it will be to brute-force a password.
55867 +
55868 +config GRKERNSEC_ACL_TIMEOUT
55869 + int "Time to wait after max password tries, in seconds"
55870 + default 30
55871 + help
55872 + This option specifies the time the user must wait after attempting to
55873 + authorize to the RBAC system with the maximum number of invalid
55874 + passwords. The higher the number, the harder it will be to brute-force
55875 + a password.
55876 +
55877 +endmenu
55878 +menu "Filesystem Protections"
55879 +depends on GRKERNSEC
55880 +
55881 +config GRKERNSEC_PROC
55882 + bool "Proc restrictions"
55883 + default y if GRKERNSEC_CONFIG_AUTO
55884 + help
55885 + If you say Y here, the permissions of the /proc filesystem
55886 + will be altered to enhance system security and privacy. You MUST
55887 + choose either a user only restriction or a user and group restriction.
55888 + Depending upon the option you choose, you can either restrict users to
55889 + see only the processes they themselves run, or choose a group that can
55890 + view all processes and files normally restricted to root if you choose
55891 + the "restrict to user only" option. NOTE: If you're running identd or
55892 + ntpd as a non-root user, you will have to run it as the group you
55893 + specify here.
55894 +
55895 +config GRKERNSEC_PROC_USER
55896 + bool "Restrict /proc to user only"
55897 + depends on GRKERNSEC_PROC
55898 + help
55899 + If you say Y here, non-root users will only be able to view their own
55900 + processes, and restricts them from viewing network-related information,
55901 + and viewing kernel symbol and module information.
55902 +
55903 +config GRKERNSEC_PROC_USERGROUP
55904 + bool "Allow special group"
55905 + default y if GRKERNSEC_CONFIG_AUTO
55906 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
55907 + help
55908 + If you say Y here, you will be able to select a group that will be
55909 + able to view all processes and network-related information. If you've
55910 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
55911 + remain hidden. This option is useful if you want to run identd as
55912 + a non-root user. The group you select may also be chosen at boot time
55913 + via "grsec_proc_gid=" on the kernel commandline.
55914 +
55915 +config GRKERNSEC_PROC_GID
55916 + int "GID for special group"
55917 + depends on GRKERNSEC_PROC_USERGROUP
55918 + default 1001
55919 +
55920 +config GRKERNSEC_PROC_ADD
55921 + bool "Additional restrictions"
55922 + default y if GRKERNSEC_CONFIG_AUTO
55923 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
55924 + help
55925 + If you say Y here, additional restrictions will be placed on
55926 + /proc that keep normal users from viewing device information and
55927 + slabinfo information that could be useful for exploits.
55928 +
55929 +config GRKERNSEC_LINK
55930 + bool "Linking restrictions"
55931 + default y if GRKERNSEC_CONFIG_AUTO
55932 + help
55933 + If you say Y here, /tmp race exploits will be prevented, since users
55934 + will no longer be able to follow symlinks owned by other users in
55935 + world-writable +t directories (e.g. /tmp), unless the owner of the
55936 + symlink is the owner of the directory. users will also not be
55937 + able to hardlink to files they do not own. If the sysctl option is
55938 + enabled, a sysctl option with name "linking_restrictions" is created.
55939 +
55940 +config GRKERNSEC_SYMLINKOWN
55941 + bool "Kernel-enforced SymlinksIfOwnerMatch"
55942 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
55943 + help
55944 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
55945 + that prevents it from being used as a security feature. As Apache
55946 + verifies the symlink by performing a stat() against the target of
55947 + the symlink before it is followed, an attacker can setup a symlink
55948 + to point to a same-owned file, then replace the symlink with one
55949 + that targets another user's file just after Apache "validates" the
55950 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
55951 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
55952 + will be in place for the group you specify. If the sysctl option
55953 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
55954 + created.
55955 +
55956 +config GRKERNSEC_SYMLINKOWN_GID
55957 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
55958 + depends on GRKERNSEC_SYMLINKOWN
55959 + default 1006
55960 + help
55961 + Setting this GID determines what group kernel-enforced
55962 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
55963 + is enabled, a sysctl option with name "symlinkown_gid" is created.
55964 +
55965 +config GRKERNSEC_FIFO
55966 + bool "FIFO restrictions"
55967 + default y if GRKERNSEC_CONFIG_AUTO
55968 + help
55969 + If you say Y here, users will not be able to write to FIFOs they don't
55970 + own in world-writable +t directories (e.g. /tmp), unless the owner of
55971 + the FIFO is the same owner of the directory it's held in. If the sysctl
55972 + option is enabled, a sysctl option with name "fifo_restrictions" is
55973 + created.
55974 +
55975 +config GRKERNSEC_SYSFS_RESTRICT
55976 + bool "Sysfs/debugfs restriction"
55977 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
55978 + depends on SYSFS
55979 + help
55980 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
55981 + any filesystem normally mounted under it (e.g. debugfs) will be
55982 + mostly accessible only by root. These filesystems generally provide access
55983 + to hardware and debug information that isn't appropriate for unprivileged
55984 + users of the system. Sysfs and debugfs have also become a large source
55985 + of new vulnerabilities, ranging from infoleaks to local compromise.
55986 + There has been very little oversight with an eye toward security involved
55987 + in adding new exporters of information to these filesystems, so their
55988 + use is discouraged.
55989 + For reasons of compatibility, a few directories have been whitelisted
55990 + for access by non-root users:
55991 + /sys/fs/selinux
55992 + /sys/fs/fuse
55993 + /sys/devices/system/cpu
55994 +
55995 +config GRKERNSEC_ROFS
55996 + bool "Runtime read-only mount protection"
55997 + help
55998 + If you say Y here, a sysctl option with name "romount_protect" will
55999 + be created. By setting this option to 1 at runtime, filesystems
56000 + will be protected in the following ways:
56001 + * No new writable mounts will be allowed
56002 + * Existing read-only mounts won't be able to be remounted read/write
56003 + * Write operations will be denied on all block devices
56004 + This option acts independently of grsec_lock: once it is set to 1,
56005 + it cannot be turned off. Therefore, please be mindful of the resulting
56006 + behavior if this option is enabled in an init script on a read-only
56007 + filesystem. This feature is mainly intended for secure embedded systems.
56008 +
56009 +config GRKERNSEC_DEVICE_SIDECHANNEL
56010 + bool "Eliminate stat/notify-based device sidechannels"
56011 + default y if GRKERNSEC_CONFIG_AUTO
56012 + help
56013 + If you say Y here, timing analyses on block or character
56014 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
56015 + will be thwarted for unprivileged users. If a process without
56016 + CAP_MKNOD stats such a device, the last access and last modify times
56017 + will match the device's create time. No access or modify events
56018 + will be triggered through inotify/dnotify/fanotify for such devices.
56019 + This feature will prevent attacks that may at a minimum
56020 + allow an attacker to determine the administrator's password length.
56021 +
56022 +config GRKERNSEC_CHROOT
56023 + bool "Chroot jail restrictions"
56024 + default y if GRKERNSEC_CONFIG_AUTO
56025 + help
56026 + If you say Y here, you will be able to choose several options that will
56027 + make breaking out of a chrooted jail much more difficult. If you
56028 + encounter no software incompatibilities with the following options, it
56029 + is recommended that you enable each one.
56030 +
56031 +config GRKERNSEC_CHROOT_MOUNT
56032 + bool "Deny mounts"
56033 + default y if GRKERNSEC_CONFIG_AUTO
56034 + depends on GRKERNSEC_CHROOT
56035 + help
56036 + If you say Y here, processes inside a chroot will not be able to
56037 + mount or remount filesystems. If the sysctl option is enabled, a
56038 + sysctl option with name "chroot_deny_mount" is created.
56039 +
56040 +config GRKERNSEC_CHROOT_DOUBLE
56041 + bool "Deny double-chroots"
56042 + default y if GRKERNSEC_CONFIG_AUTO
56043 + depends on GRKERNSEC_CHROOT
56044 + help
56045 + If you say Y here, processes inside a chroot will not be able to chroot
56046 + again outside the chroot. This is a widely used method of breaking
56047 + out of a chroot jail and should not be allowed. If the sysctl
56048 + option is enabled, a sysctl option with name
56049 + "chroot_deny_chroot" is created.
56050 +
56051 +config GRKERNSEC_CHROOT_PIVOT
56052 + bool "Deny pivot_root in chroot"
56053 + default y if GRKERNSEC_CONFIG_AUTO
56054 + depends on GRKERNSEC_CHROOT
56055 + help
56056 + If you say Y here, processes inside a chroot will not be able to use
56057 + a function called pivot_root() that was introduced in Linux 2.3.41. It
56058 + works similar to chroot in that it changes the root filesystem. This
56059 + function could be misused in a chrooted process to attempt to break out
56060 + of the chroot, and therefore should not be allowed. If the sysctl
56061 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
56062 + created.
56063 +
56064 +config GRKERNSEC_CHROOT_CHDIR
56065 + bool "Enforce chdir(\"/\") on all chroots"
56066 + default y if GRKERNSEC_CONFIG_AUTO
56067 + depends on GRKERNSEC_CHROOT
56068 + help
56069 + If you say Y here, the current working directory of all newly-chrooted
56070 + applications will be set to the the root directory of the chroot.
56071 + The man page on chroot(2) states:
56072 + Note that this call does not change the current working
56073 + directory, so that `.' can be outside the tree rooted at
56074 + `/'. In particular, the super-user can escape from a
56075 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
56076 +
56077 + It is recommended that you say Y here, since it's not known to break
56078 + any software. If the sysctl option is enabled, a sysctl option with
56079 + name "chroot_enforce_chdir" is created.
56080 +
56081 +config GRKERNSEC_CHROOT_CHMOD
56082 + bool "Deny (f)chmod +s"
56083 + default y if GRKERNSEC_CONFIG_AUTO
56084 + depends on GRKERNSEC_CHROOT
56085 + help
56086 + If you say Y here, processes inside a chroot will not be able to chmod
56087 + or fchmod files to make them have suid or sgid bits. This protects
56088 + against another published method of breaking a chroot. If the sysctl
56089 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
56090 + created.
56091 +
56092 +config GRKERNSEC_CHROOT_FCHDIR
56093 + bool "Deny fchdir out of chroot"
56094 + default y if GRKERNSEC_CONFIG_AUTO
56095 + depends on GRKERNSEC_CHROOT
56096 + help
56097 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
56098 + to a file descriptor of the chrooting process that points to a directory
56099 + outside the filesystem will be stopped. If the sysctl option
56100 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
56101 +
56102 +config GRKERNSEC_CHROOT_MKNOD
56103 + bool "Deny mknod"
56104 + default y if GRKERNSEC_CONFIG_AUTO
56105 + depends on GRKERNSEC_CHROOT
56106 + help
56107 + If you say Y here, processes inside a chroot will not be allowed to
56108 + mknod. The problem with using mknod inside a chroot is that it
56109 + would allow an attacker to create a device entry that is the same
56110 + as one on the physical root of your system, which could range from
56111 + anything from the console device to a device for your harddrive (which
56112 + they could then use to wipe the drive or steal data). It is recommended
56113 + that you say Y here, unless you run into software incompatibilities.
56114 + If the sysctl option is enabled, a sysctl option with name
56115 + "chroot_deny_mknod" is created.
56116 +
56117 +config GRKERNSEC_CHROOT_SHMAT
56118 + bool "Deny shmat() out of chroot"
56119 + default y if GRKERNSEC_CONFIG_AUTO
56120 + depends on GRKERNSEC_CHROOT
56121 + help
56122 + If you say Y here, processes inside a chroot will not be able to attach
56123 + to shared memory segments that were created outside of the chroot jail.
56124 + It is recommended that you say Y here. If the sysctl option is enabled,
56125 + a sysctl option with name "chroot_deny_shmat" is created.
56126 +
56127 +config GRKERNSEC_CHROOT_UNIX
56128 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
56129 + default y if GRKERNSEC_CONFIG_AUTO
56130 + depends on GRKERNSEC_CHROOT
56131 + help
56132 + If you say Y here, processes inside a chroot will not be able to
56133 + connect to abstract (meaning not belonging to a filesystem) Unix
56134 + domain sockets that were bound outside of a chroot. It is recommended
56135 + that you say Y here. If the sysctl option is enabled, a sysctl option
56136 + with name "chroot_deny_unix" is created.
56137 +
56138 +config GRKERNSEC_CHROOT_FINDTASK
56139 + bool "Protect outside processes"
56140 + default y if GRKERNSEC_CONFIG_AUTO
56141 + depends on GRKERNSEC_CHROOT
56142 + help
56143 + If you say Y here, processes inside a chroot will not be able to
56144 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
56145 + getsid, or view any process outside of the chroot. If the sysctl
56146 + option is enabled, a sysctl option with name "chroot_findtask" is
56147 + created.
56148 +
56149 +config GRKERNSEC_CHROOT_NICE
56150 + bool "Restrict priority changes"
56151 + default y if GRKERNSEC_CONFIG_AUTO
56152 + depends on GRKERNSEC_CHROOT
56153 + help
56154 + If you say Y here, processes inside a chroot will not be able to raise
56155 + the priority of processes in the chroot, or alter the priority of
56156 + processes outside the chroot. This provides more security than simply
56157 + removing CAP_SYS_NICE from the process' capability set. If the
56158 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
56159 + is created.
56160 +
56161 +config GRKERNSEC_CHROOT_SYSCTL
56162 + bool "Deny sysctl writes"
56163 + default y if GRKERNSEC_CONFIG_AUTO
56164 + depends on GRKERNSEC_CHROOT
56165 + help
56166 + If you say Y here, an attacker in a chroot will not be able to
56167 + write to sysctl entries, either by sysctl(2) or through a /proc
56168 + interface. It is strongly recommended that you say Y here. If the
56169 + sysctl option is enabled, a sysctl option with name
56170 + "chroot_deny_sysctl" is created.
56171 +
56172 +config GRKERNSEC_CHROOT_CAPS
56173 + bool "Capability restrictions"
56174 + default y if GRKERNSEC_CONFIG_AUTO
56175 + depends on GRKERNSEC_CHROOT
56176 + help
56177 + If you say Y here, the capabilities on all processes within a
56178 + chroot jail will be lowered to stop module insertion, raw i/o,
56179 + system and net admin tasks, rebooting the system, modifying immutable
56180 + files, modifying IPC owned by another, and changing the system time.
56181 + This is left an option because it can break some apps. Disable this
56182 + if your chrooted apps are having problems performing those kinds of
56183 + tasks. If the sysctl option is enabled, a sysctl option with
56184 + name "chroot_caps" is created.
56185 +
56186 +endmenu
56187 +menu "Kernel Auditing"
56188 +depends on GRKERNSEC
56189 +
56190 +config GRKERNSEC_AUDIT_GROUP
56191 + bool "Single group for auditing"
56192 + help
56193 + If you say Y here, the exec and chdir logging features will only operate
56194 + on a group you specify. This option is recommended if you only want to
56195 + watch certain users instead of having a large amount of logs from the
56196 + entire system. If the sysctl option is enabled, a sysctl option with
56197 + name "audit_group" is created.
56198 +
56199 +config GRKERNSEC_AUDIT_GID
56200 + int "GID for auditing"
56201 + depends on GRKERNSEC_AUDIT_GROUP
56202 + default 1007
56203 +
56204 +config GRKERNSEC_EXECLOG
56205 + bool "Exec logging"
56206 + help
56207 + If you say Y here, all execve() calls will be logged (since the
56208 + other exec*() calls are frontends to execve(), all execution
56209 + will be logged). Useful for shell-servers that like to keep track
56210 + of their users. If the sysctl option is enabled, a sysctl option with
56211 + name "exec_logging" is created.
56212 + WARNING: This option when enabled will produce a LOT of logs, especially
56213 + on an active system.
56214 +
56215 +config GRKERNSEC_RESLOG
56216 + bool "Resource logging"
56217 + default y if GRKERNSEC_CONFIG_AUTO
56218 + help
56219 + If you say Y here, all attempts to overstep resource limits will
56220 + be logged with the resource name, the requested size, and the current
56221 + limit. It is highly recommended that you say Y here. If the sysctl
56222 + option is enabled, a sysctl option with name "resource_logging" is
56223 + created. If the RBAC system is enabled, the sysctl value is ignored.
56224 +
56225 +config GRKERNSEC_CHROOT_EXECLOG
56226 + bool "Log execs within chroot"
56227 + help
56228 + If you say Y here, all executions inside a chroot jail will be logged
56229 + to syslog. This can cause a large amount of logs if certain
56230 + applications (eg. djb's daemontools) are installed on the system, and
56231 + is therefore left as an option. If the sysctl option is enabled, a
56232 + sysctl option with name "chroot_execlog" is created.
56233 +
56234 +config GRKERNSEC_AUDIT_PTRACE
56235 + bool "Ptrace logging"
56236 + help
56237 + If you say Y here, all attempts to attach to a process via ptrace
56238 + will be logged. If the sysctl option is enabled, a sysctl option
56239 + with name "audit_ptrace" is created.
56240 +
56241 +config GRKERNSEC_AUDIT_CHDIR
56242 + bool "Chdir logging"
56243 + help
56244 + If you say Y here, all chdir() calls will be logged. If the sysctl
56245 + option is enabled, a sysctl option with name "audit_chdir" is created.
56246 +
56247 +config GRKERNSEC_AUDIT_MOUNT
56248 + bool "(Un)Mount logging"
56249 + help
56250 + If you say Y here, all mounts and unmounts will be logged. If the
56251 + sysctl option is enabled, a sysctl option with name "audit_mount" is
56252 + created.
56253 +
56254 +config GRKERNSEC_SIGNAL
56255 + bool "Signal logging"
56256 + default y if GRKERNSEC_CONFIG_AUTO
56257 + help
56258 + If you say Y here, certain important signals will be logged, such as
56259 + SIGSEGV, which will as a result inform you of when a error in a program
56260 + occurred, which in some cases could mean a possible exploit attempt.
56261 + If the sysctl option is enabled, a sysctl option with name
56262 + "signal_logging" is created.
56263 +
56264 +config GRKERNSEC_FORKFAIL
56265 + bool "Fork failure logging"
56266 + help
56267 + If you say Y here, all failed fork() attempts will be logged.
56268 + This could suggest a fork bomb, or someone attempting to overstep
56269 + their process limit. If the sysctl option is enabled, a sysctl option
56270 + with name "forkfail_logging" is created.
56271 +
56272 +config GRKERNSEC_TIME
56273 + bool "Time change logging"
56274 + default y if GRKERNSEC_CONFIG_AUTO
56275 + help
56276 + If you say Y here, any changes of the system clock will be logged.
56277 + If the sysctl option is enabled, a sysctl option with name
56278 + "timechange_logging" is created.
56279 +
56280 +config GRKERNSEC_PROC_IPADDR
56281 + bool "/proc/<pid>/ipaddr support"
56282 + default y if GRKERNSEC_CONFIG_AUTO
56283 + help
56284 + If you say Y here, a new entry will be added to each /proc/<pid>
56285 + directory that contains the IP address of the person using the task.
56286 + The IP is carried across local TCP and AF_UNIX stream sockets.
56287 + This information can be useful for IDS/IPSes to perform remote response
56288 + to a local attack. The entry is readable by only the owner of the
56289 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
56290 + the RBAC system), and thus does not create privacy concerns.
56291 +
56292 +config GRKERNSEC_RWXMAP_LOG
56293 + bool 'Denied RWX mmap/mprotect logging'
56294 + default y if GRKERNSEC_CONFIG_AUTO
56295 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
56296 + help
56297 + If you say Y here, calls to mmap() and mprotect() with explicit
56298 + usage of PROT_WRITE and PROT_EXEC together will be logged when
56299 + denied by the PAX_MPROTECT feature. If the sysctl option is
56300 + enabled, a sysctl option with name "rwxmap_logging" is created.
56301 +
56302 +config GRKERNSEC_AUDIT_TEXTREL
56303 + bool 'ELF text relocations logging (READ HELP)'
56304 + depends on PAX_MPROTECT
56305 + help
56306 + If you say Y here, text relocations will be logged with the filename
56307 + of the offending library or binary. The purpose of the feature is
56308 + to help Linux distribution developers get rid of libraries and
56309 + binaries that need text relocations which hinder the future progress
56310 + of PaX. Only Linux distribution developers should say Y here, and
56311 + never on a production machine, as this option creates an information
56312 + leak that could aid an attacker in defeating the randomization of
56313 + a single memory region. If the sysctl option is enabled, a sysctl
56314 + option with name "audit_textrel" is created.
56315 +
56316 +endmenu
56317 +
56318 +menu "Executable Protections"
56319 +depends on GRKERNSEC
56320 +
56321 +config GRKERNSEC_DMESG
56322 + bool "Dmesg(8) restriction"
56323 + default y if GRKERNSEC_CONFIG_AUTO
56324 + help
56325 + If you say Y here, non-root users will not be able to use dmesg(8)
56326 + to view the contents of the kernel's circular log buffer.
56327 + The kernel's log buffer often contains kernel addresses and other
56328 + identifying information useful to an attacker in fingerprinting a
56329 + system for a targeted exploit.
56330 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
56331 + created.
56332 +
56333 +config GRKERNSEC_HARDEN_PTRACE
56334 + bool "Deter ptrace-based process snooping"
56335 + default y if GRKERNSEC_CONFIG_AUTO
56336 + help
56337 + If you say Y here, TTY sniffers and other malicious monitoring
56338 + programs implemented through ptrace will be defeated. If you
56339 + have been using the RBAC system, this option has already been
56340 + enabled for several years for all users, with the ability to make
56341 + fine-grained exceptions.
56342 +
56343 + This option only affects the ability of non-root users to ptrace
56344 + processes that are not a descendent of the ptracing process.
56345 + This means that strace ./binary and gdb ./binary will still work,
56346 + but attaching to arbitrary processes will not. If the sysctl
56347 + option is enabled, a sysctl option with name "harden_ptrace" is
56348 + created.
56349 +
56350 +config GRKERNSEC_PTRACE_READEXEC
56351 + bool "Require read access to ptrace sensitive binaries"
56352 + default y if GRKERNSEC_CONFIG_AUTO
56353 + help
56354 + If you say Y here, unprivileged users will not be able to ptrace unreadable
56355 + binaries. This option is useful in environments that
56356 + remove the read bits (e.g. file mode 4711) from suid binaries to
56357 + prevent infoleaking of their contents. This option adds
56358 + consistency to the use of that file mode, as the binary could normally
56359 + be read out when run without privileges while ptracing.
56360 +
56361 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
56362 + is created.
56363 +
56364 +config GRKERNSEC_SETXID
56365 + bool "Enforce consistent multithreaded privileges"
56366 + default y if GRKERNSEC_CONFIG_AUTO
56367 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
56368 + help
56369 + If you say Y here, a change from a root uid to a non-root uid
56370 + in a multithreaded application will cause the resulting uids,
56371 + gids, supplementary groups, and capabilities in that thread
56372 + to be propagated to the other threads of the process. In most
56373 + cases this is unnecessary, as glibc will emulate this behavior
56374 + on behalf of the application. Other libcs do not act in the
56375 + same way, allowing the other threads of the process to continue
56376 + running with root privileges. If the sysctl option is enabled,
56377 + a sysctl option with name "consistent_setxid" is created.
56378 +
56379 +config GRKERNSEC_TPE
56380 + bool "Trusted Path Execution (TPE)"
56381 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56382 + help
56383 + If you say Y here, you will be able to choose a gid to add to the
56384 + supplementary groups of users you want to mark as "untrusted."
56385 + These users will not be able to execute any files that are not in
56386 + root-owned directories writable only by root. If the sysctl option
56387 + is enabled, a sysctl option with name "tpe" is created.
56388 +
56389 +config GRKERNSEC_TPE_ALL
56390 + bool "Partially restrict all non-root users"
56391 + depends on GRKERNSEC_TPE
56392 + help
56393 + If you say Y here, all non-root users will be covered under
56394 + a weaker TPE restriction. This is separate from, and in addition to,
56395 + the main TPE options that you have selected elsewhere. Thus, if a
56396 + "trusted" GID is chosen, this restriction applies to even that GID.
56397 + Under this restriction, all non-root users will only be allowed to
56398 + execute files in directories they own that are not group or
56399 + world-writable, or in directories owned by root and writable only by
56400 + root. If the sysctl option is enabled, a sysctl option with name
56401 + "tpe_restrict_all" is created.
56402 +
56403 +config GRKERNSEC_TPE_INVERT
56404 + bool "Invert GID option"
56405 + depends on GRKERNSEC_TPE
56406 + help
56407 + If you say Y here, the group you specify in the TPE configuration will
56408 + decide what group TPE restrictions will be *disabled* for. This
56409 + option is useful if you want TPE restrictions to be applied to most
56410 + users on the system. If the sysctl option is enabled, a sysctl option
56411 + with name "tpe_invert" is created. Unlike other sysctl options, this
56412 + entry will default to on for backward-compatibility.
56413 +
56414 +config GRKERNSEC_TPE_GID
56415 + int
56416 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
56417 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
56418 +
56419 +config GRKERNSEC_TPE_UNTRUSTED_GID
56420 + int "GID for TPE-untrusted users"
56421 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
56422 + default 1005
56423 + help
56424 + Setting this GID determines what group TPE restrictions will be
56425 + *enabled* for. If the sysctl option is enabled, a sysctl option
56426 + with name "tpe_gid" is created.
56427 +
56428 +config GRKERNSEC_TPE_TRUSTED_GID
56429 + int "GID for TPE-trusted users"
56430 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
56431 + default 1005
56432 + help
56433 + Setting this GID determines what group TPE restrictions will be
56434 + *disabled* for. If the sysctl option is enabled, a sysctl option
56435 + with name "tpe_gid" is created.
56436 +
56437 +endmenu
56438 +menu "Network Protections"
56439 +depends on GRKERNSEC
56440 +
56441 +config GRKERNSEC_RANDNET
56442 + bool "Larger entropy pools"
56443 + default y if GRKERNSEC_CONFIG_AUTO
56444 + help
56445 + If you say Y here, the entropy pools used for many features of Linux
56446 + and grsecurity will be doubled in size. Since several grsecurity
56447 + features use additional randomness, it is recommended that you say Y
56448 + here. Saying Y here has a similar effect as modifying
56449 + /proc/sys/kernel/random/poolsize.
56450 +
56451 +config GRKERNSEC_BLACKHOLE
56452 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
56453 + default y if GRKERNSEC_CONFIG_AUTO
56454 + depends on NET
56455 + help
56456 + If you say Y here, neither TCP resets nor ICMP
56457 + destination-unreachable packets will be sent in response to packets
56458 + sent to ports for which no associated listening process exists.
56459 + This feature supports both IPV4 and IPV6 and exempts the
56460 + loopback interface from blackholing. Enabling this feature
56461 + makes a host more resilient to DoS attacks and reduces network
56462 + visibility against scanners.
56463 +
56464 + The blackhole feature as-implemented is equivalent to the FreeBSD
56465 + blackhole feature, as it prevents RST responses to all packets, not
56466 + just SYNs. Under most application behavior this causes no
56467 + problems, but applications (like haproxy) may not close certain
56468 + connections in a way that cleanly terminates them on the remote
56469 + end, leaving the remote host in LAST_ACK state. Because of this
56470 + side-effect and to prevent intentional LAST_ACK DoSes, this
56471 + feature also adds automatic mitigation against such attacks.
56472 + The mitigation drastically reduces the amount of time a socket
56473 + can spend in LAST_ACK state. If you're using haproxy and not
56474 + all servers it connects to have this option enabled, consider
56475 + disabling this feature on the haproxy host.
56476 +
56477 + If the sysctl option is enabled, two sysctl options with names
56478 + "ip_blackhole" and "lastack_retries" will be created.
56479 + While "ip_blackhole" takes the standard zero/non-zero on/off
56480 + toggle, "lastack_retries" uses the same kinds of values as
56481 + "tcp_retries1" and "tcp_retries2". The default value of 4
56482 + prevents a socket from lasting more than 45 seconds in LAST_ACK
56483 + state.
56484 +
56485 +config GRKERNSEC_NO_SIMULT_CONNECT
56486 + bool "Disable TCP Simultaneous Connect"
56487 + default y if GRKERNSEC_CONFIG_AUTO
56488 + depends on NET
56489 + help
56490 + If you say Y here, a feature by Willy Tarreau will be enabled that
56491 + removes a weakness in Linux's strict implementation of TCP that
56492 + allows two clients to connect to each other without either entering
56493 + a listening state. The weakness allows an attacker to easily prevent
56494 + a client from connecting to a known server provided the source port
56495 + for the connection is guessed correctly.
56496 +
56497 + As the weakness could be used to prevent an antivirus or IPS from
56498 + fetching updates, or prevent an SSL gateway from fetching a CRL,
56499 + it should be eliminated by enabling this option. Though Linux is
56500 + one of few operating systems supporting simultaneous connect, it
56501 + has no legitimate use in practice and is rarely supported by firewalls.
56502 +
56503 +config GRKERNSEC_SOCKET
56504 + bool "Socket restrictions"
56505 + depends on NET
56506 + help
56507 + If you say Y here, you will be able to choose from several options.
56508 + If you assign a GID on your system and add it to the supplementary
56509 + groups of users you want to restrict socket access to, this patch
56510 + will perform up to three things, based on the option(s) you choose.
56511 +
56512 +config GRKERNSEC_SOCKET_ALL
56513 + bool "Deny any sockets to group"
56514 + depends on GRKERNSEC_SOCKET
56515 + help
56516 + If you say Y here, you will be able to choose a GID of whose users will
56517 + be unable to connect to other hosts from your machine or run server
56518 + applications from your machine. If the sysctl option is enabled, a
56519 + sysctl option with name "socket_all" is created.
56520 +
56521 +config GRKERNSEC_SOCKET_ALL_GID
56522 + int "GID to deny all sockets for"
56523 + depends on GRKERNSEC_SOCKET_ALL
56524 + default 1004
56525 + help
56526 + Here you can choose the GID to disable socket access for. Remember to
56527 + add the users you want socket access disabled for to the GID
56528 + specified here. If the sysctl option is enabled, a sysctl option
56529 + with name "socket_all_gid" is created.
56530 +
56531 +config GRKERNSEC_SOCKET_CLIENT
56532 + bool "Deny client sockets to group"
56533 + depends on GRKERNSEC_SOCKET
56534 + help
56535 + If you say Y here, you will be able to choose a GID of whose users will
56536 + be unable to connect to other hosts from your machine, but will be
56537 + able to run servers. If this option is enabled, all users in the group
56538 + you specify will have to use passive mode when initiating ftp transfers
56539 + from the shell on your machine. If the sysctl option is enabled, a
56540 + sysctl option with name "socket_client" is created.
56541 +
56542 +config GRKERNSEC_SOCKET_CLIENT_GID
56543 + int "GID to deny client sockets for"
56544 + depends on GRKERNSEC_SOCKET_CLIENT
56545 + default 1003
56546 + help
56547 + Here you can choose the GID to disable client socket access for.
56548 + Remember to add the users you want client socket access disabled for to
56549 + the GID specified here. If the sysctl option is enabled, a sysctl
56550 + option with name "socket_client_gid" is created.
56551 +
56552 +config GRKERNSEC_SOCKET_SERVER
56553 + bool "Deny server sockets to group"
56554 + depends on GRKERNSEC_SOCKET
56555 + help
56556 + If you say Y here, you will be able to choose a GID of whose users will
56557 + be unable to run server applications from your machine. If the sysctl
56558 + option is enabled, a sysctl option with name "socket_server" is created.
56559 +
56560 +config GRKERNSEC_SOCKET_SERVER_GID
56561 + int "GID to deny server sockets for"
56562 + depends on GRKERNSEC_SOCKET_SERVER
56563 + default 1002
56564 + help
56565 + Here you can choose the GID to disable server socket access for.
56566 + Remember to add the users you want server socket access disabled for to
56567 + the GID specified here. If the sysctl option is enabled, a sysctl
56568 + option with name "socket_server_gid" is created.
56569 +
56570 +endmenu
56571 +menu "Sysctl Support"
56572 +depends on GRKERNSEC && SYSCTL
56573 +
56574 +config GRKERNSEC_SYSCTL
56575 + bool "Sysctl support"
56576 + default y if GRKERNSEC_CONFIG_AUTO
56577 + help
56578 + If you say Y here, you will be able to change the options that
56579 + grsecurity runs with at bootup, without having to recompile your
56580 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
56581 + to enable (1) or disable (0) various features. All the sysctl entries
56582 + are mutable until the "grsec_lock" entry is set to a non-zero value.
56583 + All features enabled in the kernel configuration are disabled at boot
56584 + if you do not say Y to the "Turn on features by default" option.
56585 + All options should be set at startup, and the grsec_lock entry should
56586 + be set to a non-zero value after all the options are set.
56587 + *THIS IS EXTREMELY IMPORTANT*
56588 +
56589 +config GRKERNSEC_SYSCTL_DISTRO
56590 + bool "Extra sysctl support for distro makers (READ HELP)"
56591 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
56592 + help
56593 + If you say Y here, additional sysctl options will be created
56594 + for features that affect processes running as root. Therefore,
56595 + it is critical when using this option that the grsec_lock entry be
56596 + enabled after boot. Only distros with prebuilt kernel packages
56597 + with this option enabled that can ensure grsec_lock is enabled
56598 + after boot should use this option.
56599 + *Failure to set grsec_lock after boot makes all grsec features
56600 + this option covers useless*
56601 +
56602 + Currently this option creates the following sysctl entries:
56603 + "Disable Privileged I/O": "disable_priv_io"
56604 +
56605 +config GRKERNSEC_SYSCTL_ON
56606 + bool "Turn on features by default"
56607 + default y if GRKERNSEC_CONFIG_AUTO
56608 + depends on GRKERNSEC_SYSCTL
56609 + help
56610 + If you say Y here, instead of having all features enabled in the
56611 + kernel configuration disabled at boot time, the features will be
56612 + enabled at boot time. It is recommended you say Y here unless
56613 + there is some reason you would want all sysctl-tunable features to
56614 + be disabled by default. As mentioned elsewhere, it is important
56615 + to enable the grsec_lock entry once you have finished modifying
56616 + the sysctl entries.
56617 +
56618 +endmenu
56619 +menu "Logging Options"
56620 +depends on GRKERNSEC
56621 +
56622 +config GRKERNSEC_FLOODTIME
56623 + int "Seconds in between log messages (minimum)"
56624 + default 10
56625 + help
56626 + This option allows you to enforce the number of seconds between
56627 + grsecurity log messages. The default should be suitable for most
56628 + people, however, if you choose to change it, choose a value small enough
56629 + to allow informative logs to be produced, but large enough to
56630 + prevent flooding.
56631 +
56632 +config GRKERNSEC_FLOODBURST
56633 + int "Number of messages in a burst (maximum)"
56634 + default 6
56635 + help
56636 + This option allows you to choose the maximum number of messages allowed
56637 + within the flood time interval you chose in a separate option. The
56638 + default should be suitable for most people, however if you find that
56639 + many of your logs are being interpreted as flooding, you may want to
56640 + raise this value.
56641 +
56642 +endmenu
56643 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
56644 new file mode 100644
56645 index 0000000..1b9afa9
56646 --- /dev/null
56647 +++ b/grsecurity/Makefile
56648 @@ -0,0 +1,38 @@
56649 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
56650 +# during 2001-2009 it has been completely redesigned by Brad Spengler
56651 +# into an RBAC system
56652 +#
56653 +# All code in this directory and various hooks inserted throughout the kernel
56654 +# are copyright Brad Spengler - Open Source Security, Inc., and released
56655 +# under the GPL v2 or higher
56656 +
56657 +KBUILD_CFLAGS += -Werror
56658 +
56659 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
56660 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
56661 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
56662 +
56663 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
56664 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
56665 + gracl_learn.o grsec_log.o
56666 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
56667 +
56668 +ifdef CONFIG_NET
56669 +obj-y += grsec_sock.o
56670 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
56671 +endif
56672 +
56673 +ifndef CONFIG_GRKERNSEC
56674 +obj-y += grsec_disabled.o
56675 +endif
56676 +
56677 +ifdef CONFIG_GRKERNSEC_HIDESYM
56678 +extra-y := grsec_hidesym.o
56679 +$(obj)/grsec_hidesym.o:
56680 + @-chmod -f 500 /boot
56681 + @-chmod -f 500 /lib/modules
56682 + @-chmod -f 500 /lib64/modules
56683 + @-chmod -f 500 /lib32/modules
56684 + @-chmod -f 700 .
56685 + @echo ' grsec: protected kernel image paths'
56686 +endif
56687 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
56688 new file mode 100644
56689 index 0000000..0767b2e
56690 --- /dev/null
56691 +++ b/grsecurity/gracl.c
56692 @@ -0,0 +1,4067 @@
56693 +#include <linux/kernel.h>
56694 +#include <linux/module.h>
56695 +#include <linux/sched.h>
56696 +#include <linux/mm.h>
56697 +#include <linux/file.h>
56698 +#include <linux/fs.h>
56699 +#include <linux/namei.h>
56700 +#include <linux/mount.h>
56701 +#include <linux/tty.h>
56702 +#include <linux/proc_fs.h>
56703 +#include <linux/lglock.h>
56704 +#include <linux/slab.h>
56705 +#include <linux/vmalloc.h>
56706 +#include <linux/types.h>
56707 +#include <linux/sysctl.h>
56708 +#include <linux/netdevice.h>
56709 +#include <linux/ptrace.h>
56710 +#include <linux/gracl.h>
56711 +#include <linux/gralloc.h>
56712 +#include <linux/security.h>
56713 +#include <linux/grinternal.h>
56714 +#include <linux/pid_namespace.h>
56715 +#include <linux/stop_machine.h>
56716 +#include <linux/fdtable.h>
56717 +#include <linux/percpu.h>
56718 +#include <linux/lglock.h>
56719 +#include <linux/hugetlb.h>
56720 +#include "../fs/mount.h"
56721 +
56722 +#include <asm/uaccess.h>
56723 +#include <asm/errno.h>
56724 +#include <asm/mman.h>
56725 +
56726 +extern struct lglock vfsmount_lock;
56727 +
56728 +static struct acl_role_db acl_role_set;
56729 +static struct name_db name_set;
56730 +static struct inodev_db inodev_set;
56731 +
56732 +/* for keeping track of userspace pointers used for subjects, so we
56733 + can share references in the kernel as well
56734 +*/
56735 +
56736 +static struct path real_root;
56737 +
56738 +static struct acl_subj_map_db subj_map_set;
56739 +
56740 +static struct acl_role_label *default_role;
56741 +
56742 +static struct acl_role_label *role_list;
56743 +
56744 +static u16 acl_sp_role_value;
56745 +
56746 +extern char *gr_shared_page[4];
56747 +static DEFINE_MUTEX(gr_dev_mutex);
56748 +DEFINE_RWLOCK(gr_inode_lock);
56749 +
56750 +struct gr_arg *gr_usermode;
56751 +
56752 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
56753 +
56754 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
56755 +extern void gr_clear_learn_entries(void);
56756 +
56757 +unsigned char *gr_system_salt;
56758 +unsigned char *gr_system_sum;
56759 +
56760 +static struct sprole_pw **acl_special_roles = NULL;
56761 +static __u16 num_sprole_pws = 0;
56762 +
56763 +static struct acl_role_label *kernel_role = NULL;
56764 +
56765 +static unsigned int gr_auth_attempts = 0;
56766 +static unsigned long gr_auth_expires = 0UL;
56767 +
56768 +#ifdef CONFIG_NET
56769 +extern struct vfsmount *sock_mnt;
56770 +#endif
56771 +
56772 +extern struct vfsmount *pipe_mnt;
56773 +extern struct vfsmount *shm_mnt;
56774 +
56775 +#ifdef CONFIG_HUGETLBFS
56776 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
56777 +#endif
56778 +
56779 +static struct acl_object_label *fakefs_obj_rw;
56780 +static struct acl_object_label *fakefs_obj_rwx;
56781 +
56782 +extern int gr_init_uidset(void);
56783 +extern void gr_free_uidset(void);
56784 +extern void gr_remove_uid(uid_t uid);
56785 +extern int gr_find_uid(uid_t uid);
56786 +
56787 +__inline__ int
56788 +gr_acl_is_enabled(void)
56789 +{
56790 + return (gr_status & GR_READY);
56791 +}
56792 +
56793 +#ifdef CONFIG_BTRFS_FS
56794 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56795 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56796 +#endif
56797 +
56798 +static inline dev_t __get_dev(const struct dentry *dentry)
56799 +{
56800 +#ifdef CONFIG_BTRFS_FS
56801 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56802 + return get_btrfs_dev_from_inode(dentry->d_inode);
56803 + else
56804 +#endif
56805 + return dentry->d_inode->i_sb->s_dev;
56806 +}
56807 +
56808 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
56809 +{
56810 + return __get_dev(dentry);
56811 +}
56812 +
56813 +static char gr_task_roletype_to_char(struct task_struct *task)
56814 +{
56815 + switch (task->role->roletype &
56816 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
56817 + GR_ROLE_SPECIAL)) {
56818 + case GR_ROLE_DEFAULT:
56819 + return 'D';
56820 + case GR_ROLE_USER:
56821 + return 'U';
56822 + case GR_ROLE_GROUP:
56823 + return 'G';
56824 + case GR_ROLE_SPECIAL:
56825 + return 'S';
56826 + }
56827 +
56828 + return 'X';
56829 +}
56830 +
56831 +char gr_roletype_to_char(void)
56832 +{
56833 + return gr_task_roletype_to_char(current);
56834 +}
56835 +
56836 +__inline__ int
56837 +gr_acl_tpe_check(void)
56838 +{
56839 + if (unlikely(!(gr_status & GR_READY)))
56840 + return 0;
56841 + if (current->role->roletype & GR_ROLE_TPE)
56842 + return 1;
56843 + else
56844 + return 0;
56845 +}
56846 +
56847 +int
56848 +gr_handle_rawio(const struct inode *inode)
56849 +{
56850 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56851 + if (inode && S_ISBLK(inode->i_mode) &&
56852 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56853 + !capable(CAP_SYS_RAWIO))
56854 + return 1;
56855 +#endif
56856 + return 0;
56857 +}
56858 +
56859 +static int
56860 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
56861 +{
56862 + if (likely(lena != lenb))
56863 + return 0;
56864 +
56865 + return !memcmp(a, b, lena);
56866 +}
56867 +
56868 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
56869 +{
56870 + *buflen -= namelen;
56871 + if (*buflen < 0)
56872 + return -ENAMETOOLONG;
56873 + *buffer -= namelen;
56874 + memcpy(*buffer, str, namelen);
56875 + return 0;
56876 +}
56877 +
56878 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
56879 +{
56880 + return prepend(buffer, buflen, name->name, name->len);
56881 +}
56882 +
56883 +static int prepend_path(const struct path *path, struct path *root,
56884 + char **buffer, int *buflen)
56885 +{
56886 + struct dentry *dentry = path->dentry;
56887 + struct vfsmount *vfsmnt = path->mnt;
56888 + struct mount *mnt = real_mount(vfsmnt);
56889 + bool slash = false;
56890 + int error = 0;
56891 +
56892 + while (dentry != root->dentry || vfsmnt != root->mnt) {
56893 + struct dentry * parent;
56894 +
56895 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
56896 + /* Global root? */
56897 + if (!mnt_has_parent(mnt)) {
56898 + goto out;
56899 + }
56900 + dentry = mnt->mnt_mountpoint;
56901 + mnt = mnt->mnt_parent;
56902 + vfsmnt = &mnt->mnt;
56903 + continue;
56904 + }
56905 + parent = dentry->d_parent;
56906 + prefetch(parent);
56907 + spin_lock(&dentry->d_lock);
56908 + error = prepend_name(buffer, buflen, &dentry->d_name);
56909 + spin_unlock(&dentry->d_lock);
56910 + if (!error)
56911 + error = prepend(buffer, buflen, "/", 1);
56912 + if (error)
56913 + break;
56914 +
56915 + slash = true;
56916 + dentry = parent;
56917 + }
56918 +
56919 +out:
56920 + if (!error && !slash)
56921 + error = prepend(buffer, buflen, "/", 1);
56922 +
56923 + return error;
56924 +}
56925 +
56926 +/* this must be called with vfsmount_lock and rename_lock held */
56927 +
56928 +static char *__our_d_path(const struct path *path, struct path *root,
56929 + char *buf, int buflen)
56930 +{
56931 + char *res = buf + buflen;
56932 + int error;
56933 +
56934 + prepend(&res, &buflen, "\0", 1);
56935 + error = prepend_path(path, root, &res, &buflen);
56936 + if (error)
56937 + return ERR_PTR(error);
56938 +
56939 + return res;
56940 +}
56941 +
56942 +static char *
56943 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
56944 +{
56945 + char *retval;
56946 +
56947 + retval = __our_d_path(path, root, buf, buflen);
56948 + if (unlikely(IS_ERR(retval)))
56949 + retval = strcpy(buf, "<path too long>");
56950 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
56951 + retval[1] = '\0';
56952 +
56953 + return retval;
56954 +}
56955 +
56956 +static char *
56957 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
56958 + char *buf, int buflen)
56959 +{
56960 + struct path path;
56961 + char *res;
56962 +
56963 + path.dentry = (struct dentry *)dentry;
56964 + path.mnt = (struct vfsmount *)vfsmnt;
56965 +
56966 + /* we can use real_root.dentry, real_root.mnt, because this is only called
56967 + by the RBAC system */
56968 + res = gen_full_path(&path, &real_root, buf, buflen);
56969 +
56970 + return res;
56971 +}
56972 +
56973 +static char *
56974 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
56975 + char *buf, int buflen)
56976 +{
56977 + char *res;
56978 + struct path path;
56979 + struct path root;
56980 + struct task_struct *reaper = init_pid_ns.child_reaper;
56981 +
56982 + path.dentry = (struct dentry *)dentry;
56983 + path.mnt = (struct vfsmount *)vfsmnt;
56984 +
56985 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
56986 + get_fs_root(reaper->fs, &root);
56987 +
56988 + write_seqlock(&rename_lock);
56989 + br_read_lock(&vfsmount_lock);
56990 + res = gen_full_path(&path, &root, buf, buflen);
56991 + br_read_unlock(&vfsmount_lock);
56992 + write_sequnlock(&rename_lock);
56993 +
56994 + path_put(&root);
56995 + return res;
56996 +}
56997 +
56998 +static char *
56999 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57000 +{
57001 + char *ret;
57002 + write_seqlock(&rename_lock);
57003 + br_read_lock(&vfsmount_lock);
57004 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57005 + PAGE_SIZE);
57006 + br_read_unlock(&vfsmount_lock);
57007 + write_sequnlock(&rename_lock);
57008 + return ret;
57009 +}
57010 +
57011 +static char *
57012 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57013 +{
57014 + char *ret;
57015 + char *buf;
57016 + int buflen;
57017 +
57018 + write_seqlock(&rename_lock);
57019 + br_read_lock(&vfsmount_lock);
57020 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
57021 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
57022 + buflen = (int)(ret - buf);
57023 + if (buflen >= 5)
57024 + prepend(&ret, &buflen, "/proc", 5);
57025 + else
57026 + ret = strcpy(buf, "<path too long>");
57027 + br_read_unlock(&vfsmount_lock);
57028 + write_sequnlock(&rename_lock);
57029 + return ret;
57030 +}
57031 +
57032 +char *
57033 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
57034 +{
57035 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57036 + PAGE_SIZE);
57037 +}
57038 +
57039 +char *
57040 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
57041 +{
57042 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57043 + PAGE_SIZE);
57044 +}
57045 +
57046 +char *
57047 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
57048 +{
57049 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
57050 + PAGE_SIZE);
57051 +}
57052 +
57053 +char *
57054 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
57055 +{
57056 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
57057 + PAGE_SIZE);
57058 +}
57059 +
57060 +char *
57061 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
57062 +{
57063 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
57064 + PAGE_SIZE);
57065 +}
57066 +
57067 +__inline__ __u32
57068 +to_gr_audit(const __u32 reqmode)
57069 +{
57070 + /* masks off auditable permission flags, then shifts them to create
57071 + auditing flags, and adds the special case of append auditing if
57072 + we're requesting write */
57073 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
57074 +}
57075 +
57076 +struct acl_subject_label *
57077 +lookup_subject_map(const struct acl_subject_label *userp)
57078 +{
57079 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
57080 + struct subject_map *match;
57081 +
57082 + match = subj_map_set.s_hash[index];
57083 +
57084 + while (match && match->user != userp)
57085 + match = match->next;
57086 +
57087 + if (match != NULL)
57088 + return match->kernel;
57089 + else
57090 + return NULL;
57091 +}
57092 +
57093 +static void
57094 +insert_subj_map_entry(struct subject_map *subjmap)
57095 +{
57096 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
57097 + struct subject_map **curr;
57098 +
57099 + subjmap->prev = NULL;
57100 +
57101 + curr = &subj_map_set.s_hash[index];
57102 + if (*curr != NULL)
57103 + (*curr)->prev = subjmap;
57104 +
57105 + subjmap->next = *curr;
57106 + *curr = subjmap;
57107 +
57108 + return;
57109 +}
57110 +
57111 +static struct acl_role_label *
57112 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
57113 + const gid_t gid)
57114 +{
57115 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
57116 + struct acl_role_label *match;
57117 + struct role_allowed_ip *ipp;
57118 + unsigned int x;
57119 + u32 curr_ip = task->signal->curr_ip;
57120 +
57121 + task->signal->saved_ip = curr_ip;
57122 +
57123 + match = acl_role_set.r_hash[index];
57124 +
57125 + while (match) {
57126 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
57127 + for (x = 0; x < match->domain_child_num; x++) {
57128 + if (match->domain_children[x] == uid)
57129 + goto found;
57130 + }
57131 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
57132 + break;
57133 + match = match->next;
57134 + }
57135 +found:
57136 + if (match == NULL) {
57137 + try_group:
57138 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
57139 + match = acl_role_set.r_hash[index];
57140 +
57141 + while (match) {
57142 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
57143 + for (x = 0; x < match->domain_child_num; x++) {
57144 + if (match->domain_children[x] == gid)
57145 + goto found2;
57146 + }
57147 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
57148 + break;
57149 + match = match->next;
57150 + }
57151 +found2:
57152 + if (match == NULL)
57153 + match = default_role;
57154 + if (match->allowed_ips == NULL)
57155 + return match;
57156 + else {
57157 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57158 + if (likely
57159 + ((ntohl(curr_ip) & ipp->netmask) ==
57160 + (ntohl(ipp->addr) & ipp->netmask)))
57161 + return match;
57162 + }
57163 + match = default_role;
57164 + }
57165 + } else if (match->allowed_ips == NULL) {
57166 + return match;
57167 + } else {
57168 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57169 + if (likely
57170 + ((ntohl(curr_ip) & ipp->netmask) ==
57171 + (ntohl(ipp->addr) & ipp->netmask)))
57172 + return match;
57173 + }
57174 + goto try_group;
57175 + }
57176 +
57177 + return match;
57178 +}
57179 +
57180 +struct acl_subject_label *
57181 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
57182 + const struct acl_role_label *role)
57183 +{
57184 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57185 + struct acl_subject_label *match;
57186 +
57187 + match = role->subj_hash[index];
57188 +
57189 + while (match && (match->inode != ino || match->device != dev ||
57190 + (match->mode & GR_DELETED))) {
57191 + match = match->next;
57192 + }
57193 +
57194 + if (match && !(match->mode & GR_DELETED))
57195 + return match;
57196 + else
57197 + return NULL;
57198 +}
57199 +
57200 +struct acl_subject_label *
57201 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
57202 + const struct acl_role_label *role)
57203 +{
57204 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57205 + struct acl_subject_label *match;
57206 +
57207 + match = role->subj_hash[index];
57208 +
57209 + while (match && (match->inode != ino || match->device != dev ||
57210 + !(match->mode & GR_DELETED))) {
57211 + match = match->next;
57212 + }
57213 +
57214 + if (match && (match->mode & GR_DELETED))
57215 + return match;
57216 + else
57217 + return NULL;
57218 +}
57219 +
57220 +static struct acl_object_label *
57221 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
57222 + const struct acl_subject_label *subj)
57223 +{
57224 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57225 + struct acl_object_label *match;
57226 +
57227 + match = subj->obj_hash[index];
57228 +
57229 + while (match && (match->inode != ino || match->device != dev ||
57230 + (match->mode & GR_DELETED))) {
57231 + match = match->next;
57232 + }
57233 +
57234 + if (match && !(match->mode & GR_DELETED))
57235 + return match;
57236 + else
57237 + return NULL;
57238 +}
57239 +
57240 +static struct acl_object_label *
57241 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
57242 + const struct acl_subject_label *subj)
57243 +{
57244 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57245 + struct acl_object_label *match;
57246 +
57247 + match = subj->obj_hash[index];
57248 +
57249 + while (match && (match->inode != ino || match->device != dev ||
57250 + !(match->mode & GR_DELETED))) {
57251 + match = match->next;
57252 + }
57253 +
57254 + if (match && (match->mode & GR_DELETED))
57255 + return match;
57256 +
57257 + match = subj->obj_hash[index];
57258 +
57259 + while (match && (match->inode != ino || match->device != dev ||
57260 + (match->mode & GR_DELETED))) {
57261 + match = match->next;
57262 + }
57263 +
57264 + if (match && !(match->mode & GR_DELETED))
57265 + return match;
57266 + else
57267 + return NULL;
57268 +}
57269 +
57270 +static struct name_entry *
57271 +lookup_name_entry(const char *name)
57272 +{
57273 + unsigned int len = strlen(name);
57274 + unsigned int key = full_name_hash(name, len);
57275 + unsigned int index = key % name_set.n_size;
57276 + struct name_entry *match;
57277 +
57278 + match = name_set.n_hash[index];
57279 +
57280 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
57281 + match = match->next;
57282 +
57283 + return match;
57284 +}
57285 +
57286 +static struct name_entry *
57287 +lookup_name_entry_create(const char *name)
57288 +{
57289 + unsigned int len = strlen(name);
57290 + unsigned int key = full_name_hash(name, len);
57291 + unsigned int index = key % name_set.n_size;
57292 + struct name_entry *match;
57293 +
57294 + match = name_set.n_hash[index];
57295 +
57296 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57297 + !match->deleted))
57298 + match = match->next;
57299 +
57300 + if (match && match->deleted)
57301 + return match;
57302 +
57303 + match = name_set.n_hash[index];
57304 +
57305 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57306 + match->deleted))
57307 + match = match->next;
57308 +
57309 + if (match && !match->deleted)
57310 + return match;
57311 + else
57312 + return NULL;
57313 +}
57314 +
57315 +static struct inodev_entry *
57316 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
57317 +{
57318 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
57319 + struct inodev_entry *match;
57320 +
57321 + match = inodev_set.i_hash[index];
57322 +
57323 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
57324 + match = match->next;
57325 +
57326 + return match;
57327 +}
57328 +
57329 +static void
57330 +insert_inodev_entry(struct inodev_entry *entry)
57331 +{
57332 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
57333 + inodev_set.i_size);
57334 + struct inodev_entry **curr;
57335 +
57336 + entry->prev = NULL;
57337 +
57338 + curr = &inodev_set.i_hash[index];
57339 + if (*curr != NULL)
57340 + (*curr)->prev = entry;
57341 +
57342 + entry->next = *curr;
57343 + *curr = entry;
57344 +
57345 + return;
57346 +}
57347 +
57348 +static void
57349 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
57350 +{
57351 + unsigned int index =
57352 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
57353 + struct acl_role_label **curr;
57354 + struct acl_role_label *tmp, *tmp2;
57355 +
57356 + curr = &acl_role_set.r_hash[index];
57357 +
57358 + /* simple case, slot is empty, just set it to our role */
57359 + if (*curr == NULL) {
57360 + *curr = role;
57361 + } else {
57362 + /* example:
57363 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
57364 + 2 -> 3
57365 + */
57366 + /* first check to see if we can already be reached via this slot */
57367 + tmp = *curr;
57368 + while (tmp && tmp != role)
57369 + tmp = tmp->next;
57370 + if (tmp == role) {
57371 + /* we don't need to add ourselves to this slot's chain */
57372 + return;
57373 + }
57374 + /* we need to add ourselves to this chain, two cases */
57375 + if (role->next == NULL) {
57376 + /* simple case, append the current chain to our role */
57377 + role->next = *curr;
57378 + *curr = role;
57379 + } else {
57380 + /* 1 -> 2 -> 3 -> 4
57381 + 2 -> 3 -> 4
57382 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
57383 + */
57384 + /* trickier case: walk our role's chain until we find
57385 + the role for the start of the current slot's chain */
57386 + tmp = role;
57387 + tmp2 = *curr;
57388 + while (tmp->next && tmp->next != tmp2)
57389 + tmp = tmp->next;
57390 + if (tmp->next == tmp2) {
57391 + /* from example above, we found 3, so just
57392 + replace this slot's chain with ours */
57393 + *curr = role;
57394 + } else {
57395 + /* we didn't find a subset of our role's chain
57396 + in the current slot's chain, so append their
57397 + chain to ours, and set us as the first role in
57398 + the slot's chain
57399 +
57400 + we could fold this case with the case above,
57401 + but making it explicit for clarity
57402 + */
57403 + tmp->next = tmp2;
57404 + *curr = role;
57405 + }
57406 + }
57407 + }
57408 +
57409 + return;
57410 +}
57411 +
57412 +static void
57413 +insert_acl_role_label(struct acl_role_label *role)
57414 +{
57415 + int i;
57416 +
57417 + if (role_list == NULL) {
57418 + role_list = role;
57419 + role->prev = NULL;
57420 + } else {
57421 + role->prev = role_list;
57422 + role_list = role;
57423 + }
57424 +
57425 + /* used for hash chains */
57426 + role->next = NULL;
57427 +
57428 + if (role->roletype & GR_ROLE_DOMAIN) {
57429 + for (i = 0; i < role->domain_child_num; i++)
57430 + __insert_acl_role_label(role, role->domain_children[i]);
57431 + } else
57432 + __insert_acl_role_label(role, role->uidgid);
57433 +}
57434 +
57435 +static int
57436 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
57437 +{
57438 + struct name_entry **curr, *nentry;
57439 + struct inodev_entry *ientry;
57440 + unsigned int len = strlen(name);
57441 + unsigned int key = full_name_hash(name, len);
57442 + unsigned int index = key % name_set.n_size;
57443 +
57444 + curr = &name_set.n_hash[index];
57445 +
57446 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
57447 + curr = &((*curr)->next);
57448 +
57449 + if (*curr != NULL)
57450 + return 1;
57451 +
57452 + nentry = acl_alloc(sizeof (struct name_entry));
57453 + if (nentry == NULL)
57454 + return 0;
57455 + ientry = acl_alloc(sizeof (struct inodev_entry));
57456 + if (ientry == NULL)
57457 + return 0;
57458 + ientry->nentry = nentry;
57459 +
57460 + nentry->key = key;
57461 + nentry->name = name;
57462 + nentry->inode = inode;
57463 + nentry->device = device;
57464 + nentry->len = len;
57465 + nentry->deleted = deleted;
57466 +
57467 + nentry->prev = NULL;
57468 + curr = &name_set.n_hash[index];
57469 + if (*curr != NULL)
57470 + (*curr)->prev = nentry;
57471 + nentry->next = *curr;
57472 + *curr = nentry;
57473 +
57474 + /* insert us into the table searchable by inode/dev */
57475 + insert_inodev_entry(ientry);
57476 +
57477 + return 1;
57478 +}
57479 +
57480 +static void
57481 +insert_acl_obj_label(struct acl_object_label *obj,
57482 + struct acl_subject_label *subj)
57483 +{
57484 + unsigned int index =
57485 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
57486 + struct acl_object_label **curr;
57487 +
57488 +
57489 + obj->prev = NULL;
57490 +
57491 + curr = &subj->obj_hash[index];
57492 + if (*curr != NULL)
57493 + (*curr)->prev = obj;
57494 +
57495 + obj->next = *curr;
57496 + *curr = obj;
57497 +
57498 + return;
57499 +}
57500 +
57501 +static void
57502 +insert_acl_subj_label(struct acl_subject_label *obj,
57503 + struct acl_role_label *role)
57504 +{
57505 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
57506 + struct acl_subject_label **curr;
57507 +
57508 + obj->prev = NULL;
57509 +
57510 + curr = &role->subj_hash[index];
57511 + if (*curr != NULL)
57512 + (*curr)->prev = obj;
57513 +
57514 + obj->next = *curr;
57515 + *curr = obj;
57516 +
57517 + return;
57518 +}
57519 +
57520 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
57521 +
57522 +static void *
57523 +create_table(__u32 * len, int elementsize)
57524 +{
57525 + unsigned int table_sizes[] = {
57526 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
57527 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
57528 + 4194301, 8388593, 16777213, 33554393, 67108859
57529 + };
57530 + void *newtable = NULL;
57531 + unsigned int pwr = 0;
57532 +
57533 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
57534 + table_sizes[pwr] <= *len)
57535 + pwr++;
57536 +
57537 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
57538 + return newtable;
57539 +
57540 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
57541 + newtable =
57542 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
57543 + else
57544 + newtable = vmalloc(table_sizes[pwr] * elementsize);
57545 +
57546 + *len = table_sizes[pwr];
57547 +
57548 + return newtable;
57549 +}
57550 +
57551 +static int
57552 +init_variables(const struct gr_arg *arg)
57553 +{
57554 + struct task_struct *reaper = init_pid_ns.child_reaper;
57555 + unsigned int stacksize;
57556 +
57557 + subj_map_set.s_size = arg->role_db.num_subjects;
57558 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
57559 + name_set.n_size = arg->role_db.num_objects;
57560 + inodev_set.i_size = arg->role_db.num_objects;
57561 +
57562 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
57563 + !name_set.n_size || !inodev_set.i_size)
57564 + return 1;
57565 +
57566 + if (!gr_init_uidset())
57567 + return 1;
57568 +
57569 + /* set up the stack that holds allocation info */
57570 +
57571 + stacksize = arg->role_db.num_pointers + 5;
57572 +
57573 + if (!acl_alloc_stack_init(stacksize))
57574 + return 1;
57575 +
57576 + /* grab reference for the real root dentry and vfsmount */
57577 + get_fs_root(reaper->fs, &real_root);
57578 +
57579 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57580 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
57581 +#endif
57582 +
57583 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
57584 + if (fakefs_obj_rw == NULL)
57585 + return 1;
57586 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
57587 +
57588 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
57589 + if (fakefs_obj_rwx == NULL)
57590 + return 1;
57591 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
57592 +
57593 + subj_map_set.s_hash =
57594 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
57595 + acl_role_set.r_hash =
57596 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
57597 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
57598 + inodev_set.i_hash =
57599 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
57600 +
57601 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
57602 + !name_set.n_hash || !inodev_set.i_hash)
57603 + return 1;
57604 +
57605 + memset(subj_map_set.s_hash, 0,
57606 + sizeof(struct subject_map *) * subj_map_set.s_size);
57607 + memset(acl_role_set.r_hash, 0,
57608 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
57609 + memset(name_set.n_hash, 0,
57610 + sizeof (struct name_entry *) * name_set.n_size);
57611 + memset(inodev_set.i_hash, 0,
57612 + sizeof (struct inodev_entry *) * inodev_set.i_size);
57613 +
57614 + return 0;
57615 +}
57616 +
57617 +/* free information not needed after startup
57618 + currently contains user->kernel pointer mappings for subjects
57619 +*/
57620 +
57621 +static void
57622 +free_init_variables(void)
57623 +{
57624 + __u32 i;
57625 +
57626 + if (subj_map_set.s_hash) {
57627 + for (i = 0; i < subj_map_set.s_size; i++) {
57628 + if (subj_map_set.s_hash[i]) {
57629 + kfree(subj_map_set.s_hash[i]);
57630 + subj_map_set.s_hash[i] = NULL;
57631 + }
57632 + }
57633 +
57634 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
57635 + PAGE_SIZE)
57636 + kfree(subj_map_set.s_hash);
57637 + else
57638 + vfree(subj_map_set.s_hash);
57639 + }
57640 +
57641 + return;
57642 +}
57643 +
57644 +static void
57645 +free_variables(void)
57646 +{
57647 + struct acl_subject_label *s;
57648 + struct acl_role_label *r;
57649 + struct task_struct *task, *task2;
57650 + unsigned int x;
57651 +
57652 + gr_clear_learn_entries();
57653 +
57654 + read_lock(&tasklist_lock);
57655 + do_each_thread(task2, task) {
57656 + task->acl_sp_role = 0;
57657 + task->acl_role_id = 0;
57658 + task->acl = NULL;
57659 + task->role = NULL;
57660 + } while_each_thread(task2, task);
57661 + read_unlock(&tasklist_lock);
57662 +
57663 + /* release the reference to the real root dentry and vfsmount */
57664 + path_put(&real_root);
57665 + memset(&real_root, 0, sizeof(real_root));
57666 +
57667 + /* free all object hash tables */
57668 +
57669 + FOR_EACH_ROLE_START(r)
57670 + if (r->subj_hash == NULL)
57671 + goto next_role;
57672 + FOR_EACH_SUBJECT_START(r, s, x)
57673 + if (s->obj_hash == NULL)
57674 + break;
57675 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
57676 + kfree(s->obj_hash);
57677 + else
57678 + vfree(s->obj_hash);
57679 + FOR_EACH_SUBJECT_END(s, x)
57680 + FOR_EACH_NESTED_SUBJECT_START(r, s)
57681 + if (s->obj_hash == NULL)
57682 + break;
57683 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
57684 + kfree(s->obj_hash);
57685 + else
57686 + vfree(s->obj_hash);
57687 + FOR_EACH_NESTED_SUBJECT_END(s)
57688 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
57689 + kfree(r->subj_hash);
57690 + else
57691 + vfree(r->subj_hash);
57692 + r->subj_hash = NULL;
57693 +next_role:
57694 + FOR_EACH_ROLE_END(r)
57695 +
57696 + acl_free_all();
57697 +
57698 + if (acl_role_set.r_hash) {
57699 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
57700 + PAGE_SIZE)
57701 + kfree(acl_role_set.r_hash);
57702 + else
57703 + vfree(acl_role_set.r_hash);
57704 + }
57705 + if (name_set.n_hash) {
57706 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
57707 + PAGE_SIZE)
57708 + kfree(name_set.n_hash);
57709 + else
57710 + vfree(name_set.n_hash);
57711 + }
57712 +
57713 + if (inodev_set.i_hash) {
57714 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
57715 + PAGE_SIZE)
57716 + kfree(inodev_set.i_hash);
57717 + else
57718 + vfree(inodev_set.i_hash);
57719 + }
57720 +
57721 + gr_free_uidset();
57722 +
57723 + memset(&name_set, 0, sizeof (struct name_db));
57724 + memset(&inodev_set, 0, sizeof (struct inodev_db));
57725 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
57726 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
57727 +
57728 + default_role = NULL;
57729 + kernel_role = NULL;
57730 + role_list = NULL;
57731 +
57732 + return;
57733 +}
57734 +
57735 +static __u32
57736 +count_user_objs(struct acl_object_label *userp)
57737 +{
57738 + struct acl_object_label o_tmp;
57739 + __u32 num = 0;
57740 +
57741 + while (userp) {
57742 + if (copy_from_user(&o_tmp, userp,
57743 + sizeof (struct acl_object_label)))
57744 + break;
57745 +
57746 + userp = o_tmp.prev;
57747 + num++;
57748 + }
57749 +
57750 + return num;
57751 +}
57752 +
57753 +static struct acl_subject_label *
57754 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
57755 +
57756 +static int
57757 +copy_user_glob(struct acl_object_label *obj)
57758 +{
57759 + struct acl_object_label *g_tmp, **guser;
57760 + unsigned int len;
57761 + char *tmp;
57762 +
57763 + if (obj->globbed == NULL)
57764 + return 0;
57765 +
57766 + guser = &obj->globbed;
57767 + while (*guser) {
57768 + g_tmp = (struct acl_object_label *)
57769 + acl_alloc(sizeof (struct acl_object_label));
57770 + if (g_tmp == NULL)
57771 + return -ENOMEM;
57772 +
57773 + if (copy_from_user(g_tmp, *guser,
57774 + sizeof (struct acl_object_label)))
57775 + return -EFAULT;
57776 +
57777 + len = strnlen_user(g_tmp->filename, PATH_MAX);
57778 +
57779 + if (!len || len >= PATH_MAX)
57780 + return -EINVAL;
57781 +
57782 + if ((tmp = (char *) acl_alloc(len)) == NULL)
57783 + return -ENOMEM;
57784 +
57785 + if (copy_from_user(tmp, g_tmp->filename, len))
57786 + return -EFAULT;
57787 + tmp[len-1] = '\0';
57788 + g_tmp->filename = tmp;
57789 +
57790 + *guser = g_tmp;
57791 + guser = &(g_tmp->next);
57792 + }
57793 +
57794 + return 0;
57795 +}
57796 +
57797 +static int
57798 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
57799 + struct acl_role_label *role)
57800 +{
57801 + struct acl_object_label *o_tmp;
57802 + unsigned int len;
57803 + int ret;
57804 + char *tmp;
57805 +
57806 + while (userp) {
57807 + if ((o_tmp = (struct acl_object_label *)
57808 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
57809 + return -ENOMEM;
57810 +
57811 + if (copy_from_user(o_tmp, userp,
57812 + sizeof (struct acl_object_label)))
57813 + return -EFAULT;
57814 +
57815 + userp = o_tmp->prev;
57816 +
57817 + len = strnlen_user(o_tmp->filename, PATH_MAX);
57818 +
57819 + if (!len || len >= PATH_MAX)
57820 + return -EINVAL;
57821 +
57822 + if ((tmp = (char *) acl_alloc(len)) == NULL)
57823 + return -ENOMEM;
57824 +
57825 + if (copy_from_user(tmp, o_tmp->filename, len))
57826 + return -EFAULT;
57827 + tmp[len-1] = '\0';
57828 + o_tmp->filename = tmp;
57829 +
57830 + insert_acl_obj_label(o_tmp, subj);
57831 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
57832 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
57833 + return -ENOMEM;
57834 +
57835 + ret = copy_user_glob(o_tmp);
57836 + if (ret)
57837 + return ret;
57838 +
57839 + if (o_tmp->nested) {
57840 + int already_copied;
57841 +
57842 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
57843 + if (IS_ERR(o_tmp->nested))
57844 + return PTR_ERR(o_tmp->nested);
57845 +
57846 + /* insert into nested subject list if we haven't copied this one yet
57847 + to prevent duplicate entries */
57848 + if (!already_copied) {
57849 + o_tmp->nested->next = role->hash->first;
57850 + role->hash->first = o_tmp->nested;
57851 + }
57852 + }
57853 + }
57854 +
57855 + return 0;
57856 +}
57857 +
57858 +static __u32
57859 +count_user_subjs(struct acl_subject_label *userp)
57860 +{
57861 + struct acl_subject_label s_tmp;
57862 + __u32 num = 0;
57863 +
57864 + while (userp) {
57865 + if (copy_from_user(&s_tmp, userp,
57866 + sizeof (struct acl_subject_label)))
57867 + break;
57868 +
57869 + userp = s_tmp.prev;
57870 + }
57871 +
57872 + return num;
57873 +}
57874 +
57875 +static int
57876 +copy_user_allowedips(struct acl_role_label *rolep)
57877 +{
57878 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
57879 +
57880 + ruserip = rolep->allowed_ips;
57881 +
57882 + while (ruserip) {
57883 + rlast = rtmp;
57884 +
57885 + if ((rtmp = (struct role_allowed_ip *)
57886 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
57887 + return -ENOMEM;
57888 +
57889 + if (copy_from_user(rtmp, ruserip,
57890 + sizeof (struct role_allowed_ip)))
57891 + return -EFAULT;
57892 +
57893 + ruserip = rtmp->prev;
57894 +
57895 + if (!rlast) {
57896 + rtmp->prev = NULL;
57897 + rolep->allowed_ips = rtmp;
57898 + } else {
57899 + rlast->next = rtmp;
57900 + rtmp->prev = rlast;
57901 + }
57902 +
57903 + if (!ruserip)
57904 + rtmp->next = NULL;
57905 + }
57906 +
57907 + return 0;
57908 +}
57909 +
57910 +static int
57911 +copy_user_transitions(struct acl_role_label *rolep)
57912 +{
57913 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
57914 +
57915 + unsigned int len;
57916 + char *tmp;
57917 +
57918 + rusertp = rolep->transitions;
57919 +
57920 + while (rusertp) {
57921 + rlast = rtmp;
57922 +
57923 + if ((rtmp = (struct role_transition *)
57924 + acl_alloc(sizeof (struct role_transition))) == NULL)
57925 + return -ENOMEM;
57926 +
57927 + if (copy_from_user(rtmp, rusertp,
57928 + sizeof (struct role_transition)))
57929 + return -EFAULT;
57930 +
57931 + rusertp = rtmp->prev;
57932 +
57933 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
57934 +
57935 + if (!len || len >= GR_SPROLE_LEN)
57936 + return -EINVAL;
57937 +
57938 + if ((tmp = (char *) acl_alloc(len)) == NULL)
57939 + return -ENOMEM;
57940 +
57941 + if (copy_from_user(tmp, rtmp->rolename, len))
57942 + return -EFAULT;
57943 + tmp[len-1] = '\0';
57944 + rtmp->rolename = tmp;
57945 +
57946 + if (!rlast) {
57947 + rtmp->prev = NULL;
57948 + rolep->transitions = rtmp;
57949 + } else {
57950 + rlast->next = rtmp;
57951 + rtmp->prev = rlast;
57952 + }
57953 +
57954 + if (!rusertp)
57955 + rtmp->next = NULL;
57956 + }
57957 +
57958 + return 0;
57959 +}
57960 +
57961 +static struct acl_subject_label *
57962 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
57963 +{
57964 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
57965 + unsigned int len;
57966 + char *tmp;
57967 + __u32 num_objs;
57968 + struct acl_ip_label **i_tmp, *i_utmp2;
57969 + struct gr_hash_struct ghash;
57970 + struct subject_map *subjmap;
57971 + unsigned int i_num;
57972 + int err;
57973 +
57974 + if (already_copied != NULL)
57975 + *already_copied = 0;
57976 +
57977 + s_tmp = lookup_subject_map(userp);
57978 +
57979 + /* we've already copied this subject into the kernel, just return
57980 + the reference to it, and don't copy it over again
57981 + */
57982 + if (s_tmp) {
57983 + if (already_copied != NULL)
57984 + *already_copied = 1;
57985 + return(s_tmp);
57986 + }
57987 +
57988 + if ((s_tmp = (struct acl_subject_label *)
57989 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
57990 + return ERR_PTR(-ENOMEM);
57991 +
57992 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
57993 + if (subjmap == NULL)
57994 + return ERR_PTR(-ENOMEM);
57995 +
57996 + subjmap->user = userp;
57997 + subjmap->kernel = s_tmp;
57998 + insert_subj_map_entry(subjmap);
57999 +
58000 + if (copy_from_user(s_tmp, userp,
58001 + sizeof (struct acl_subject_label)))
58002 + return ERR_PTR(-EFAULT);
58003 +
58004 + len = strnlen_user(s_tmp->filename, PATH_MAX);
58005 +
58006 + if (!len || len >= PATH_MAX)
58007 + return ERR_PTR(-EINVAL);
58008 +
58009 + if ((tmp = (char *) acl_alloc(len)) == NULL)
58010 + return ERR_PTR(-ENOMEM);
58011 +
58012 + if (copy_from_user(tmp, s_tmp->filename, len))
58013 + return ERR_PTR(-EFAULT);
58014 + tmp[len-1] = '\0';
58015 + s_tmp->filename = tmp;
58016 +
58017 + if (!strcmp(s_tmp->filename, "/"))
58018 + role->root_label = s_tmp;
58019 +
58020 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
58021 + return ERR_PTR(-EFAULT);
58022 +
58023 + /* copy user and group transition tables */
58024 +
58025 + if (s_tmp->user_trans_num) {
58026 + uid_t *uidlist;
58027 +
58028 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
58029 + if (uidlist == NULL)
58030 + return ERR_PTR(-ENOMEM);
58031 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
58032 + return ERR_PTR(-EFAULT);
58033 +
58034 + s_tmp->user_transitions = uidlist;
58035 + }
58036 +
58037 + if (s_tmp->group_trans_num) {
58038 + gid_t *gidlist;
58039 +
58040 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
58041 + if (gidlist == NULL)
58042 + return ERR_PTR(-ENOMEM);
58043 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
58044 + return ERR_PTR(-EFAULT);
58045 +
58046 + s_tmp->group_transitions = gidlist;
58047 + }
58048 +
58049 + /* set up object hash table */
58050 + num_objs = count_user_objs(ghash.first);
58051 +
58052 + s_tmp->obj_hash_size = num_objs;
58053 + s_tmp->obj_hash =
58054 + (struct acl_object_label **)
58055 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
58056 +
58057 + if (!s_tmp->obj_hash)
58058 + return ERR_PTR(-ENOMEM);
58059 +
58060 + memset(s_tmp->obj_hash, 0,
58061 + s_tmp->obj_hash_size *
58062 + sizeof (struct acl_object_label *));
58063 +
58064 + /* add in objects */
58065 + err = copy_user_objs(ghash.first, s_tmp, role);
58066 +
58067 + if (err)
58068 + return ERR_PTR(err);
58069 +
58070 + /* set pointer for parent subject */
58071 + if (s_tmp->parent_subject) {
58072 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
58073 +
58074 + if (IS_ERR(s_tmp2))
58075 + return s_tmp2;
58076 +
58077 + s_tmp->parent_subject = s_tmp2;
58078 + }
58079 +
58080 + /* add in ip acls */
58081 +
58082 + if (!s_tmp->ip_num) {
58083 + s_tmp->ips = NULL;
58084 + goto insert;
58085 + }
58086 +
58087 + i_tmp =
58088 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
58089 + sizeof (struct acl_ip_label *));
58090 +
58091 + if (!i_tmp)
58092 + return ERR_PTR(-ENOMEM);
58093 +
58094 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
58095 + *(i_tmp + i_num) =
58096 + (struct acl_ip_label *)
58097 + acl_alloc(sizeof (struct acl_ip_label));
58098 + if (!*(i_tmp + i_num))
58099 + return ERR_PTR(-ENOMEM);
58100 +
58101 + if (copy_from_user
58102 + (&i_utmp2, s_tmp->ips + i_num,
58103 + sizeof (struct acl_ip_label *)))
58104 + return ERR_PTR(-EFAULT);
58105 +
58106 + if (copy_from_user
58107 + (*(i_tmp + i_num), i_utmp2,
58108 + sizeof (struct acl_ip_label)))
58109 + return ERR_PTR(-EFAULT);
58110 +
58111 + if ((*(i_tmp + i_num))->iface == NULL)
58112 + continue;
58113 +
58114 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
58115 + if (!len || len >= IFNAMSIZ)
58116 + return ERR_PTR(-EINVAL);
58117 + tmp = acl_alloc(len);
58118 + if (tmp == NULL)
58119 + return ERR_PTR(-ENOMEM);
58120 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
58121 + return ERR_PTR(-EFAULT);
58122 + (*(i_tmp + i_num))->iface = tmp;
58123 + }
58124 +
58125 + s_tmp->ips = i_tmp;
58126 +
58127 +insert:
58128 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
58129 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
58130 + return ERR_PTR(-ENOMEM);
58131 +
58132 + return s_tmp;
58133 +}
58134 +
58135 +static int
58136 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
58137 +{
58138 + struct acl_subject_label s_pre;
58139 + struct acl_subject_label * ret;
58140 + int err;
58141 +
58142 + while (userp) {
58143 + if (copy_from_user(&s_pre, userp,
58144 + sizeof (struct acl_subject_label)))
58145 + return -EFAULT;
58146 +
58147 + ret = do_copy_user_subj(userp, role, NULL);
58148 +
58149 + err = PTR_ERR(ret);
58150 + if (IS_ERR(ret))
58151 + return err;
58152 +
58153 + insert_acl_subj_label(ret, role);
58154 +
58155 + userp = s_pre.prev;
58156 + }
58157 +
58158 + return 0;
58159 +}
58160 +
58161 +static int
58162 +copy_user_acl(struct gr_arg *arg)
58163 +{
58164 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
58165 + struct acl_subject_label *subj_list;
58166 + struct sprole_pw *sptmp;
58167 + struct gr_hash_struct *ghash;
58168 + uid_t *domainlist;
58169 + unsigned int r_num;
58170 + unsigned int len;
58171 + char *tmp;
58172 + int err = 0;
58173 + __u16 i;
58174 + __u32 num_subjs;
58175 +
58176 + /* we need a default and kernel role */
58177 + if (arg->role_db.num_roles < 2)
58178 + return -EINVAL;
58179 +
58180 + /* copy special role authentication info from userspace */
58181 +
58182 + num_sprole_pws = arg->num_sprole_pws;
58183 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
58184 +
58185 + if (!acl_special_roles && num_sprole_pws)
58186 + return -ENOMEM;
58187 +
58188 + for (i = 0; i < num_sprole_pws; i++) {
58189 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
58190 + if (!sptmp)
58191 + return -ENOMEM;
58192 + if (copy_from_user(sptmp, arg->sprole_pws + i,
58193 + sizeof (struct sprole_pw)))
58194 + return -EFAULT;
58195 +
58196 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
58197 +
58198 + if (!len || len >= GR_SPROLE_LEN)
58199 + return -EINVAL;
58200 +
58201 + if ((tmp = (char *) acl_alloc(len)) == NULL)
58202 + return -ENOMEM;
58203 +
58204 + if (copy_from_user(tmp, sptmp->rolename, len))
58205 + return -EFAULT;
58206 +
58207 + tmp[len-1] = '\0';
58208 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58209 + printk(KERN_ALERT "Copying special role %s\n", tmp);
58210 +#endif
58211 + sptmp->rolename = tmp;
58212 + acl_special_roles[i] = sptmp;
58213 + }
58214 +
58215 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
58216 +
58217 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
58218 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
58219 +
58220 + if (!r_tmp)
58221 + return -ENOMEM;
58222 +
58223 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
58224 + sizeof (struct acl_role_label *)))
58225 + return -EFAULT;
58226 +
58227 + if (copy_from_user(r_tmp, r_utmp2,
58228 + sizeof (struct acl_role_label)))
58229 + return -EFAULT;
58230 +
58231 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
58232 +
58233 + if (!len || len >= PATH_MAX)
58234 + return -EINVAL;
58235 +
58236 + if ((tmp = (char *) acl_alloc(len)) == NULL)
58237 + return -ENOMEM;
58238 +
58239 + if (copy_from_user(tmp, r_tmp->rolename, len))
58240 + return -EFAULT;
58241 +
58242 + tmp[len-1] = '\0';
58243 + r_tmp->rolename = tmp;
58244 +
58245 + if (!strcmp(r_tmp->rolename, "default")
58246 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
58247 + default_role = r_tmp;
58248 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
58249 + kernel_role = r_tmp;
58250 + }
58251 +
58252 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
58253 + return -ENOMEM;
58254 +
58255 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
58256 + return -EFAULT;
58257 +
58258 + r_tmp->hash = ghash;
58259 +
58260 + num_subjs = count_user_subjs(r_tmp->hash->first);
58261 +
58262 + r_tmp->subj_hash_size = num_subjs;
58263 + r_tmp->subj_hash =
58264 + (struct acl_subject_label **)
58265 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
58266 +
58267 + if (!r_tmp->subj_hash)
58268 + return -ENOMEM;
58269 +
58270 + err = copy_user_allowedips(r_tmp);
58271 + if (err)
58272 + return err;
58273 +
58274 + /* copy domain info */
58275 + if (r_tmp->domain_children != NULL) {
58276 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
58277 + if (domainlist == NULL)
58278 + return -ENOMEM;
58279 +
58280 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
58281 + return -EFAULT;
58282 +
58283 + r_tmp->domain_children = domainlist;
58284 + }
58285 +
58286 + err = copy_user_transitions(r_tmp);
58287 + if (err)
58288 + return err;
58289 +
58290 + memset(r_tmp->subj_hash, 0,
58291 + r_tmp->subj_hash_size *
58292 + sizeof (struct acl_subject_label *));
58293 +
58294 + /* acquire the list of subjects, then NULL out
58295 + the list prior to parsing the subjects for this role,
58296 + as during this parsing the list is replaced with a list
58297 + of *nested* subjects for the role
58298 + */
58299 + subj_list = r_tmp->hash->first;
58300 +
58301 + /* set nested subject list to null */
58302 + r_tmp->hash->first = NULL;
58303 +
58304 + err = copy_user_subjs(subj_list, r_tmp);
58305 +
58306 + if (err)
58307 + return err;
58308 +
58309 + insert_acl_role_label(r_tmp);
58310 + }
58311 +
58312 + if (default_role == NULL || kernel_role == NULL)
58313 + return -EINVAL;
58314 +
58315 + return err;
58316 +}
58317 +
58318 +static int
58319 +gracl_init(struct gr_arg *args)
58320 +{
58321 + int error = 0;
58322 +
58323 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
58324 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
58325 +
58326 + if (init_variables(args)) {
58327 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
58328 + error = -ENOMEM;
58329 + free_variables();
58330 + goto out;
58331 + }
58332 +
58333 + error = copy_user_acl(args);
58334 + free_init_variables();
58335 + if (error) {
58336 + free_variables();
58337 + goto out;
58338 + }
58339 +
58340 + if ((error = gr_set_acls(0))) {
58341 + free_variables();
58342 + goto out;
58343 + }
58344 +
58345 + pax_open_kernel();
58346 + gr_status |= GR_READY;
58347 + pax_close_kernel();
58348 +
58349 + out:
58350 + return error;
58351 +}
58352 +
58353 +/* derived from glibc fnmatch() 0: match, 1: no match*/
58354 +
58355 +static int
58356 +glob_match(const char *p, const char *n)
58357 +{
58358 + char c;
58359 +
58360 + while ((c = *p++) != '\0') {
58361 + switch (c) {
58362 + case '?':
58363 + if (*n == '\0')
58364 + return 1;
58365 + else if (*n == '/')
58366 + return 1;
58367 + break;
58368 + case '\\':
58369 + if (*n != c)
58370 + return 1;
58371 + break;
58372 + case '*':
58373 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
58374 + if (*n == '/')
58375 + return 1;
58376 + else if (c == '?') {
58377 + if (*n == '\0')
58378 + return 1;
58379 + else
58380 + ++n;
58381 + }
58382 + }
58383 + if (c == '\0') {
58384 + return 0;
58385 + } else {
58386 + const char *endp;
58387 +
58388 + if ((endp = strchr(n, '/')) == NULL)
58389 + endp = n + strlen(n);
58390 +
58391 + if (c == '[') {
58392 + for (--p; n < endp; ++n)
58393 + if (!glob_match(p, n))
58394 + return 0;
58395 + } else if (c == '/') {
58396 + while (*n != '\0' && *n != '/')
58397 + ++n;
58398 + if (*n == '/' && !glob_match(p, n + 1))
58399 + return 0;
58400 + } else {
58401 + for (--p; n < endp; ++n)
58402 + if (*n == c && !glob_match(p, n))
58403 + return 0;
58404 + }
58405 +
58406 + return 1;
58407 + }
58408 + case '[':
58409 + {
58410 + int not;
58411 + char cold;
58412 +
58413 + if (*n == '\0' || *n == '/')
58414 + return 1;
58415 +
58416 + not = (*p == '!' || *p == '^');
58417 + if (not)
58418 + ++p;
58419 +
58420 + c = *p++;
58421 + for (;;) {
58422 + unsigned char fn = (unsigned char)*n;
58423 +
58424 + if (c == '\0')
58425 + return 1;
58426 + else {
58427 + if (c == fn)
58428 + goto matched;
58429 + cold = c;
58430 + c = *p++;
58431 +
58432 + if (c == '-' && *p != ']') {
58433 + unsigned char cend = *p++;
58434 +
58435 + if (cend == '\0')
58436 + return 1;
58437 +
58438 + if (cold <= fn && fn <= cend)
58439 + goto matched;
58440 +
58441 + c = *p++;
58442 + }
58443 + }
58444 +
58445 + if (c == ']')
58446 + break;
58447 + }
58448 + if (!not)
58449 + return 1;
58450 + break;
58451 + matched:
58452 + while (c != ']') {
58453 + if (c == '\0')
58454 + return 1;
58455 +
58456 + c = *p++;
58457 + }
58458 + if (not)
58459 + return 1;
58460 + }
58461 + break;
58462 + default:
58463 + if (c != *n)
58464 + return 1;
58465 + }
58466 +
58467 + ++n;
58468 + }
58469 +
58470 + if (*n == '\0')
58471 + return 0;
58472 +
58473 + if (*n == '/')
58474 + return 0;
58475 +
58476 + return 1;
58477 +}
58478 +
58479 +static struct acl_object_label *
58480 +chk_glob_label(struct acl_object_label *globbed,
58481 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
58482 +{
58483 + struct acl_object_label *tmp;
58484 +
58485 + if (*path == NULL)
58486 + *path = gr_to_filename_nolock(dentry, mnt);
58487 +
58488 + tmp = globbed;
58489 +
58490 + while (tmp) {
58491 + if (!glob_match(tmp->filename, *path))
58492 + return tmp;
58493 + tmp = tmp->next;
58494 + }
58495 +
58496 + return NULL;
58497 +}
58498 +
58499 +static struct acl_object_label *
58500 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
58501 + const ino_t curr_ino, const dev_t curr_dev,
58502 + const struct acl_subject_label *subj, char **path, const int checkglob)
58503 +{
58504 + struct acl_subject_label *tmpsubj;
58505 + struct acl_object_label *retval;
58506 + struct acl_object_label *retval2;
58507 +
58508 + tmpsubj = (struct acl_subject_label *) subj;
58509 + read_lock(&gr_inode_lock);
58510 + do {
58511 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
58512 + if (retval) {
58513 + if (checkglob && retval->globbed) {
58514 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
58515 + if (retval2)
58516 + retval = retval2;
58517 + }
58518 + break;
58519 + }
58520 + } while ((tmpsubj = tmpsubj->parent_subject));
58521 + read_unlock(&gr_inode_lock);
58522 +
58523 + return retval;
58524 +}
58525 +
58526 +static __inline__ struct acl_object_label *
58527 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
58528 + struct dentry *curr_dentry,
58529 + const struct acl_subject_label *subj, char **path, const int checkglob)
58530 +{
58531 + int newglob = checkglob;
58532 + ino_t inode;
58533 + dev_t device;
58534 +
58535 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
58536 + as we don't want a / * rule to match instead of the / object
58537 + don't do this for create lookups that call this function though, since they're looking up
58538 + on the parent and thus need globbing checks on all paths
58539 + */
58540 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
58541 + newglob = GR_NO_GLOB;
58542 +
58543 + spin_lock(&curr_dentry->d_lock);
58544 + inode = curr_dentry->d_inode->i_ino;
58545 + device = __get_dev(curr_dentry);
58546 + spin_unlock(&curr_dentry->d_lock);
58547 +
58548 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
58549 +}
58550 +
58551 +#ifdef CONFIG_HUGETLBFS
58552 +static inline bool
58553 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
58554 +{
58555 + int i;
58556 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
58557 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
58558 + return true;
58559 + }
58560 +
58561 + return false;
58562 +}
58563 +#endif
58564 +
58565 +static struct acl_object_label *
58566 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58567 + const struct acl_subject_label *subj, char *path, const int checkglob)
58568 +{
58569 + struct dentry *dentry = (struct dentry *) l_dentry;
58570 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
58571 + struct mount *real_mnt = real_mount(mnt);
58572 + struct acl_object_label *retval;
58573 + struct dentry *parent;
58574 +
58575 + write_seqlock(&rename_lock);
58576 + br_read_lock(&vfsmount_lock);
58577 +
58578 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
58579 +#ifdef CONFIG_NET
58580 + mnt == sock_mnt ||
58581 +#endif
58582 +#ifdef CONFIG_HUGETLBFS
58583 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
58584 +#endif
58585 + /* ignore Eric Biederman */
58586 + IS_PRIVATE(l_dentry->d_inode))) {
58587 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
58588 + goto out;
58589 + }
58590 +
58591 + for (;;) {
58592 + if (dentry == real_root.dentry && mnt == real_root.mnt)
58593 + break;
58594 +
58595 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
58596 + if (!mnt_has_parent(real_mnt))
58597 + break;
58598 +
58599 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58600 + if (retval != NULL)
58601 + goto out;
58602 +
58603 + dentry = real_mnt->mnt_mountpoint;
58604 + real_mnt = real_mnt->mnt_parent;
58605 + mnt = &real_mnt->mnt;
58606 + continue;
58607 + }
58608 +
58609 + parent = dentry->d_parent;
58610 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58611 + if (retval != NULL)
58612 + goto out;
58613 +
58614 + dentry = parent;
58615 + }
58616 +
58617 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58618 +
58619 + /* real_root is pinned so we don't have to hold a reference */
58620 + if (retval == NULL)
58621 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
58622 +out:
58623 + br_read_unlock(&vfsmount_lock);
58624 + write_sequnlock(&rename_lock);
58625 +
58626 + BUG_ON(retval == NULL);
58627 +
58628 + return retval;
58629 +}
58630 +
58631 +static __inline__ struct acl_object_label *
58632 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58633 + const struct acl_subject_label *subj)
58634 +{
58635 + char *path = NULL;
58636 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
58637 +}
58638 +
58639 +static __inline__ struct acl_object_label *
58640 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58641 + const struct acl_subject_label *subj)
58642 +{
58643 + char *path = NULL;
58644 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
58645 +}
58646 +
58647 +static __inline__ struct acl_object_label *
58648 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58649 + const struct acl_subject_label *subj, char *path)
58650 +{
58651 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
58652 +}
58653 +
58654 +static struct acl_subject_label *
58655 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58656 + const struct acl_role_label *role)
58657 +{
58658 + struct dentry *dentry = (struct dentry *) l_dentry;
58659 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
58660 + struct mount *real_mnt = real_mount(mnt);
58661 + struct acl_subject_label *retval;
58662 + struct dentry *parent;
58663 +
58664 + write_seqlock(&rename_lock);
58665 + br_read_lock(&vfsmount_lock);
58666 +
58667 + for (;;) {
58668 + if (dentry == real_root.dentry && mnt == real_root.mnt)
58669 + break;
58670 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
58671 + if (!mnt_has_parent(real_mnt))
58672 + break;
58673 +
58674 + spin_lock(&dentry->d_lock);
58675 + read_lock(&gr_inode_lock);
58676 + retval =
58677 + lookup_acl_subj_label(dentry->d_inode->i_ino,
58678 + __get_dev(dentry), role);
58679 + read_unlock(&gr_inode_lock);
58680 + spin_unlock(&dentry->d_lock);
58681 + if (retval != NULL)
58682 + goto out;
58683 +
58684 + dentry = real_mnt->mnt_mountpoint;
58685 + real_mnt = real_mnt->mnt_parent;
58686 + mnt = &real_mnt->mnt;
58687 + continue;
58688 + }
58689 +
58690 + spin_lock(&dentry->d_lock);
58691 + read_lock(&gr_inode_lock);
58692 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
58693 + __get_dev(dentry), role);
58694 + read_unlock(&gr_inode_lock);
58695 + parent = dentry->d_parent;
58696 + spin_unlock(&dentry->d_lock);
58697 +
58698 + if (retval != NULL)
58699 + goto out;
58700 +
58701 + dentry = parent;
58702 + }
58703 +
58704 + spin_lock(&dentry->d_lock);
58705 + read_lock(&gr_inode_lock);
58706 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
58707 + __get_dev(dentry), role);
58708 + read_unlock(&gr_inode_lock);
58709 + spin_unlock(&dentry->d_lock);
58710 +
58711 + if (unlikely(retval == NULL)) {
58712 + /* real_root is pinned, we don't need to hold a reference */
58713 + read_lock(&gr_inode_lock);
58714 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
58715 + __get_dev(real_root.dentry), role);
58716 + read_unlock(&gr_inode_lock);
58717 + }
58718 +out:
58719 + br_read_unlock(&vfsmount_lock);
58720 + write_sequnlock(&rename_lock);
58721 +
58722 + BUG_ON(retval == NULL);
58723 +
58724 + return retval;
58725 +}
58726 +
58727 +static void
58728 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
58729 +{
58730 + struct task_struct *task = current;
58731 + const struct cred *cred = current_cred();
58732 +
58733 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
58734 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58735 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58736 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
58737 +
58738 + return;
58739 +}
58740 +
58741 +static void
58742 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
58743 +{
58744 + struct task_struct *task = current;
58745 + const struct cred *cred = current_cred();
58746 +
58747 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
58748 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58749 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58750 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
58751 +
58752 + return;
58753 +}
58754 +
58755 +static void
58756 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
58757 +{
58758 + struct task_struct *task = current;
58759 + const struct cred *cred = current_cred();
58760 +
58761 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
58762 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58763 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58764 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
58765 +
58766 + return;
58767 +}
58768 +
58769 +__u32
58770 +gr_search_file(const struct dentry * dentry, const __u32 mode,
58771 + const struct vfsmount * mnt)
58772 +{
58773 + __u32 retval = mode;
58774 + struct acl_subject_label *curracl;
58775 + struct acl_object_label *currobj;
58776 +
58777 + if (unlikely(!(gr_status & GR_READY)))
58778 + return (mode & ~GR_AUDITS);
58779 +
58780 + curracl = current->acl;
58781 +
58782 + currobj = chk_obj_label(dentry, mnt, curracl);
58783 + retval = currobj->mode & mode;
58784 +
58785 + /* if we're opening a specified transfer file for writing
58786 + (e.g. /dev/initctl), then transfer our role to init
58787 + */
58788 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
58789 + current->role->roletype & GR_ROLE_PERSIST)) {
58790 + struct task_struct *task = init_pid_ns.child_reaper;
58791 +
58792 + if (task->role != current->role) {
58793 + task->acl_sp_role = 0;
58794 + task->acl_role_id = current->acl_role_id;
58795 + task->role = current->role;
58796 + rcu_read_lock();
58797 + read_lock(&grsec_exec_file_lock);
58798 + gr_apply_subject_to_task(task);
58799 + read_unlock(&grsec_exec_file_lock);
58800 + rcu_read_unlock();
58801 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
58802 + }
58803 + }
58804 +
58805 + if (unlikely
58806 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
58807 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
58808 + __u32 new_mode = mode;
58809 +
58810 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
58811 +
58812 + retval = new_mode;
58813 +
58814 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
58815 + new_mode |= GR_INHERIT;
58816 +
58817 + if (!(mode & GR_NOLEARN))
58818 + gr_log_learn(dentry, mnt, new_mode);
58819 + }
58820 +
58821 + return retval;
58822 +}
58823 +
58824 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
58825 + const struct dentry *parent,
58826 + const struct vfsmount *mnt)
58827 +{
58828 + struct name_entry *match;
58829 + struct acl_object_label *matchpo;
58830 + struct acl_subject_label *curracl;
58831 + char *path;
58832 +
58833 + if (unlikely(!(gr_status & GR_READY)))
58834 + return NULL;
58835 +
58836 + preempt_disable();
58837 + path = gr_to_filename_rbac(new_dentry, mnt);
58838 + match = lookup_name_entry_create(path);
58839 +
58840 + curracl = current->acl;
58841 +
58842 + if (match) {
58843 + read_lock(&gr_inode_lock);
58844 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
58845 + read_unlock(&gr_inode_lock);
58846 +
58847 + if (matchpo) {
58848 + preempt_enable();
58849 + return matchpo;
58850 + }
58851 + }
58852 +
58853 + // lookup parent
58854 +
58855 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
58856 +
58857 + preempt_enable();
58858 + return matchpo;
58859 +}
58860 +
58861 +__u32
58862 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
58863 + const struct vfsmount * mnt, const __u32 mode)
58864 +{
58865 + struct acl_object_label *matchpo;
58866 + __u32 retval;
58867 +
58868 + if (unlikely(!(gr_status & GR_READY)))
58869 + return (mode & ~GR_AUDITS);
58870 +
58871 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
58872 +
58873 + retval = matchpo->mode & mode;
58874 +
58875 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
58876 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
58877 + __u32 new_mode = mode;
58878 +
58879 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
58880 +
58881 + gr_log_learn(new_dentry, mnt, new_mode);
58882 + return new_mode;
58883 + }
58884 +
58885 + return retval;
58886 +}
58887 +
58888 +__u32
58889 +gr_check_link(const struct dentry * new_dentry,
58890 + const struct dentry * parent_dentry,
58891 + const struct vfsmount * parent_mnt,
58892 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
58893 +{
58894 + struct acl_object_label *obj;
58895 + __u32 oldmode, newmode;
58896 + __u32 needmode;
58897 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
58898 + GR_DELETE | GR_INHERIT;
58899 +
58900 + if (unlikely(!(gr_status & GR_READY)))
58901 + return (GR_CREATE | GR_LINK);
58902 +
58903 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
58904 + oldmode = obj->mode;
58905 +
58906 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
58907 + newmode = obj->mode;
58908 +
58909 + needmode = newmode & checkmodes;
58910 +
58911 + // old name for hardlink must have at least the permissions of the new name
58912 + if ((oldmode & needmode) != needmode)
58913 + goto bad;
58914 +
58915 + // if old name had restrictions/auditing, make sure the new name does as well
58916 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
58917 +
58918 + // don't allow hardlinking of suid/sgid/fcapped files without permission
58919 + if (is_privileged_binary(old_dentry))
58920 + needmode |= GR_SETID;
58921 +
58922 + if ((newmode & needmode) != needmode)
58923 + goto bad;
58924 +
58925 + // enforce minimum permissions
58926 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
58927 + return newmode;
58928 +bad:
58929 + needmode = oldmode;
58930 + if (is_privileged_binary(old_dentry))
58931 + needmode |= GR_SETID;
58932 +
58933 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
58934 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
58935 + return (GR_CREATE | GR_LINK);
58936 + } else if (newmode & GR_SUPPRESS)
58937 + return GR_SUPPRESS;
58938 + else
58939 + return 0;
58940 +}
58941 +
58942 +int
58943 +gr_check_hidden_task(const struct task_struct *task)
58944 +{
58945 + if (unlikely(!(gr_status & GR_READY)))
58946 + return 0;
58947 +
58948 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
58949 + return 1;
58950 +
58951 + return 0;
58952 +}
58953 +
58954 +int
58955 +gr_check_protected_task(const struct task_struct *task)
58956 +{
58957 + if (unlikely(!(gr_status & GR_READY) || !task))
58958 + return 0;
58959 +
58960 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
58961 + task->acl != current->acl)
58962 + return 1;
58963 +
58964 + return 0;
58965 +}
58966 +
58967 +int
58968 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
58969 +{
58970 + struct task_struct *p;
58971 + int ret = 0;
58972 +
58973 + if (unlikely(!(gr_status & GR_READY) || !pid))
58974 + return ret;
58975 +
58976 + read_lock(&tasklist_lock);
58977 + do_each_pid_task(pid, type, p) {
58978 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
58979 + p->acl != current->acl) {
58980 + ret = 1;
58981 + goto out;
58982 + }
58983 + } while_each_pid_task(pid, type, p);
58984 +out:
58985 + read_unlock(&tasklist_lock);
58986 +
58987 + return ret;
58988 +}
58989 +
58990 +void
58991 +gr_copy_label(struct task_struct *tsk)
58992 +{
58993 + tsk->signal->used_accept = 0;
58994 + tsk->acl_sp_role = 0;
58995 + tsk->acl_role_id = current->acl_role_id;
58996 + tsk->acl = current->acl;
58997 + tsk->role = current->role;
58998 + tsk->signal->curr_ip = current->signal->curr_ip;
58999 + tsk->signal->saved_ip = current->signal->saved_ip;
59000 + if (current->exec_file)
59001 + get_file(current->exec_file);
59002 + tsk->exec_file = current->exec_file;
59003 + tsk->is_writable = current->is_writable;
59004 + if (unlikely(current->signal->used_accept)) {
59005 + current->signal->curr_ip = 0;
59006 + current->signal->saved_ip = 0;
59007 + }
59008 +
59009 + return;
59010 +}
59011 +
59012 +static void
59013 +gr_set_proc_res(struct task_struct *task)
59014 +{
59015 + struct acl_subject_label *proc;
59016 + unsigned short i;
59017 +
59018 + proc = task->acl;
59019 +
59020 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
59021 + return;
59022 +
59023 + for (i = 0; i < RLIM_NLIMITS; i++) {
59024 + if (!(proc->resmask & (1 << i)))
59025 + continue;
59026 +
59027 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
59028 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
59029 + }
59030 +
59031 + return;
59032 +}
59033 +
59034 +extern int __gr_process_user_ban(struct user_struct *user);
59035 +
59036 +int
59037 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
59038 +{
59039 + unsigned int i;
59040 + __u16 num;
59041 + uid_t *uidlist;
59042 + uid_t curuid;
59043 + int realok = 0;
59044 + int effectiveok = 0;
59045 + int fsok = 0;
59046 + uid_t globalreal, globaleffective, globalfs;
59047 +
59048 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59049 + struct user_struct *user;
59050 +
59051 + if (!uid_valid(real))
59052 + goto skipit;
59053 +
59054 + /* find user based on global namespace */
59055 +
59056 + globalreal = GR_GLOBAL_UID(real);
59057 +
59058 + user = find_user(make_kuid(&init_user_ns, globalreal));
59059 + if (user == NULL)
59060 + goto skipit;
59061 +
59062 + if (__gr_process_user_ban(user)) {
59063 + /* for find_user */
59064 + free_uid(user);
59065 + return 1;
59066 + }
59067 +
59068 + /* for find_user */
59069 + free_uid(user);
59070 +
59071 +skipit:
59072 +#endif
59073 +
59074 + if (unlikely(!(gr_status & GR_READY)))
59075 + return 0;
59076 +
59077 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59078 + gr_log_learn_uid_change(real, effective, fs);
59079 +
59080 + num = current->acl->user_trans_num;
59081 + uidlist = current->acl->user_transitions;
59082 +
59083 + if (uidlist == NULL)
59084 + return 0;
59085 +
59086 + if (!uid_valid(real)) {
59087 + realok = 1;
59088 + globalreal = (uid_t)-1;
59089 + } else {
59090 + globalreal = GR_GLOBAL_UID(real);
59091 + }
59092 + if (!uid_valid(effective)) {
59093 + effectiveok = 1;
59094 + globaleffective = (uid_t)-1;
59095 + } else {
59096 + globaleffective = GR_GLOBAL_UID(effective);
59097 + }
59098 + if (!uid_valid(fs)) {
59099 + fsok = 1;
59100 + globalfs = (uid_t)-1;
59101 + } else {
59102 + globalfs = GR_GLOBAL_UID(fs);
59103 + }
59104 +
59105 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
59106 + for (i = 0; i < num; i++) {
59107 + curuid = uidlist[i];
59108 + if (globalreal == curuid)
59109 + realok = 1;
59110 + if (globaleffective == curuid)
59111 + effectiveok = 1;
59112 + if (globalfs == curuid)
59113 + fsok = 1;
59114 + }
59115 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
59116 + for (i = 0; i < num; i++) {
59117 + curuid = uidlist[i];
59118 + if (globalreal == curuid)
59119 + break;
59120 + if (globaleffective == curuid)
59121 + break;
59122 + if (globalfs == curuid)
59123 + break;
59124 + }
59125 + /* not in deny list */
59126 + if (i == num) {
59127 + realok = 1;
59128 + effectiveok = 1;
59129 + fsok = 1;
59130 + }
59131 + }
59132 +
59133 + if (realok && effectiveok && fsok)
59134 + return 0;
59135 + else {
59136 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59137 + return 1;
59138 + }
59139 +}
59140 +
59141 +int
59142 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
59143 +{
59144 + unsigned int i;
59145 + __u16 num;
59146 + gid_t *gidlist;
59147 + gid_t curgid;
59148 + int realok = 0;
59149 + int effectiveok = 0;
59150 + int fsok = 0;
59151 + gid_t globalreal, globaleffective, globalfs;
59152 +
59153 + if (unlikely(!(gr_status & GR_READY)))
59154 + return 0;
59155 +
59156 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59157 + gr_log_learn_gid_change(real, effective, fs);
59158 +
59159 + num = current->acl->group_trans_num;
59160 + gidlist = current->acl->group_transitions;
59161 +
59162 + if (gidlist == NULL)
59163 + return 0;
59164 +
59165 + if (!gid_valid(real)) {
59166 + realok = 1;
59167 + globalreal = (gid_t)-1;
59168 + } else {
59169 + globalreal = GR_GLOBAL_GID(real);
59170 + }
59171 + if (!gid_valid(effective)) {
59172 + effectiveok = 1;
59173 + globaleffective = (gid_t)-1;
59174 + } else {
59175 + globaleffective = GR_GLOBAL_GID(effective);
59176 + }
59177 + if (!gid_valid(fs)) {
59178 + fsok = 1;
59179 + globalfs = (gid_t)-1;
59180 + } else {
59181 + globalfs = GR_GLOBAL_GID(fs);
59182 + }
59183 +
59184 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
59185 + for (i = 0; i < num; i++) {
59186 + curgid = gidlist[i];
59187 + if (globalreal == curgid)
59188 + realok = 1;
59189 + if (globaleffective == curgid)
59190 + effectiveok = 1;
59191 + if (globalfs == curgid)
59192 + fsok = 1;
59193 + }
59194 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
59195 + for (i = 0; i < num; i++) {
59196 + curgid = gidlist[i];
59197 + if (globalreal == curgid)
59198 + break;
59199 + if (globaleffective == curgid)
59200 + break;
59201 + if (globalfs == curgid)
59202 + break;
59203 + }
59204 + /* not in deny list */
59205 + if (i == num) {
59206 + realok = 1;
59207 + effectiveok = 1;
59208 + fsok = 1;
59209 + }
59210 + }
59211 +
59212 + if (realok && effectiveok && fsok)
59213 + return 0;
59214 + else {
59215 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59216 + return 1;
59217 + }
59218 +}
59219 +
59220 +extern int gr_acl_is_capable(const int cap);
59221 +
59222 +void
59223 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
59224 +{
59225 + struct acl_role_label *role = task->role;
59226 + struct acl_subject_label *subj = NULL;
59227 + struct acl_object_label *obj;
59228 + struct file *filp;
59229 + uid_t uid;
59230 + gid_t gid;
59231 +
59232 + if (unlikely(!(gr_status & GR_READY)))
59233 + return;
59234 +
59235 + uid = GR_GLOBAL_UID(kuid);
59236 + gid = GR_GLOBAL_GID(kgid);
59237 +
59238 + filp = task->exec_file;
59239 +
59240 + /* kernel process, we'll give them the kernel role */
59241 + if (unlikely(!filp)) {
59242 + task->role = kernel_role;
59243 + task->acl = kernel_role->root_label;
59244 + return;
59245 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
59246 + role = lookup_acl_role_label(task, uid, gid);
59247 +
59248 + /* don't change the role if we're not a privileged process */
59249 + if (role && task->role != role &&
59250 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
59251 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
59252 + return;
59253 +
59254 + /* perform subject lookup in possibly new role
59255 + we can use this result below in the case where role == task->role
59256 + */
59257 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
59258 +
59259 + /* if we changed uid/gid, but result in the same role
59260 + and are using inheritance, don't lose the inherited subject
59261 + if current subject is other than what normal lookup
59262 + would result in, we arrived via inheritance, don't
59263 + lose subject
59264 + */
59265 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
59266 + (subj == task->acl)))
59267 + task->acl = subj;
59268 +
59269 + task->role = role;
59270 +
59271 + task->is_writable = 0;
59272 +
59273 + /* ignore additional mmap checks for processes that are writable
59274 + by the default ACL */
59275 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59276 + if (unlikely(obj->mode & GR_WRITE))
59277 + task->is_writable = 1;
59278 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
59279 + if (unlikely(obj->mode & GR_WRITE))
59280 + task->is_writable = 1;
59281 +
59282 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59283 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
59284 +#endif
59285 +
59286 + gr_set_proc_res(task);
59287 +
59288 + return;
59289 +}
59290 +
59291 +int
59292 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59293 + const int unsafe_flags)
59294 +{
59295 + struct task_struct *task = current;
59296 + struct acl_subject_label *newacl;
59297 + struct acl_object_label *obj;
59298 + __u32 retmode;
59299 +
59300 + if (unlikely(!(gr_status & GR_READY)))
59301 + return 0;
59302 +
59303 + newacl = chk_subj_label(dentry, mnt, task->role);
59304 +
59305 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
59306 + did an exec
59307 + */
59308 + rcu_read_lock();
59309 + read_lock(&tasklist_lock);
59310 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
59311 + (task->parent->acl->mode & GR_POVERRIDE))) {
59312 + read_unlock(&tasklist_lock);
59313 + rcu_read_unlock();
59314 + goto skip_check;
59315 + }
59316 + read_unlock(&tasklist_lock);
59317 + rcu_read_unlock();
59318 +
59319 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
59320 + !(task->role->roletype & GR_ROLE_GOD) &&
59321 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
59322 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59323 + if (unsafe_flags & LSM_UNSAFE_SHARE)
59324 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
59325 + else
59326 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
59327 + return -EACCES;
59328 + }
59329 +
59330 +skip_check:
59331 +
59332 + obj = chk_obj_label(dentry, mnt, task->acl);
59333 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
59334 +
59335 + if (!(task->acl->mode & GR_INHERITLEARN) &&
59336 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
59337 + if (obj->nested)
59338 + task->acl = obj->nested;
59339 + else
59340 + task->acl = newacl;
59341 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
59342 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
59343 +
59344 + task->is_writable = 0;
59345 +
59346 + /* ignore additional mmap checks for processes that are writable
59347 + by the default ACL */
59348 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
59349 + if (unlikely(obj->mode & GR_WRITE))
59350 + task->is_writable = 1;
59351 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
59352 + if (unlikely(obj->mode & GR_WRITE))
59353 + task->is_writable = 1;
59354 +
59355 + gr_set_proc_res(task);
59356 +
59357 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59358 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
59359 +#endif
59360 + return 0;
59361 +}
59362 +
59363 +/* always called with valid inodev ptr */
59364 +static void
59365 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
59366 +{
59367 + struct acl_object_label *matchpo;
59368 + struct acl_subject_label *matchps;
59369 + struct acl_subject_label *subj;
59370 + struct acl_role_label *role;
59371 + unsigned int x;
59372 +
59373 + FOR_EACH_ROLE_START(role)
59374 + FOR_EACH_SUBJECT_START(role, subj, x)
59375 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59376 + matchpo->mode |= GR_DELETED;
59377 + FOR_EACH_SUBJECT_END(subj,x)
59378 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
59379 + /* nested subjects aren't in the role's subj_hash table */
59380 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59381 + matchpo->mode |= GR_DELETED;
59382 + FOR_EACH_NESTED_SUBJECT_END(subj)
59383 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
59384 + matchps->mode |= GR_DELETED;
59385 + FOR_EACH_ROLE_END(role)
59386 +
59387 + inodev->nentry->deleted = 1;
59388 +
59389 + return;
59390 +}
59391 +
59392 +void
59393 +gr_handle_delete(const ino_t ino, const dev_t dev)
59394 +{
59395 + struct inodev_entry *inodev;
59396 +
59397 + if (unlikely(!(gr_status & GR_READY)))
59398 + return;
59399 +
59400 + write_lock(&gr_inode_lock);
59401 + inodev = lookup_inodev_entry(ino, dev);
59402 + if (inodev != NULL)
59403 + do_handle_delete(inodev, ino, dev);
59404 + write_unlock(&gr_inode_lock);
59405 +
59406 + return;
59407 +}
59408 +
59409 +static void
59410 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
59411 + const ino_t newinode, const dev_t newdevice,
59412 + struct acl_subject_label *subj)
59413 +{
59414 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
59415 + struct acl_object_label *match;
59416 +
59417 + match = subj->obj_hash[index];
59418 +
59419 + while (match && (match->inode != oldinode ||
59420 + match->device != olddevice ||
59421 + !(match->mode & GR_DELETED)))
59422 + match = match->next;
59423 +
59424 + if (match && (match->inode == oldinode)
59425 + && (match->device == olddevice)
59426 + && (match->mode & GR_DELETED)) {
59427 + if (match->prev == NULL) {
59428 + subj->obj_hash[index] = match->next;
59429 + if (match->next != NULL)
59430 + match->next->prev = NULL;
59431 + } else {
59432 + match->prev->next = match->next;
59433 + if (match->next != NULL)
59434 + match->next->prev = match->prev;
59435 + }
59436 + match->prev = NULL;
59437 + match->next = NULL;
59438 + match->inode = newinode;
59439 + match->device = newdevice;
59440 + match->mode &= ~GR_DELETED;
59441 +
59442 + insert_acl_obj_label(match, subj);
59443 + }
59444 +
59445 + return;
59446 +}
59447 +
59448 +static void
59449 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
59450 + const ino_t newinode, const dev_t newdevice,
59451 + struct acl_role_label *role)
59452 +{
59453 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
59454 + struct acl_subject_label *match;
59455 +
59456 + match = role->subj_hash[index];
59457 +
59458 + while (match && (match->inode != oldinode ||
59459 + match->device != olddevice ||
59460 + !(match->mode & GR_DELETED)))
59461 + match = match->next;
59462 +
59463 + if (match && (match->inode == oldinode)
59464 + && (match->device == olddevice)
59465 + && (match->mode & GR_DELETED)) {
59466 + if (match->prev == NULL) {
59467 + role->subj_hash[index] = match->next;
59468 + if (match->next != NULL)
59469 + match->next->prev = NULL;
59470 + } else {
59471 + match->prev->next = match->next;
59472 + if (match->next != NULL)
59473 + match->next->prev = match->prev;
59474 + }
59475 + match->prev = NULL;
59476 + match->next = NULL;
59477 + match->inode = newinode;
59478 + match->device = newdevice;
59479 + match->mode &= ~GR_DELETED;
59480 +
59481 + insert_acl_subj_label(match, role);
59482 + }
59483 +
59484 + return;
59485 +}
59486 +
59487 +static void
59488 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
59489 + const ino_t newinode, const dev_t newdevice)
59490 +{
59491 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
59492 + struct inodev_entry *match;
59493 +
59494 + match = inodev_set.i_hash[index];
59495 +
59496 + while (match && (match->nentry->inode != oldinode ||
59497 + match->nentry->device != olddevice || !match->nentry->deleted))
59498 + match = match->next;
59499 +
59500 + if (match && (match->nentry->inode == oldinode)
59501 + && (match->nentry->device == olddevice) &&
59502 + match->nentry->deleted) {
59503 + if (match->prev == NULL) {
59504 + inodev_set.i_hash[index] = match->next;
59505 + if (match->next != NULL)
59506 + match->next->prev = NULL;
59507 + } else {
59508 + match->prev->next = match->next;
59509 + if (match->next != NULL)
59510 + match->next->prev = match->prev;
59511 + }
59512 + match->prev = NULL;
59513 + match->next = NULL;
59514 + match->nentry->inode = newinode;
59515 + match->nentry->device = newdevice;
59516 + match->nentry->deleted = 0;
59517 +
59518 + insert_inodev_entry(match);
59519 + }
59520 +
59521 + return;
59522 +}
59523 +
59524 +static void
59525 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
59526 +{
59527 + struct acl_subject_label *subj;
59528 + struct acl_role_label *role;
59529 + unsigned int x;
59530 +
59531 + FOR_EACH_ROLE_START(role)
59532 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
59533 +
59534 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
59535 + if ((subj->inode == ino) && (subj->device == dev)) {
59536 + subj->inode = ino;
59537 + subj->device = dev;
59538 + }
59539 + /* nested subjects aren't in the role's subj_hash table */
59540 + update_acl_obj_label(matchn->inode, matchn->device,
59541 + ino, dev, subj);
59542 + FOR_EACH_NESTED_SUBJECT_END(subj)
59543 + FOR_EACH_SUBJECT_START(role, subj, x)
59544 + update_acl_obj_label(matchn->inode, matchn->device,
59545 + ino, dev, subj);
59546 + FOR_EACH_SUBJECT_END(subj,x)
59547 + FOR_EACH_ROLE_END(role)
59548 +
59549 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
59550 +
59551 + return;
59552 +}
59553 +
59554 +static void
59555 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
59556 + const struct vfsmount *mnt)
59557 +{
59558 + ino_t ino = dentry->d_inode->i_ino;
59559 + dev_t dev = __get_dev(dentry);
59560 +
59561 + __do_handle_create(matchn, ino, dev);
59562 +
59563 + return;
59564 +}
59565 +
59566 +void
59567 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59568 +{
59569 + struct name_entry *matchn;
59570 +
59571 + if (unlikely(!(gr_status & GR_READY)))
59572 + return;
59573 +
59574 + preempt_disable();
59575 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
59576 +
59577 + if (unlikely((unsigned long)matchn)) {
59578 + write_lock(&gr_inode_lock);
59579 + do_handle_create(matchn, dentry, mnt);
59580 + write_unlock(&gr_inode_lock);
59581 + }
59582 + preempt_enable();
59583 +
59584 + return;
59585 +}
59586 +
59587 +void
59588 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59589 +{
59590 + struct name_entry *matchn;
59591 +
59592 + if (unlikely(!(gr_status & GR_READY)))
59593 + return;
59594 +
59595 + preempt_disable();
59596 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
59597 +
59598 + if (unlikely((unsigned long)matchn)) {
59599 + write_lock(&gr_inode_lock);
59600 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
59601 + write_unlock(&gr_inode_lock);
59602 + }
59603 + preempt_enable();
59604 +
59605 + return;
59606 +}
59607 +
59608 +void
59609 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59610 + struct dentry *old_dentry,
59611 + struct dentry *new_dentry,
59612 + struct vfsmount *mnt, const __u8 replace)
59613 +{
59614 + struct name_entry *matchn;
59615 + struct inodev_entry *inodev;
59616 + struct inode *inode = new_dentry->d_inode;
59617 + ino_t old_ino = old_dentry->d_inode->i_ino;
59618 + dev_t old_dev = __get_dev(old_dentry);
59619 +
59620 + /* vfs_rename swaps the name and parent link for old_dentry and
59621 + new_dentry
59622 + at this point, old_dentry has the new name, parent link, and inode
59623 + for the renamed file
59624 + if a file is being replaced by a rename, new_dentry has the inode
59625 + and name for the replaced file
59626 + */
59627 +
59628 + if (unlikely(!(gr_status & GR_READY)))
59629 + return;
59630 +
59631 + preempt_disable();
59632 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
59633 +
59634 + /* we wouldn't have to check d_inode if it weren't for
59635 + NFS silly-renaming
59636 + */
59637 +
59638 + write_lock(&gr_inode_lock);
59639 + if (unlikely(replace && inode)) {
59640 + ino_t new_ino = inode->i_ino;
59641 + dev_t new_dev = __get_dev(new_dentry);
59642 +
59643 + inodev = lookup_inodev_entry(new_ino, new_dev);
59644 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
59645 + do_handle_delete(inodev, new_ino, new_dev);
59646 + }
59647 +
59648 + inodev = lookup_inodev_entry(old_ino, old_dev);
59649 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
59650 + do_handle_delete(inodev, old_ino, old_dev);
59651 +
59652 + if (unlikely((unsigned long)matchn))
59653 + do_handle_create(matchn, old_dentry, mnt);
59654 +
59655 + write_unlock(&gr_inode_lock);
59656 + preempt_enable();
59657 +
59658 + return;
59659 +}
59660 +
59661 +static int
59662 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
59663 + unsigned char **sum)
59664 +{
59665 + struct acl_role_label *r;
59666 + struct role_allowed_ip *ipp;
59667 + struct role_transition *trans;
59668 + unsigned int i;
59669 + int found = 0;
59670 + u32 curr_ip = current->signal->curr_ip;
59671 +
59672 + current->signal->saved_ip = curr_ip;
59673 +
59674 + /* check transition table */
59675 +
59676 + for (trans = current->role->transitions; trans; trans = trans->next) {
59677 + if (!strcmp(rolename, trans->rolename)) {
59678 + found = 1;
59679 + break;
59680 + }
59681 + }
59682 +
59683 + if (!found)
59684 + return 0;
59685 +
59686 + /* handle special roles that do not require authentication
59687 + and check ip */
59688 +
59689 + FOR_EACH_ROLE_START(r)
59690 + if (!strcmp(rolename, r->rolename) &&
59691 + (r->roletype & GR_ROLE_SPECIAL)) {
59692 + found = 0;
59693 + if (r->allowed_ips != NULL) {
59694 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
59695 + if ((ntohl(curr_ip) & ipp->netmask) ==
59696 + (ntohl(ipp->addr) & ipp->netmask))
59697 + found = 1;
59698 + }
59699 + } else
59700 + found = 2;
59701 + if (!found)
59702 + return 0;
59703 +
59704 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
59705 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
59706 + *salt = NULL;
59707 + *sum = NULL;
59708 + return 1;
59709 + }
59710 + }
59711 + FOR_EACH_ROLE_END(r)
59712 +
59713 + for (i = 0; i < num_sprole_pws; i++) {
59714 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
59715 + *salt = acl_special_roles[i]->salt;
59716 + *sum = acl_special_roles[i]->sum;
59717 + return 1;
59718 + }
59719 + }
59720 +
59721 + return 0;
59722 +}
59723 +
59724 +static void
59725 +assign_special_role(char *rolename)
59726 +{
59727 + struct acl_object_label *obj;
59728 + struct acl_role_label *r;
59729 + struct acl_role_label *assigned = NULL;
59730 + struct task_struct *tsk;
59731 + struct file *filp;
59732 +
59733 + FOR_EACH_ROLE_START(r)
59734 + if (!strcmp(rolename, r->rolename) &&
59735 + (r->roletype & GR_ROLE_SPECIAL)) {
59736 + assigned = r;
59737 + break;
59738 + }
59739 + FOR_EACH_ROLE_END(r)
59740 +
59741 + if (!assigned)
59742 + return;
59743 +
59744 + read_lock(&tasklist_lock);
59745 + read_lock(&grsec_exec_file_lock);
59746 +
59747 + tsk = current->real_parent;
59748 + if (tsk == NULL)
59749 + goto out_unlock;
59750 +
59751 + filp = tsk->exec_file;
59752 + if (filp == NULL)
59753 + goto out_unlock;
59754 +
59755 + tsk->is_writable = 0;
59756 +
59757 + tsk->acl_sp_role = 1;
59758 + tsk->acl_role_id = ++acl_sp_role_value;
59759 + tsk->role = assigned;
59760 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
59761 +
59762 + /* ignore additional mmap checks for processes that are writable
59763 + by the default ACL */
59764 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59765 + if (unlikely(obj->mode & GR_WRITE))
59766 + tsk->is_writable = 1;
59767 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
59768 + if (unlikely(obj->mode & GR_WRITE))
59769 + tsk->is_writable = 1;
59770 +
59771 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59772 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
59773 +#endif
59774 +
59775 +out_unlock:
59776 + read_unlock(&grsec_exec_file_lock);
59777 + read_unlock(&tasklist_lock);
59778 + return;
59779 +}
59780 +
59781 +int gr_check_secure_terminal(struct task_struct *task)
59782 +{
59783 + struct task_struct *p, *p2, *p3;
59784 + struct files_struct *files;
59785 + struct fdtable *fdt;
59786 + struct file *our_file = NULL, *file;
59787 + int i;
59788 +
59789 + if (task->signal->tty == NULL)
59790 + return 1;
59791 +
59792 + files = get_files_struct(task);
59793 + if (files != NULL) {
59794 + rcu_read_lock();
59795 + fdt = files_fdtable(files);
59796 + for (i=0; i < fdt->max_fds; i++) {
59797 + file = fcheck_files(files, i);
59798 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
59799 + get_file(file);
59800 + our_file = file;
59801 + }
59802 + }
59803 + rcu_read_unlock();
59804 + put_files_struct(files);
59805 + }
59806 +
59807 + if (our_file == NULL)
59808 + return 1;
59809 +
59810 + read_lock(&tasklist_lock);
59811 + do_each_thread(p2, p) {
59812 + files = get_files_struct(p);
59813 + if (files == NULL ||
59814 + (p->signal && p->signal->tty == task->signal->tty)) {
59815 + if (files != NULL)
59816 + put_files_struct(files);
59817 + continue;
59818 + }
59819 + rcu_read_lock();
59820 + fdt = files_fdtable(files);
59821 + for (i=0; i < fdt->max_fds; i++) {
59822 + file = fcheck_files(files, i);
59823 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
59824 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
59825 + p3 = task;
59826 + while (task_pid_nr(p3) > 0) {
59827 + if (p3 == p)
59828 + break;
59829 + p3 = p3->real_parent;
59830 + }
59831 + if (p3 == p)
59832 + break;
59833 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
59834 + gr_handle_alertkill(p);
59835 + rcu_read_unlock();
59836 + put_files_struct(files);
59837 + read_unlock(&tasklist_lock);
59838 + fput(our_file);
59839 + return 0;
59840 + }
59841 + }
59842 + rcu_read_unlock();
59843 + put_files_struct(files);
59844 + } while_each_thread(p2, p);
59845 + read_unlock(&tasklist_lock);
59846 +
59847 + fput(our_file);
59848 + return 1;
59849 +}
59850 +
59851 +static int gr_rbac_disable(void *unused)
59852 +{
59853 + pax_open_kernel();
59854 + gr_status &= ~GR_READY;
59855 + pax_close_kernel();
59856 +
59857 + return 0;
59858 +}
59859 +
59860 +ssize_t
59861 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
59862 +{
59863 + struct gr_arg_wrapper uwrap;
59864 + unsigned char *sprole_salt = NULL;
59865 + unsigned char *sprole_sum = NULL;
59866 + int error = sizeof (struct gr_arg_wrapper);
59867 + int error2 = 0;
59868 +
59869 + mutex_lock(&gr_dev_mutex);
59870 +
59871 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
59872 + error = -EPERM;
59873 + goto out;
59874 + }
59875 +
59876 + if (count != sizeof (struct gr_arg_wrapper)) {
59877 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
59878 + error = -EINVAL;
59879 + goto out;
59880 + }
59881 +
59882 +
59883 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
59884 + gr_auth_expires = 0;
59885 + gr_auth_attempts = 0;
59886 + }
59887 +
59888 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
59889 + error = -EFAULT;
59890 + goto out;
59891 + }
59892 +
59893 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
59894 + error = -EINVAL;
59895 + goto out;
59896 + }
59897 +
59898 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
59899 + error = -EFAULT;
59900 + goto out;
59901 + }
59902 +
59903 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
59904 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
59905 + time_after(gr_auth_expires, get_seconds())) {
59906 + error = -EBUSY;
59907 + goto out;
59908 + }
59909 +
59910 + /* if non-root trying to do anything other than use a special role,
59911 + do not attempt authentication, do not count towards authentication
59912 + locking
59913 + */
59914 +
59915 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
59916 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
59917 + gr_is_global_nonroot(current_uid())) {
59918 + error = -EPERM;
59919 + goto out;
59920 + }
59921 +
59922 + /* ensure pw and special role name are null terminated */
59923 +
59924 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
59925 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
59926 +
59927 + /* Okay.
59928 + * We have our enough of the argument structure..(we have yet
59929 + * to copy_from_user the tables themselves) . Copy the tables
59930 + * only if we need them, i.e. for loading operations. */
59931 +
59932 + switch (gr_usermode->mode) {
59933 + case GR_STATUS:
59934 + if (gr_status & GR_READY) {
59935 + error = 1;
59936 + if (!gr_check_secure_terminal(current))
59937 + error = 3;
59938 + } else
59939 + error = 2;
59940 + goto out;
59941 + case GR_SHUTDOWN:
59942 + if ((gr_status & GR_READY)
59943 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
59944 + stop_machine(gr_rbac_disable, NULL, NULL);
59945 + free_variables();
59946 + memset(gr_usermode, 0, sizeof (struct gr_arg));
59947 + memset(gr_system_salt, 0, GR_SALT_LEN);
59948 + memset(gr_system_sum, 0, GR_SHA_LEN);
59949 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
59950 + } else if (gr_status & GR_READY) {
59951 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
59952 + error = -EPERM;
59953 + } else {
59954 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
59955 + error = -EAGAIN;
59956 + }
59957 + break;
59958 + case GR_ENABLE:
59959 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
59960 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
59961 + else {
59962 + if (gr_status & GR_READY)
59963 + error = -EAGAIN;
59964 + else
59965 + error = error2;
59966 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
59967 + }
59968 + break;
59969 + case GR_RELOAD:
59970 + if (!(gr_status & GR_READY)) {
59971 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
59972 + error = -EAGAIN;
59973 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
59974 + stop_machine(gr_rbac_disable, NULL, NULL);
59975 + free_variables();
59976 + error2 = gracl_init(gr_usermode);
59977 + if (!error2)
59978 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
59979 + else {
59980 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
59981 + error = error2;
59982 + }
59983 + } else {
59984 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
59985 + error = -EPERM;
59986 + }
59987 + break;
59988 + case GR_SEGVMOD:
59989 + if (unlikely(!(gr_status & GR_READY))) {
59990 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
59991 + error = -EAGAIN;
59992 + break;
59993 + }
59994 +
59995 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
59996 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
59997 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
59998 + struct acl_subject_label *segvacl;
59999 + segvacl =
60000 + lookup_acl_subj_label(gr_usermode->segv_inode,
60001 + gr_usermode->segv_device,
60002 + current->role);
60003 + if (segvacl) {
60004 + segvacl->crashes = 0;
60005 + segvacl->expires = 0;
60006 + }
60007 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
60008 + gr_remove_uid(gr_usermode->segv_uid);
60009 + }
60010 + } else {
60011 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
60012 + error = -EPERM;
60013 + }
60014 + break;
60015 + case GR_SPROLE:
60016 + case GR_SPROLEPAM:
60017 + if (unlikely(!(gr_status & GR_READY))) {
60018 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
60019 + error = -EAGAIN;
60020 + break;
60021 + }
60022 +
60023 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
60024 + current->role->expires = 0;
60025 + current->role->auth_attempts = 0;
60026 + }
60027 +
60028 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60029 + time_after(current->role->expires, get_seconds())) {
60030 + error = -EBUSY;
60031 + goto out;
60032 + }
60033 +
60034 + if (lookup_special_role_auth
60035 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
60036 + && ((!sprole_salt && !sprole_sum)
60037 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
60038 + char *p = "";
60039 + assign_special_role(gr_usermode->sp_role);
60040 + read_lock(&tasklist_lock);
60041 + if (current->real_parent)
60042 + p = current->real_parent->role->rolename;
60043 + read_unlock(&tasklist_lock);
60044 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
60045 + p, acl_sp_role_value);
60046 + } else {
60047 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
60048 + error = -EPERM;
60049 + if(!(current->role->auth_attempts++))
60050 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60051 +
60052 + goto out;
60053 + }
60054 + break;
60055 + case GR_UNSPROLE:
60056 + if (unlikely(!(gr_status & GR_READY))) {
60057 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
60058 + error = -EAGAIN;
60059 + break;
60060 + }
60061 +
60062 + if (current->role->roletype & GR_ROLE_SPECIAL) {
60063 + char *p = "";
60064 + int i = 0;
60065 +
60066 + read_lock(&tasklist_lock);
60067 + if (current->real_parent) {
60068 + p = current->real_parent->role->rolename;
60069 + i = current->real_parent->acl_role_id;
60070 + }
60071 + read_unlock(&tasklist_lock);
60072 +
60073 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
60074 + gr_set_acls(1);
60075 + } else {
60076 + error = -EPERM;
60077 + goto out;
60078 + }
60079 + break;
60080 + default:
60081 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
60082 + error = -EINVAL;
60083 + break;
60084 + }
60085 +
60086 + if (error != -EPERM)
60087 + goto out;
60088 +
60089 + if(!(gr_auth_attempts++))
60090 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60091 +
60092 + out:
60093 + mutex_unlock(&gr_dev_mutex);
60094 + return error;
60095 +}
60096 +
60097 +/* must be called with
60098 + rcu_read_lock();
60099 + read_lock(&tasklist_lock);
60100 + read_lock(&grsec_exec_file_lock);
60101 +*/
60102 +int gr_apply_subject_to_task(struct task_struct *task)
60103 +{
60104 + struct acl_object_label *obj;
60105 + char *tmpname;
60106 + struct acl_subject_label *tmpsubj;
60107 + struct file *filp;
60108 + struct name_entry *nmatch;
60109 +
60110 + filp = task->exec_file;
60111 + if (filp == NULL)
60112 + return 0;
60113 +
60114 + /* the following is to apply the correct subject
60115 + on binaries running when the RBAC system
60116 + is enabled, when the binaries have been
60117 + replaced or deleted since their execution
60118 + -----
60119 + when the RBAC system starts, the inode/dev
60120 + from exec_file will be one the RBAC system
60121 + is unaware of. It only knows the inode/dev
60122 + of the present file on disk, or the absence
60123 + of it.
60124 + */
60125 + preempt_disable();
60126 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
60127 +
60128 + nmatch = lookup_name_entry(tmpname);
60129 + preempt_enable();
60130 + tmpsubj = NULL;
60131 + if (nmatch) {
60132 + if (nmatch->deleted)
60133 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
60134 + else
60135 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
60136 + if (tmpsubj != NULL)
60137 + task->acl = tmpsubj;
60138 + }
60139 + if (tmpsubj == NULL)
60140 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
60141 + task->role);
60142 + if (task->acl) {
60143 + task->is_writable = 0;
60144 + /* ignore additional mmap checks for processes that are writable
60145 + by the default ACL */
60146 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60147 + if (unlikely(obj->mode & GR_WRITE))
60148 + task->is_writable = 1;
60149 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60150 + if (unlikely(obj->mode & GR_WRITE))
60151 + task->is_writable = 1;
60152 +
60153 + gr_set_proc_res(task);
60154 +
60155 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60156 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task_pid_nr(task), task->role->rolename, task->acl->filename);
60157 +#endif
60158 + } else {
60159 + return 1;
60160 + }
60161 +
60162 + return 0;
60163 +}
60164 +
60165 +int
60166 +gr_set_acls(const int type)
60167 +{
60168 + struct task_struct *task, *task2;
60169 + struct acl_role_label *role = current->role;
60170 + __u16 acl_role_id = current->acl_role_id;
60171 + const struct cred *cred;
60172 + int ret;
60173 +
60174 + rcu_read_lock();
60175 + read_lock(&tasklist_lock);
60176 + read_lock(&grsec_exec_file_lock);
60177 + do_each_thread(task2, task) {
60178 + /* check to see if we're called from the exit handler,
60179 + if so, only replace ACLs that have inherited the admin
60180 + ACL */
60181 +
60182 + if (type && (task->role != role ||
60183 + task->acl_role_id != acl_role_id))
60184 + continue;
60185 +
60186 + task->acl_role_id = 0;
60187 + task->acl_sp_role = 0;
60188 +
60189 + if (task->exec_file) {
60190 + cred = __task_cred(task);
60191 + task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
60192 + ret = gr_apply_subject_to_task(task);
60193 + if (ret) {
60194 + read_unlock(&grsec_exec_file_lock);
60195 + read_unlock(&tasklist_lock);
60196 + rcu_read_unlock();
60197 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
60198 + return ret;
60199 + }
60200 + } else {
60201 + // it's a kernel process
60202 + task->role = kernel_role;
60203 + task->acl = kernel_role->root_label;
60204 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
60205 + task->acl->mode &= ~GR_PROCFIND;
60206 +#endif
60207 + }
60208 + } while_each_thread(task2, task);
60209 + read_unlock(&grsec_exec_file_lock);
60210 + read_unlock(&tasklist_lock);
60211 + rcu_read_unlock();
60212 +
60213 + return 0;
60214 +}
60215 +
60216 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
60217 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
60218 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
60219 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
60220 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
60221 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
60222 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
60223 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
60224 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
60225 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
60226 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
60227 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
60228 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
60229 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
60230 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
60231 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
60232 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
60233 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
60234 +};
60235 +
60236 +void
60237 +gr_learn_resource(const struct task_struct *task,
60238 + const int res, const unsigned long wanted, const int gt)
60239 +{
60240 + struct acl_subject_label *acl;
60241 + const struct cred *cred;
60242 +
60243 + if (unlikely((gr_status & GR_READY) &&
60244 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
60245 + goto skip_reslog;
60246 +
60247 + gr_log_resource(task, res, wanted, gt);
60248 +skip_reslog:
60249 +
60250 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
60251 + return;
60252 +
60253 + acl = task->acl;
60254 +
60255 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
60256 + !(acl->resmask & (1 << (unsigned short) res))))
60257 + return;
60258 +
60259 + if (wanted >= acl->res[res].rlim_cur) {
60260 + unsigned long res_add;
60261 +
60262 + res_add = wanted + res_learn_bumps[res];
60263 +
60264 + acl->res[res].rlim_cur = res_add;
60265 +
60266 + if (wanted > acl->res[res].rlim_max)
60267 + acl->res[res].rlim_max = res_add;
60268 +
60269 + /* only log the subject filename, since resource logging is supported for
60270 + single-subject learning only */
60271 + rcu_read_lock();
60272 + cred = __task_cred(task);
60273 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60274 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
60275 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
60276 + "", (unsigned long) res, &task->signal->saved_ip);
60277 + rcu_read_unlock();
60278 + }
60279 +
60280 + return;
60281 +}
60282 +EXPORT_SYMBOL(gr_learn_resource);
60283 +#endif
60284 +
60285 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
60286 +void
60287 +pax_set_initial_flags(struct linux_binprm *bprm)
60288 +{
60289 + struct task_struct *task = current;
60290 + struct acl_subject_label *proc;
60291 + unsigned long flags;
60292 +
60293 + if (unlikely(!(gr_status & GR_READY)))
60294 + return;
60295 +
60296 + flags = pax_get_flags(task);
60297 +
60298 + proc = task->acl;
60299 +
60300 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
60301 + flags &= ~MF_PAX_PAGEEXEC;
60302 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
60303 + flags &= ~MF_PAX_SEGMEXEC;
60304 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
60305 + flags &= ~MF_PAX_RANDMMAP;
60306 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
60307 + flags &= ~MF_PAX_EMUTRAMP;
60308 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
60309 + flags &= ~MF_PAX_MPROTECT;
60310 +
60311 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
60312 + flags |= MF_PAX_PAGEEXEC;
60313 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
60314 + flags |= MF_PAX_SEGMEXEC;
60315 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
60316 + flags |= MF_PAX_RANDMMAP;
60317 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
60318 + flags |= MF_PAX_EMUTRAMP;
60319 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
60320 + flags |= MF_PAX_MPROTECT;
60321 +
60322 + pax_set_flags(task, flags);
60323 +
60324 + return;
60325 +}
60326 +#endif
60327 +
60328 +int
60329 +gr_handle_proc_ptrace(struct task_struct *task)
60330 +{
60331 + struct file *filp;
60332 + struct task_struct *tmp = task;
60333 + struct task_struct *curtemp = current;
60334 + __u32 retmode;
60335 +
60336 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60337 + if (unlikely(!(gr_status & GR_READY)))
60338 + return 0;
60339 +#endif
60340 +
60341 + read_lock(&tasklist_lock);
60342 + read_lock(&grsec_exec_file_lock);
60343 + filp = task->exec_file;
60344 +
60345 + while (task_pid_nr(tmp) > 0) {
60346 + if (tmp == curtemp)
60347 + break;
60348 + tmp = tmp->real_parent;
60349 + }
60350 +
60351 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60352 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
60353 + read_unlock(&grsec_exec_file_lock);
60354 + read_unlock(&tasklist_lock);
60355 + return 1;
60356 + }
60357 +
60358 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60359 + if (!(gr_status & GR_READY)) {
60360 + read_unlock(&grsec_exec_file_lock);
60361 + read_unlock(&tasklist_lock);
60362 + return 0;
60363 + }
60364 +#endif
60365 +
60366 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
60367 + read_unlock(&grsec_exec_file_lock);
60368 + read_unlock(&tasklist_lock);
60369 +
60370 + if (retmode & GR_NOPTRACE)
60371 + return 1;
60372 +
60373 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
60374 + && (current->acl != task->acl || (current->acl != current->role->root_label
60375 + && task_pid_nr(current) != task_pid_nr(task))))
60376 + return 1;
60377 +
60378 + return 0;
60379 +}
60380 +
60381 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
60382 +{
60383 + if (unlikely(!(gr_status & GR_READY)))
60384 + return;
60385 +
60386 + if (!(current->role->roletype & GR_ROLE_GOD))
60387 + return;
60388 +
60389 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
60390 + p->role->rolename, gr_task_roletype_to_char(p),
60391 + p->acl->filename);
60392 +}
60393 +
60394 +int
60395 +gr_handle_ptrace(struct task_struct *task, const long request)
60396 +{
60397 + struct task_struct *tmp = task;
60398 + struct task_struct *curtemp = current;
60399 + __u32 retmode;
60400 +
60401 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60402 + if (unlikely(!(gr_status & GR_READY)))
60403 + return 0;
60404 +#endif
60405 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
60406 + read_lock(&tasklist_lock);
60407 + while (task_pid_nr(tmp) > 0) {
60408 + if (tmp == curtemp)
60409 + break;
60410 + tmp = tmp->real_parent;
60411 + }
60412 +
60413 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60414 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
60415 + read_unlock(&tasklist_lock);
60416 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60417 + return 1;
60418 + }
60419 + read_unlock(&tasklist_lock);
60420 + }
60421 +
60422 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60423 + if (!(gr_status & GR_READY))
60424 + return 0;
60425 +#endif
60426 +
60427 + read_lock(&grsec_exec_file_lock);
60428 + if (unlikely(!task->exec_file)) {
60429 + read_unlock(&grsec_exec_file_lock);
60430 + return 0;
60431 + }
60432 +
60433 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
60434 + read_unlock(&grsec_exec_file_lock);
60435 +
60436 + if (retmode & GR_NOPTRACE) {
60437 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60438 + return 1;
60439 + }
60440 +
60441 + if (retmode & GR_PTRACERD) {
60442 + switch (request) {
60443 + case PTRACE_SEIZE:
60444 + case PTRACE_POKETEXT:
60445 + case PTRACE_POKEDATA:
60446 + case PTRACE_POKEUSR:
60447 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
60448 + case PTRACE_SETREGS:
60449 + case PTRACE_SETFPREGS:
60450 +#endif
60451 +#ifdef CONFIG_X86
60452 + case PTRACE_SETFPXREGS:
60453 +#endif
60454 +#ifdef CONFIG_ALTIVEC
60455 + case PTRACE_SETVRREGS:
60456 +#endif
60457 + return 1;
60458 + default:
60459 + return 0;
60460 + }
60461 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
60462 + !(current->role->roletype & GR_ROLE_GOD) &&
60463 + (current->acl != task->acl)) {
60464 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60465 + return 1;
60466 + }
60467 +
60468 + return 0;
60469 +}
60470 +
60471 +static int is_writable_mmap(const struct file *filp)
60472 +{
60473 + struct task_struct *task = current;
60474 + struct acl_object_label *obj, *obj2;
60475 +
60476 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
60477 + !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))) {
60478 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60479 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
60480 + task->role->root_label);
60481 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
60482 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
60483 + return 1;
60484 + }
60485 + }
60486 + return 0;
60487 +}
60488 +
60489 +int
60490 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
60491 +{
60492 + __u32 mode;
60493 +
60494 + if (unlikely(!file || !(prot & PROT_EXEC)))
60495 + return 1;
60496 +
60497 + if (is_writable_mmap(file))
60498 + return 0;
60499 +
60500 + mode =
60501 + gr_search_file(file->f_path.dentry,
60502 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
60503 + file->f_path.mnt);
60504 +
60505 + if (!gr_tpe_allow(file))
60506 + return 0;
60507 +
60508 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
60509 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60510 + return 0;
60511 + } else if (unlikely(!(mode & GR_EXEC))) {
60512 + return 0;
60513 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
60514 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60515 + return 1;
60516 + }
60517 +
60518 + return 1;
60519 +}
60520 +
60521 +int
60522 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60523 +{
60524 + __u32 mode;
60525 +
60526 + if (unlikely(!file || !(prot & PROT_EXEC)))
60527 + return 1;
60528 +
60529 + if (is_writable_mmap(file))
60530 + return 0;
60531 +
60532 + mode =
60533 + gr_search_file(file->f_path.dentry,
60534 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
60535 + file->f_path.mnt);
60536 +
60537 + if (!gr_tpe_allow(file))
60538 + return 0;
60539 +
60540 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
60541 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60542 + return 0;
60543 + } else if (unlikely(!(mode & GR_EXEC))) {
60544 + return 0;
60545 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
60546 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60547 + return 1;
60548 + }
60549 +
60550 + return 1;
60551 +}
60552 +
60553 +void
60554 +gr_acl_handle_psacct(struct task_struct *task, const long code)
60555 +{
60556 + unsigned long runtime;
60557 + unsigned long cputime;
60558 + unsigned int wday, cday;
60559 + __u8 whr, chr;
60560 + __u8 wmin, cmin;
60561 + __u8 wsec, csec;
60562 + struct timespec timeval;
60563 +
60564 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
60565 + !(task->acl->mode & GR_PROCACCT)))
60566 + return;
60567 +
60568 + do_posix_clock_monotonic_gettime(&timeval);
60569 + runtime = timeval.tv_sec - task->start_time.tv_sec;
60570 + wday = runtime / (3600 * 24);
60571 + runtime -= wday * (3600 * 24);
60572 + whr = runtime / 3600;
60573 + runtime -= whr * 3600;
60574 + wmin = runtime / 60;
60575 + runtime -= wmin * 60;
60576 + wsec = runtime;
60577 +
60578 + cputime = (task->utime + task->stime) / HZ;
60579 + cday = cputime / (3600 * 24);
60580 + cputime -= cday * (3600 * 24);
60581 + chr = cputime / 3600;
60582 + cputime -= chr * 3600;
60583 + cmin = cputime / 60;
60584 + cputime -= cmin * 60;
60585 + csec = cputime;
60586 +
60587 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
60588 +
60589 + return;
60590 +}
60591 +
60592 +void gr_set_kernel_label(struct task_struct *task)
60593 +{
60594 + if (gr_status & GR_READY) {
60595 + task->role = kernel_role;
60596 + task->acl = kernel_role->root_label;
60597 + }
60598 + return;
60599 +}
60600 +
60601 +#ifdef CONFIG_TASKSTATS
60602 +int gr_is_taskstats_denied(int pid)
60603 +{
60604 + struct task_struct *task;
60605 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60606 + const struct cred *cred;
60607 +#endif
60608 + int ret = 0;
60609 +
60610 + /* restrict taskstats viewing to un-chrooted root users
60611 + who have the 'view' subject flag if the RBAC system is enabled
60612 + */
60613 +
60614 + rcu_read_lock();
60615 + read_lock(&tasklist_lock);
60616 + task = find_task_by_vpid(pid);
60617 + if (task) {
60618 +#ifdef CONFIG_GRKERNSEC_CHROOT
60619 + if (proc_is_chrooted(task))
60620 + ret = -EACCES;
60621 +#endif
60622 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60623 + cred = __task_cred(task);
60624 +#ifdef CONFIG_GRKERNSEC_PROC_USER
60625 + if (gr_is_global_nonroot(cred->uid))
60626 + ret = -EACCES;
60627 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60628 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
60629 + ret = -EACCES;
60630 +#endif
60631 +#endif
60632 + if (gr_status & GR_READY) {
60633 + if (!(task->acl->mode & GR_VIEW))
60634 + ret = -EACCES;
60635 + }
60636 + } else
60637 + ret = -ENOENT;
60638 +
60639 + read_unlock(&tasklist_lock);
60640 + rcu_read_unlock();
60641 +
60642 + return ret;
60643 +}
60644 +#endif
60645 +
60646 +/* AUXV entries are filled via a descendant of search_binary_handler
60647 + after we've already applied the subject for the target
60648 +*/
60649 +int gr_acl_enable_at_secure(void)
60650 +{
60651 + if (unlikely(!(gr_status & GR_READY)))
60652 + return 0;
60653 +
60654 + if (current->acl->mode & GR_ATSECURE)
60655 + return 1;
60656 +
60657 + return 0;
60658 +}
60659 +
60660 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
60661 +{
60662 + struct task_struct *task = current;
60663 + struct dentry *dentry = file->f_path.dentry;
60664 + struct vfsmount *mnt = file->f_path.mnt;
60665 + struct acl_object_label *obj, *tmp;
60666 + struct acl_subject_label *subj;
60667 + unsigned int bufsize;
60668 + int is_not_root;
60669 + char *path;
60670 + dev_t dev = __get_dev(dentry);
60671 +
60672 + if (unlikely(!(gr_status & GR_READY)))
60673 + return 1;
60674 +
60675 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60676 + return 1;
60677 +
60678 + /* ignore Eric Biederman */
60679 + if (IS_PRIVATE(dentry->d_inode))
60680 + return 1;
60681 +
60682 + subj = task->acl;
60683 + read_lock(&gr_inode_lock);
60684 + do {
60685 + obj = lookup_acl_obj_label(ino, dev, subj);
60686 + if (obj != NULL) {
60687 + read_unlock(&gr_inode_lock);
60688 + return (obj->mode & GR_FIND) ? 1 : 0;
60689 + }
60690 + } while ((subj = subj->parent_subject));
60691 + read_unlock(&gr_inode_lock);
60692 +
60693 + /* this is purely an optimization since we're looking for an object
60694 + for the directory we're doing a readdir on
60695 + if it's possible for any globbed object to match the entry we're
60696 + filling into the directory, then the object we find here will be
60697 + an anchor point with attached globbed objects
60698 + */
60699 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
60700 + if (obj->globbed == NULL)
60701 + return (obj->mode & GR_FIND) ? 1 : 0;
60702 +
60703 + is_not_root = ((obj->filename[0] == '/') &&
60704 + (obj->filename[1] == '\0')) ? 0 : 1;
60705 + bufsize = PAGE_SIZE - namelen - is_not_root;
60706 +
60707 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
60708 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
60709 + return 1;
60710 +
60711 + preempt_disable();
60712 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
60713 + bufsize);
60714 +
60715 + bufsize = strlen(path);
60716 +
60717 + /* if base is "/", don't append an additional slash */
60718 + if (is_not_root)
60719 + *(path + bufsize) = '/';
60720 + memcpy(path + bufsize + is_not_root, name, namelen);
60721 + *(path + bufsize + namelen + is_not_root) = '\0';
60722 +
60723 + tmp = obj->globbed;
60724 + while (tmp) {
60725 + if (!glob_match(tmp->filename, path)) {
60726 + preempt_enable();
60727 + return (tmp->mode & GR_FIND) ? 1 : 0;
60728 + }
60729 + tmp = tmp->next;
60730 + }
60731 + preempt_enable();
60732 + return (obj->mode & GR_FIND) ? 1 : 0;
60733 +}
60734 +
60735 +void gr_put_exec_file(struct task_struct *task)
60736 +{
60737 + struct file *filp;
60738 +
60739 + write_lock(&grsec_exec_file_lock);
60740 + filp = task->exec_file;
60741 + task->exec_file = NULL;
60742 + write_unlock(&grsec_exec_file_lock);
60743 +
60744 + if (filp)
60745 + fput(filp);
60746 +
60747 + return;
60748 +}
60749 +
60750 +
60751 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
60752 +EXPORT_SYMBOL(gr_acl_is_enabled);
60753 +#endif
60754 +EXPORT_SYMBOL(gr_set_kernel_label);
60755 +#ifdef CONFIG_SECURITY
60756 +EXPORT_SYMBOL(gr_check_user_change);
60757 +EXPORT_SYMBOL(gr_check_group_change);
60758 +#endif
60759 +
60760 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
60761 new file mode 100644
60762 index 0000000..34fefda
60763 --- /dev/null
60764 +++ b/grsecurity/gracl_alloc.c
60765 @@ -0,0 +1,105 @@
60766 +#include <linux/kernel.h>
60767 +#include <linux/mm.h>
60768 +#include <linux/slab.h>
60769 +#include <linux/vmalloc.h>
60770 +#include <linux/gracl.h>
60771 +#include <linux/grsecurity.h>
60772 +
60773 +static unsigned long alloc_stack_next = 1;
60774 +static unsigned long alloc_stack_size = 1;
60775 +static void **alloc_stack;
60776 +
60777 +static __inline__ int
60778 +alloc_pop(void)
60779 +{
60780 + if (alloc_stack_next == 1)
60781 + return 0;
60782 +
60783 + kfree(alloc_stack[alloc_stack_next - 2]);
60784 +
60785 + alloc_stack_next--;
60786 +
60787 + return 1;
60788 +}
60789 +
60790 +static __inline__ int
60791 +alloc_push(void *buf)
60792 +{
60793 + if (alloc_stack_next >= alloc_stack_size)
60794 + return 1;
60795 +
60796 + alloc_stack[alloc_stack_next - 1] = buf;
60797 +
60798 + alloc_stack_next++;
60799 +
60800 + return 0;
60801 +}
60802 +
60803 +void *
60804 +acl_alloc(unsigned long len)
60805 +{
60806 + void *ret = NULL;
60807 +
60808 + if (!len || len > PAGE_SIZE)
60809 + goto out;
60810 +
60811 + ret = kmalloc(len, GFP_KERNEL);
60812 +
60813 + if (ret) {
60814 + if (alloc_push(ret)) {
60815 + kfree(ret);
60816 + ret = NULL;
60817 + }
60818 + }
60819 +
60820 +out:
60821 + return ret;
60822 +}
60823 +
60824 +void *
60825 +acl_alloc_num(unsigned long num, unsigned long len)
60826 +{
60827 + if (!len || (num > (PAGE_SIZE / len)))
60828 + return NULL;
60829 +
60830 + return acl_alloc(num * len);
60831 +}
60832 +
60833 +void
60834 +acl_free_all(void)
60835 +{
60836 + if (gr_acl_is_enabled() || !alloc_stack)
60837 + return;
60838 +
60839 + while (alloc_pop()) ;
60840 +
60841 + if (alloc_stack) {
60842 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
60843 + kfree(alloc_stack);
60844 + else
60845 + vfree(alloc_stack);
60846 + }
60847 +
60848 + alloc_stack = NULL;
60849 + alloc_stack_size = 1;
60850 + alloc_stack_next = 1;
60851 +
60852 + return;
60853 +}
60854 +
60855 +int
60856 +acl_alloc_stack_init(unsigned long size)
60857 +{
60858 + if ((size * sizeof (void *)) <= PAGE_SIZE)
60859 + alloc_stack =
60860 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
60861 + else
60862 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
60863 +
60864 + alloc_stack_size = size;
60865 +
60866 + if (!alloc_stack)
60867 + return 0;
60868 + else
60869 + return 1;
60870 +}
60871 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
60872 new file mode 100644
60873 index 0000000..bdd51ea
60874 --- /dev/null
60875 +++ b/grsecurity/gracl_cap.c
60876 @@ -0,0 +1,110 @@
60877 +#include <linux/kernel.h>
60878 +#include <linux/module.h>
60879 +#include <linux/sched.h>
60880 +#include <linux/gracl.h>
60881 +#include <linux/grsecurity.h>
60882 +#include <linux/grinternal.h>
60883 +
60884 +extern const char *captab_log[];
60885 +extern int captab_log_entries;
60886 +
60887 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60888 +{
60889 + struct acl_subject_label *curracl;
60890 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
60891 + kernel_cap_t cap_audit = __cap_empty_set;
60892 +
60893 + if (!gr_acl_is_enabled())
60894 + return 1;
60895 +
60896 + curracl = task->acl;
60897 +
60898 + cap_drop = curracl->cap_lower;
60899 + cap_mask = curracl->cap_mask;
60900 + cap_audit = curracl->cap_invert_audit;
60901 +
60902 + while ((curracl = curracl->parent_subject)) {
60903 + /* if the cap isn't specified in the current computed mask but is specified in the
60904 + current level subject, and is lowered in the current level subject, then add
60905 + it to the set of dropped capabilities
60906 + otherwise, add the current level subject's mask to the current computed mask
60907 + */
60908 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
60909 + cap_raise(cap_mask, cap);
60910 + if (cap_raised(curracl->cap_lower, cap))
60911 + cap_raise(cap_drop, cap);
60912 + if (cap_raised(curracl->cap_invert_audit, cap))
60913 + cap_raise(cap_audit, cap);
60914 + }
60915 + }
60916 +
60917 + if (!cap_raised(cap_drop, cap)) {
60918 + if (cap_raised(cap_audit, cap))
60919 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
60920 + return 1;
60921 + }
60922 +
60923 + curracl = task->acl;
60924 +
60925 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
60926 + && cap_raised(cred->cap_effective, cap)) {
60927 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60928 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
60929 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
60930 + gr_to_filename(task->exec_file->f_path.dentry,
60931 + task->exec_file->f_path.mnt) : curracl->filename,
60932 + curracl->filename, 0UL,
60933 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
60934 + return 1;
60935 + }
60936 +
60937 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
60938 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
60939 +
60940 + return 0;
60941 +}
60942 +
60943 +int
60944 +gr_acl_is_capable(const int cap)
60945 +{
60946 + return gr_task_acl_is_capable(current, current_cred(), cap);
60947 +}
60948 +
60949 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
60950 +{
60951 + struct acl_subject_label *curracl;
60952 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
60953 +
60954 + if (!gr_acl_is_enabled())
60955 + return 1;
60956 +
60957 + curracl = task->acl;
60958 +
60959 + cap_drop = curracl->cap_lower;
60960 + cap_mask = curracl->cap_mask;
60961 +
60962 + while ((curracl = curracl->parent_subject)) {
60963 + /* if the cap isn't specified in the current computed mask but is specified in the
60964 + current level subject, and is lowered in the current level subject, then add
60965 + it to the set of dropped capabilities
60966 + otherwise, add the current level subject's mask to the current computed mask
60967 + */
60968 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
60969 + cap_raise(cap_mask, cap);
60970 + if (cap_raised(curracl->cap_lower, cap))
60971 + cap_raise(cap_drop, cap);
60972 + }
60973 + }
60974 +
60975 + if (!cap_raised(cap_drop, cap))
60976 + return 1;
60977 +
60978 + return 0;
60979 +}
60980 +
60981 +int
60982 +gr_acl_is_capable_nolog(const int cap)
60983 +{
60984 + return gr_task_acl_is_capable_nolog(current, cap);
60985 +}
60986 +
60987 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
60988 new file mode 100644
60989 index 0000000..a340c17
60990 --- /dev/null
60991 +++ b/grsecurity/gracl_fs.c
60992 @@ -0,0 +1,431 @@
60993 +#include <linux/kernel.h>
60994 +#include <linux/sched.h>
60995 +#include <linux/types.h>
60996 +#include <linux/fs.h>
60997 +#include <linux/file.h>
60998 +#include <linux/stat.h>
60999 +#include <linux/grsecurity.h>
61000 +#include <linux/grinternal.h>
61001 +#include <linux/gracl.h>
61002 +
61003 +umode_t
61004 +gr_acl_umask(void)
61005 +{
61006 + if (unlikely(!gr_acl_is_enabled()))
61007 + return 0;
61008 +
61009 + return current->role->umask;
61010 +}
61011 +
61012 +__u32
61013 +gr_acl_handle_hidden_file(const struct dentry * dentry,
61014 + const struct vfsmount * mnt)
61015 +{
61016 + __u32 mode;
61017 +
61018 + if (unlikely(!dentry->d_inode))
61019 + return GR_FIND;
61020 +
61021 + mode =
61022 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
61023 +
61024 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
61025 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61026 + return mode;
61027 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
61028 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61029 + return 0;
61030 + } else if (unlikely(!(mode & GR_FIND)))
61031 + return 0;
61032 +
61033 + return GR_FIND;
61034 +}
61035 +
61036 +__u32
61037 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
61038 + int acc_mode)
61039 +{
61040 + __u32 reqmode = GR_FIND;
61041 + __u32 mode;
61042 +
61043 + if (unlikely(!dentry->d_inode))
61044 + return reqmode;
61045 +
61046 + if (acc_mode & MAY_APPEND)
61047 + reqmode |= GR_APPEND;
61048 + else if (acc_mode & MAY_WRITE)
61049 + reqmode |= GR_WRITE;
61050 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
61051 + reqmode |= GR_READ;
61052 +
61053 + mode =
61054 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61055 + mnt);
61056 +
61057 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61058 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61059 + reqmode & GR_READ ? " reading" : "",
61060 + reqmode & GR_WRITE ? " writing" : reqmode &
61061 + GR_APPEND ? " appending" : "");
61062 + return reqmode;
61063 + } else
61064 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61065 + {
61066 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61067 + reqmode & GR_READ ? " reading" : "",
61068 + reqmode & GR_WRITE ? " writing" : reqmode &
61069 + GR_APPEND ? " appending" : "");
61070 + return 0;
61071 + } else if (unlikely((mode & reqmode) != reqmode))
61072 + return 0;
61073 +
61074 + return reqmode;
61075 +}
61076 +
61077 +__u32
61078 +gr_acl_handle_creat(const struct dentry * dentry,
61079 + const struct dentry * p_dentry,
61080 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
61081 + const int imode)
61082 +{
61083 + __u32 reqmode = GR_WRITE | GR_CREATE;
61084 + __u32 mode;
61085 +
61086 + if (acc_mode & MAY_APPEND)
61087 + reqmode |= GR_APPEND;
61088 + // if a directory was required or the directory already exists, then
61089 + // don't count this open as a read
61090 + if ((acc_mode & MAY_READ) &&
61091 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
61092 + reqmode |= GR_READ;
61093 + if ((open_flags & O_CREAT) &&
61094 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61095 + reqmode |= GR_SETID;
61096 +
61097 + mode =
61098 + gr_check_create(dentry, p_dentry, p_mnt,
61099 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61100 +
61101 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61102 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61103 + reqmode & GR_READ ? " reading" : "",
61104 + reqmode & GR_WRITE ? " writing" : reqmode &
61105 + GR_APPEND ? " appending" : "");
61106 + return reqmode;
61107 + } else
61108 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61109 + {
61110 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61111 + reqmode & GR_READ ? " reading" : "",
61112 + reqmode & GR_WRITE ? " writing" : reqmode &
61113 + GR_APPEND ? " appending" : "");
61114 + return 0;
61115 + } else if (unlikely((mode & reqmode) != reqmode))
61116 + return 0;
61117 +
61118 + return reqmode;
61119 +}
61120 +
61121 +__u32
61122 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
61123 + const int fmode)
61124 +{
61125 + __u32 mode, reqmode = GR_FIND;
61126 +
61127 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
61128 + reqmode |= GR_EXEC;
61129 + if (fmode & S_IWOTH)
61130 + reqmode |= GR_WRITE;
61131 + if (fmode & S_IROTH)
61132 + reqmode |= GR_READ;
61133 +
61134 + mode =
61135 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61136 + mnt);
61137 +
61138 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61139 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61140 + reqmode & GR_READ ? " reading" : "",
61141 + reqmode & GR_WRITE ? " writing" : "",
61142 + reqmode & GR_EXEC ? " executing" : "");
61143 + return reqmode;
61144 + } else
61145 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61146 + {
61147 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61148 + reqmode & GR_READ ? " reading" : "",
61149 + reqmode & GR_WRITE ? " writing" : "",
61150 + reqmode & GR_EXEC ? " executing" : "");
61151 + return 0;
61152 + } else if (unlikely((mode & reqmode) != reqmode))
61153 + return 0;
61154 +
61155 + return reqmode;
61156 +}
61157 +
61158 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
61159 +{
61160 + __u32 mode;
61161 +
61162 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
61163 +
61164 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61165 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
61166 + return mode;
61167 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61168 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
61169 + return 0;
61170 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
61171 + return 0;
61172 +
61173 + return (reqmode);
61174 +}
61175 +
61176 +__u32
61177 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
61178 +{
61179 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
61180 +}
61181 +
61182 +__u32
61183 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
61184 +{
61185 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
61186 +}
61187 +
61188 +__u32
61189 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
61190 +{
61191 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
61192 +}
61193 +
61194 +__u32
61195 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
61196 +{
61197 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
61198 +}
61199 +
61200 +__u32
61201 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
61202 + umode_t *modeptr)
61203 +{
61204 + umode_t mode;
61205 +
61206 + *modeptr &= ~gr_acl_umask();
61207 + mode = *modeptr;
61208 +
61209 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
61210 + return 1;
61211 +
61212 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
61213 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
61214 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
61215 + GR_CHMOD_ACL_MSG);
61216 + } else {
61217 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
61218 + }
61219 +}
61220 +
61221 +__u32
61222 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
61223 +{
61224 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
61225 +}
61226 +
61227 +__u32
61228 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
61229 +{
61230 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
61231 +}
61232 +
61233 +__u32
61234 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
61235 +{
61236 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
61237 +}
61238 +
61239 +__u32
61240 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
61241 +{
61242 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
61243 + GR_UNIXCONNECT_ACL_MSG);
61244 +}
61245 +
61246 +/* hardlinks require at minimum create and link permission,
61247 + any additional privilege required is based on the
61248 + privilege of the file being linked to
61249 +*/
61250 +__u32
61251 +gr_acl_handle_link(const struct dentry * new_dentry,
61252 + const struct dentry * parent_dentry,
61253 + const struct vfsmount * parent_mnt,
61254 + const struct dentry * old_dentry,
61255 + const struct vfsmount * old_mnt, const struct filename *to)
61256 +{
61257 + __u32 mode;
61258 + __u32 needmode = GR_CREATE | GR_LINK;
61259 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
61260 +
61261 + mode =
61262 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
61263 + old_mnt);
61264 +
61265 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
61266 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61267 + return mode;
61268 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61269 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61270 + return 0;
61271 + } else if (unlikely((mode & needmode) != needmode))
61272 + return 0;
61273 +
61274 + return 1;
61275 +}
61276 +
61277 +__u32
61278 +gr_acl_handle_symlink(const struct dentry * new_dentry,
61279 + const struct dentry * parent_dentry,
61280 + const struct vfsmount * parent_mnt, const struct filename *from)
61281 +{
61282 + __u32 needmode = GR_WRITE | GR_CREATE;
61283 + __u32 mode;
61284 +
61285 + mode =
61286 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
61287 + GR_CREATE | GR_AUDIT_CREATE |
61288 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
61289 +
61290 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
61291 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61292 + return mode;
61293 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61294 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61295 + return 0;
61296 + } else if (unlikely((mode & needmode) != needmode))
61297 + return 0;
61298 +
61299 + return (GR_WRITE | GR_CREATE);
61300 +}
61301 +
61302 +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)
61303 +{
61304 + __u32 mode;
61305 +
61306 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61307 +
61308 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61309 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
61310 + return mode;
61311 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61312 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
61313 + return 0;
61314 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
61315 + return 0;
61316 +
61317 + return (reqmode);
61318 +}
61319 +
61320 +__u32
61321 +gr_acl_handle_mknod(const struct dentry * new_dentry,
61322 + const struct dentry * parent_dentry,
61323 + const struct vfsmount * parent_mnt,
61324 + const int mode)
61325 +{
61326 + __u32 reqmode = GR_WRITE | GR_CREATE;
61327 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61328 + reqmode |= GR_SETID;
61329 +
61330 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61331 + reqmode, GR_MKNOD_ACL_MSG);
61332 +}
61333 +
61334 +__u32
61335 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
61336 + const struct dentry *parent_dentry,
61337 + const struct vfsmount *parent_mnt)
61338 +{
61339 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61340 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
61341 +}
61342 +
61343 +#define RENAME_CHECK_SUCCESS(old, new) \
61344 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
61345 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
61346 +
61347 +int
61348 +gr_acl_handle_rename(struct dentry *new_dentry,
61349 + struct dentry *parent_dentry,
61350 + const struct vfsmount *parent_mnt,
61351 + struct dentry *old_dentry,
61352 + struct inode *old_parent_inode,
61353 + struct vfsmount *old_mnt, const struct filename *newname)
61354 +{
61355 + __u32 comp1, comp2;
61356 + int error = 0;
61357 +
61358 + if (unlikely(!gr_acl_is_enabled()))
61359 + return 0;
61360 +
61361 + if (!new_dentry->d_inode) {
61362 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
61363 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
61364 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
61365 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
61366 + GR_DELETE | GR_AUDIT_DELETE |
61367 + GR_AUDIT_READ | GR_AUDIT_WRITE |
61368 + GR_SUPPRESS, old_mnt);
61369 + } else {
61370 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
61371 + GR_CREATE | GR_DELETE |
61372 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
61373 + GR_AUDIT_READ | GR_AUDIT_WRITE |
61374 + GR_SUPPRESS, parent_mnt);
61375 + comp2 =
61376 + gr_search_file(old_dentry,
61377 + GR_READ | GR_WRITE | GR_AUDIT_READ |
61378 + GR_DELETE | GR_AUDIT_DELETE |
61379 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
61380 + }
61381 +
61382 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
61383 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
61384 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61385 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
61386 + && !(comp2 & GR_SUPPRESS)) {
61387 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61388 + error = -EACCES;
61389 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
61390 + error = -EACCES;
61391 +
61392 + return error;
61393 +}
61394 +
61395 +void
61396 +gr_acl_handle_exit(void)
61397 +{
61398 + u16 id;
61399 + char *rolename;
61400 +
61401 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
61402 + !(current->role->roletype & GR_ROLE_PERSIST))) {
61403 + id = current->acl_role_id;
61404 + rolename = current->role->rolename;
61405 + gr_set_acls(1);
61406 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
61407 + }
61408 +
61409 + gr_put_exec_file(current);
61410 + return;
61411 +}
61412 +
61413 +int
61414 +gr_acl_handle_procpidmem(const struct task_struct *task)
61415 +{
61416 + if (unlikely(!gr_acl_is_enabled()))
61417 + return 0;
61418 +
61419 + if (task != current && task->acl->mode & GR_PROTPROCFD)
61420 + return -EACCES;
61421 +
61422 + return 0;
61423 +}
61424 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
61425 new file mode 100644
61426 index 0000000..4699807
61427 --- /dev/null
61428 +++ b/grsecurity/gracl_ip.c
61429 @@ -0,0 +1,384 @@
61430 +#include <linux/kernel.h>
61431 +#include <asm/uaccess.h>
61432 +#include <asm/errno.h>
61433 +#include <net/sock.h>
61434 +#include <linux/file.h>
61435 +#include <linux/fs.h>
61436 +#include <linux/net.h>
61437 +#include <linux/in.h>
61438 +#include <linux/skbuff.h>
61439 +#include <linux/ip.h>
61440 +#include <linux/udp.h>
61441 +#include <linux/types.h>
61442 +#include <linux/sched.h>
61443 +#include <linux/netdevice.h>
61444 +#include <linux/inetdevice.h>
61445 +#include <linux/gracl.h>
61446 +#include <linux/grsecurity.h>
61447 +#include <linux/grinternal.h>
61448 +
61449 +#define GR_BIND 0x01
61450 +#define GR_CONNECT 0x02
61451 +#define GR_INVERT 0x04
61452 +#define GR_BINDOVERRIDE 0x08
61453 +#define GR_CONNECTOVERRIDE 0x10
61454 +#define GR_SOCK_FAMILY 0x20
61455 +
61456 +static const char * gr_protocols[IPPROTO_MAX] = {
61457 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
61458 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
61459 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
61460 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
61461 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
61462 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
61463 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
61464 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
61465 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
61466 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
61467 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
61468 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
61469 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
61470 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
61471 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
61472 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
61473 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
61474 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
61475 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
61476 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
61477 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
61478 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
61479 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
61480 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
61481 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
61482 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
61483 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
61484 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
61485 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
61486 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
61487 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
61488 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
61489 + };
61490 +
61491 +static const char * gr_socktypes[SOCK_MAX] = {
61492 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
61493 + "unknown:7", "unknown:8", "unknown:9", "packet"
61494 + };
61495 +
61496 +static const char * gr_sockfamilies[AF_MAX+1] = {
61497 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
61498 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
61499 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
61500 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
61501 + };
61502 +
61503 +const char *
61504 +gr_proto_to_name(unsigned char proto)
61505 +{
61506 + return gr_protocols[proto];
61507 +}
61508 +
61509 +const char *
61510 +gr_socktype_to_name(unsigned char type)
61511 +{
61512 + return gr_socktypes[type];
61513 +}
61514 +
61515 +const char *
61516 +gr_sockfamily_to_name(unsigned char family)
61517 +{
61518 + return gr_sockfamilies[family];
61519 +}
61520 +
61521 +int
61522 +gr_search_socket(const int domain, const int type, const int protocol)
61523 +{
61524 + struct acl_subject_label *curr;
61525 + const struct cred *cred = current_cred();
61526 +
61527 + if (unlikely(!gr_acl_is_enabled()))
61528 + goto exit;
61529 +
61530 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
61531 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
61532 + goto exit; // let the kernel handle it
61533 +
61534 + curr = current->acl;
61535 +
61536 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
61537 + /* the family is allowed, if this is PF_INET allow it only if
61538 + the extra sock type/protocol checks pass */
61539 + if (domain == PF_INET)
61540 + goto inet_check;
61541 + goto exit;
61542 + } else {
61543 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61544 + __u32 fakeip = 0;
61545 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61546 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61547 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61548 + gr_to_filename(current->exec_file->f_path.dentry,
61549 + current->exec_file->f_path.mnt) :
61550 + curr->filename, curr->filename,
61551 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
61552 + &current->signal->saved_ip);
61553 + goto exit;
61554 + }
61555 + goto exit_fail;
61556 + }
61557 +
61558 +inet_check:
61559 + /* the rest of this checking is for IPv4 only */
61560 + if (!curr->ips)
61561 + goto exit;
61562 +
61563 + if ((curr->ip_type & (1 << type)) &&
61564 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
61565 + goto exit;
61566 +
61567 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61568 + /* we don't place acls on raw sockets , and sometimes
61569 + dgram/ip sockets are opened for ioctl and not
61570 + bind/connect, so we'll fake a bind learn log */
61571 + if (type == SOCK_RAW || type == SOCK_PACKET) {
61572 + __u32 fakeip = 0;
61573 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61574 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61575 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61576 + gr_to_filename(current->exec_file->f_path.dentry,
61577 + current->exec_file->f_path.mnt) :
61578 + curr->filename, curr->filename,
61579 + &fakeip, 0, type,
61580 + protocol, GR_CONNECT, &current->signal->saved_ip);
61581 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
61582 + __u32 fakeip = 0;
61583 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61584 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61585 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61586 + gr_to_filename(current->exec_file->f_path.dentry,
61587 + current->exec_file->f_path.mnt) :
61588 + curr->filename, curr->filename,
61589 + &fakeip, 0, type,
61590 + protocol, GR_BIND, &current->signal->saved_ip);
61591 + }
61592 + /* we'll log when they use connect or bind */
61593 + goto exit;
61594 + }
61595 +
61596 +exit_fail:
61597 + if (domain == PF_INET)
61598 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
61599 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
61600 + else
61601 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
61602 + gr_socktype_to_name(type), protocol);
61603 +
61604 + return 0;
61605 +exit:
61606 + return 1;
61607 +}
61608 +
61609 +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)
61610 +{
61611 + if ((ip->mode & mode) &&
61612 + (ip_port >= ip->low) &&
61613 + (ip_port <= ip->high) &&
61614 + ((ntohl(ip_addr) & our_netmask) ==
61615 + (ntohl(our_addr) & our_netmask))
61616 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
61617 + && (ip->type & (1 << type))) {
61618 + if (ip->mode & GR_INVERT)
61619 + return 2; // specifically denied
61620 + else
61621 + return 1; // allowed
61622 + }
61623 +
61624 + return 0; // not specifically allowed, may continue parsing
61625 +}
61626 +
61627 +static int
61628 +gr_search_connectbind(const int full_mode, struct sock *sk,
61629 + struct sockaddr_in *addr, const int type)
61630 +{
61631 + char iface[IFNAMSIZ] = {0};
61632 + struct acl_subject_label *curr;
61633 + struct acl_ip_label *ip;
61634 + struct inet_sock *isk;
61635 + struct net_device *dev;
61636 + struct in_device *idev;
61637 + unsigned long i;
61638 + int ret;
61639 + int mode = full_mode & (GR_BIND | GR_CONNECT);
61640 + __u32 ip_addr = 0;
61641 + __u32 our_addr;
61642 + __u32 our_netmask;
61643 + char *p;
61644 + __u16 ip_port = 0;
61645 + const struct cred *cred = current_cred();
61646 +
61647 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
61648 + return 0;
61649 +
61650 + curr = current->acl;
61651 + isk = inet_sk(sk);
61652 +
61653 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
61654 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
61655 + addr->sin_addr.s_addr = curr->inaddr_any_override;
61656 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
61657 + struct sockaddr_in saddr;
61658 + int err;
61659 +
61660 + saddr.sin_family = AF_INET;
61661 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
61662 + saddr.sin_port = isk->inet_sport;
61663 +
61664 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
61665 + if (err)
61666 + return err;
61667 +
61668 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
61669 + if (err)
61670 + return err;
61671 + }
61672 +
61673 + if (!curr->ips)
61674 + return 0;
61675 +
61676 + ip_addr = addr->sin_addr.s_addr;
61677 + ip_port = ntohs(addr->sin_port);
61678 +
61679 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61680 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61681 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61682 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61683 + gr_to_filename(current->exec_file->f_path.dentry,
61684 + current->exec_file->f_path.mnt) :
61685 + curr->filename, curr->filename,
61686 + &ip_addr, ip_port, type,
61687 + sk->sk_protocol, mode, &current->signal->saved_ip);
61688 + return 0;
61689 + }
61690 +
61691 + for (i = 0; i < curr->ip_num; i++) {
61692 + ip = *(curr->ips + i);
61693 + if (ip->iface != NULL) {
61694 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
61695 + p = strchr(iface, ':');
61696 + if (p != NULL)
61697 + *p = '\0';
61698 + dev = dev_get_by_name(sock_net(sk), iface);
61699 + if (dev == NULL)
61700 + continue;
61701 + idev = in_dev_get(dev);
61702 + if (idev == NULL) {
61703 + dev_put(dev);
61704 + continue;
61705 + }
61706 + rcu_read_lock();
61707 + for_ifa(idev) {
61708 + if (!strcmp(ip->iface, ifa->ifa_label)) {
61709 + our_addr = ifa->ifa_address;
61710 + our_netmask = 0xffffffff;
61711 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
61712 + if (ret == 1) {
61713 + rcu_read_unlock();
61714 + in_dev_put(idev);
61715 + dev_put(dev);
61716 + return 0;
61717 + } else if (ret == 2) {
61718 + rcu_read_unlock();
61719 + in_dev_put(idev);
61720 + dev_put(dev);
61721 + goto denied;
61722 + }
61723 + }
61724 + } endfor_ifa(idev);
61725 + rcu_read_unlock();
61726 + in_dev_put(idev);
61727 + dev_put(dev);
61728 + } else {
61729 + our_addr = ip->addr;
61730 + our_netmask = ip->netmask;
61731 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
61732 + if (ret == 1)
61733 + return 0;
61734 + else if (ret == 2)
61735 + goto denied;
61736 + }
61737 + }
61738 +
61739 +denied:
61740 + if (mode == GR_BIND)
61741 + 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));
61742 + else if (mode == GR_CONNECT)
61743 + 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));
61744 +
61745 + return -EACCES;
61746 +}
61747 +
61748 +int
61749 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
61750 +{
61751 + /* always allow disconnection of dgram sockets with connect */
61752 + if (addr->sin_family == AF_UNSPEC)
61753 + return 0;
61754 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
61755 +}
61756 +
61757 +int
61758 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
61759 +{
61760 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
61761 +}
61762 +
61763 +int gr_search_listen(struct socket *sock)
61764 +{
61765 + struct sock *sk = sock->sk;
61766 + struct sockaddr_in addr;
61767 +
61768 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
61769 + addr.sin_port = inet_sk(sk)->inet_sport;
61770 +
61771 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
61772 +}
61773 +
61774 +int gr_search_accept(struct socket *sock)
61775 +{
61776 + struct sock *sk = sock->sk;
61777 + struct sockaddr_in addr;
61778 +
61779 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
61780 + addr.sin_port = inet_sk(sk)->inet_sport;
61781 +
61782 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
61783 +}
61784 +
61785 +int
61786 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
61787 +{
61788 + if (addr)
61789 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
61790 + else {
61791 + struct sockaddr_in sin;
61792 + const struct inet_sock *inet = inet_sk(sk);
61793 +
61794 + sin.sin_addr.s_addr = inet->inet_daddr;
61795 + sin.sin_port = inet->inet_dport;
61796 +
61797 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
61798 + }
61799 +}
61800 +
61801 +int
61802 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
61803 +{
61804 + struct sockaddr_in sin;
61805 +
61806 + if (unlikely(skb->len < sizeof (struct udphdr)))
61807 + return 0; // skip this packet
61808 +
61809 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
61810 + sin.sin_port = udp_hdr(skb)->source;
61811 +
61812 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
61813 +}
61814 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
61815 new file mode 100644
61816 index 0000000..25f54ef
61817 --- /dev/null
61818 +++ b/grsecurity/gracl_learn.c
61819 @@ -0,0 +1,207 @@
61820 +#include <linux/kernel.h>
61821 +#include <linux/mm.h>
61822 +#include <linux/sched.h>
61823 +#include <linux/poll.h>
61824 +#include <linux/string.h>
61825 +#include <linux/file.h>
61826 +#include <linux/types.h>
61827 +#include <linux/vmalloc.h>
61828 +#include <linux/grinternal.h>
61829 +
61830 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
61831 + size_t count, loff_t *ppos);
61832 +extern int gr_acl_is_enabled(void);
61833 +
61834 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
61835 +static int gr_learn_attached;
61836 +
61837 +/* use a 512k buffer */
61838 +#define LEARN_BUFFER_SIZE (512 * 1024)
61839 +
61840 +static DEFINE_SPINLOCK(gr_learn_lock);
61841 +static DEFINE_MUTEX(gr_learn_user_mutex);
61842 +
61843 +/* we need to maintain two buffers, so that the kernel context of grlearn
61844 + uses a semaphore around the userspace copying, and the other kernel contexts
61845 + use a spinlock when copying into the buffer, since they cannot sleep
61846 +*/
61847 +static char *learn_buffer;
61848 +static char *learn_buffer_user;
61849 +static int learn_buffer_len;
61850 +static int learn_buffer_user_len;
61851 +
61852 +static ssize_t
61853 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
61854 +{
61855 + DECLARE_WAITQUEUE(wait, current);
61856 + ssize_t retval = 0;
61857 +
61858 + add_wait_queue(&learn_wait, &wait);
61859 + set_current_state(TASK_INTERRUPTIBLE);
61860 + do {
61861 + mutex_lock(&gr_learn_user_mutex);
61862 + spin_lock(&gr_learn_lock);
61863 + if (learn_buffer_len)
61864 + break;
61865 + spin_unlock(&gr_learn_lock);
61866 + mutex_unlock(&gr_learn_user_mutex);
61867 + if (file->f_flags & O_NONBLOCK) {
61868 + retval = -EAGAIN;
61869 + goto out;
61870 + }
61871 + if (signal_pending(current)) {
61872 + retval = -ERESTARTSYS;
61873 + goto out;
61874 + }
61875 +
61876 + schedule();
61877 + } while (1);
61878 +
61879 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
61880 + learn_buffer_user_len = learn_buffer_len;
61881 + retval = learn_buffer_len;
61882 + learn_buffer_len = 0;
61883 +
61884 + spin_unlock(&gr_learn_lock);
61885 +
61886 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
61887 + retval = -EFAULT;
61888 +
61889 + mutex_unlock(&gr_learn_user_mutex);
61890 +out:
61891 + set_current_state(TASK_RUNNING);
61892 + remove_wait_queue(&learn_wait, &wait);
61893 + return retval;
61894 +}
61895 +
61896 +static unsigned int
61897 +poll_learn(struct file * file, poll_table * wait)
61898 +{
61899 + poll_wait(file, &learn_wait, wait);
61900 +
61901 + if (learn_buffer_len)
61902 + return (POLLIN | POLLRDNORM);
61903 +
61904 + return 0;
61905 +}
61906 +
61907 +void
61908 +gr_clear_learn_entries(void)
61909 +{
61910 + char *tmp;
61911 +
61912 + mutex_lock(&gr_learn_user_mutex);
61913 + spin_lock(&gr_learn_lock);
61914 + tmp = learn_buffer;
61915 + learn_buffer = NULL;
61916 + spin_unlock(&gr_learn_lock);
61917 + if (tmp)
61918 + vfree(tmp);
61919 + if (learn_buffer_user != NULL) {
61920 + vfree(learn_buffer_user);
61921 + learn_buffer_user = NULL;
61922 + }
61923 + learn_buffer_len = 0;
61924 + mutex_unlock(&gr_learn_user_mutex);
61925 +
61926 + return;
61927 +}
61928 +
61929 +void
61930 +gr_add_learn_entry(const char *fmt, ...)
61931 +{
61932 + va_list args;
61933 + unsigned int len;
61934 +
61935 + if (!gr_learn_attached)
61936 + return;
61937 +
61938 + spin_lock(&gr_learn_lock);
61939 +
61940 + /* leave a gap at the end so we know when it's "full" but don't have to
61941 + compute the exact length of the string we're trying to append
61942 + */
61943 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
61944 + spin_unlock(&gr_learn_lock);
61945 + wake_up_interruptible(&learn_wait);
61946 + return;
61947 + }
61948 + if (learn_buffer == NULL) {
61949 + spin_unlock(&gr_learn_lock);
61950 + return;
61951 + }
61952 +
61953 + va_start(args, fmt);
61954 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
61955 + va_end(args);
61956 +
61957 + learn_buffer_len += len + 1;
61958 +
61959 + spin_unlock(&gr_learn_lock);
61960 + wake_up_interruptible(&learn_wait);
61961 +
61962 + return;
61963 +}
61964 +
61965 +static int
61966 +open_learn(struct inode *inode, struct file *file)
61967 +{
61968 + if (file->f_mode & FMODE_READ && gr_learn_attached)
61969 + return -EBUSY;
61970 + if (file->f_mode & FMODE_READ) {
61971 + int retval = 0;
61972 + mutex_lock(&gr_learn_user_mutex);
61973 + if (learn_buffer == NULL)
61974 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
61975 + if (learn_buffer_user == NULL)
61976 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
61977 + if (learn_buffer == NULL) {
61978 + retval = -ENOMEM;
61979 + goto out_error;
61980 + }
61981 + if (learn_buffer_user == NULL) {
61982 + retval = -ENOMEM;
61983 + goto out_error;
61984 + }
61985 + learn_buffer_len = 0;
61986 + learn_buffer_user_len = 0;
61987 + gr_learn_attached = 1;
61988 +out_error:
61989 + mutex_unlock(&gr_learn_user_mutex);
61990 + return retval;
61991 + }
61992 + return 0;
61993 +}
61994 +
61995 +static int
61996 +close_learn(struct inode *inode, struct file *file)
61997 +{
61998 + if (file->f_mode & FMODE_READ) {
61999 + char *tmp = NULL;
62000 + mutex_lock(&gr_learn_user_mutex);
62001 + spin_lock(&gr_learn_lock);
62002 + tmp = learn_buffer;
62003 + learn_buffer = NULL;
62004 + spin_unlock(&gr_learn_lock);
62005 + if (tmp)
62006 + vfree(tmp);
62007 + if (learn_buffer_user != NULL) {
62008 + vfree(learn_buffer_user);
62009 + learn_buffer_user = NULL;
62010 + }
62011 + learn_buffer_len = 0;
62012 + learn_buffer_user_len = 0;
62013 + gr_learn_attached = 0;
62014 + mutex_unlock(&gr_learn_user_mutex);
62015 + }
62016 +
62017 + return 0;
62018 +}
62019 +
62020 +const struct file_operations grsec_fops = {
62021 + .read = read_learn,
62022 + .write = write_grsec_handler,
62023 + .open = open_learn,
62024 + .release = close_learn,
62025 + .poll = poll_learn,
62026 +};
62027 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
62028 new file mode 100644
62029 index 0000000..39645c9
62030 --- /dev/null
62031 +++ b/grsecurity/gracl_res.c
62032 @@ -0,0 +1,68 @@
62033 +#include <linux/kernel.h>
62034 +#include <linux/sched.h>
62035 +#include <linux/gracl.h>
62036 +#include <linux/grinternal.h>
62037 +
62038 +static const char *restab_log[] = {
62039 + [RLIMIT_CPU] = "RLIMIT_CPU",
62040 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
62041 + [RLIMIT_DATA] = "RLIMIT_DATA",
62042 + [RLIMIT_STACK] = "RLIMIT_STACK",
62043 + [RLIMIT_CORE] = "RLIMIT_CORE",
62044 + [RLIMIT_RSS] = "RLIMIT_RSS",
62045 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
62046 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
62047 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
62048 + [RLIMIT_AS] = "RLIMIT_AS",
62049 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
62050 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
62051 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
62052 + [RLIMIT_NICE] = "RLIMIT_NICE",
62053 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
62054 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
62055 + [GR_CRASH_RES] = "RLIMIT_CRASH"
62056 +};
62057 +
62058 +void
62059 +gr_log_resource(const struct task_struct *task,
62060 + const int res, const unsigned long wanted, const int gt)
62061 +{
62062 + const struct cred *cred;
62063 + unsigned long rlim;
62064 +
62065 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
62066 + return;
62067 +
62068 + // not yet supported resource
62069 + if (unlikely(!restab_log[res]))
62070 + return;
62071 +
62072 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
62073 + rlim = task_rlimit_max(task, res);
62074 + else
62075 + rlim = task_rlimit(task, res);
62076 +
62077 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
62078 + return;
62079 +
62080 + rcu_read_lock();
62081 + cred = __task_cred(task);
62082 +
62083 + if (res == RLIMIT_NPROC &&
62084 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
62085 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
62086 + goto out_rcu_unlock;
62087 + else if (res == RLIMIT_MEMLOCK &&
62088 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
62089 + goto out_rcu_unlock;
62090 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
62091 + goto out_rcu_unlock;
62092 + rcu_read_unlock();
62093 +
62094 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
62095 +
62096 + return;
62097 +out_rcu_unlock:
62098 + rcu_read_unlock();
62099 + return;
62100 +}
62101 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
62102 new file mode 100644
62103 index 0000000..8c8fc9d
62104 --- /dev/null
62105 +++ b/grsecurity/gracl_segv.c
62106 @@ -0,0 +1,303 @@
62107 +#include <linux/kernel.h>
62108 +#include <linux/mm.h>
62109 +#include <asm/uaccess.h>
62110 +#include <asm/errno.h>
62111 +#include <asm/mman.h>
62112 +#include <net/sock.h>
62113 +#include <linux/file.h>
62114 +#include <linux/fs.h>
62115 +#include <linux/net.h>
62116 +#include <linux/in.h>
62117 +#include <linux/slab.h>
62118 +#include <linux/types.h>
62119 +#include <linux/sched.h>
62120 +#include <linux/timer.h>
62121 +#include <linux/gracl.h>
62122 +#include <linux/grsecurity.h>
62123 +#include <linux/grinternal.h>
62124 +
62125 +static struct crash_uid *uid_set;
62126 +static unsigned short uid_used;
62127 +static DEFINE_SPINLOCK(gr_uid_lock);
62128 +extern rwlock_t gr_inode_lock;
62129 +extern struct acl_subject_label *
62130 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
62131 + struct acl_role_label *role);
62132 +
62133 +#ifdef CONFIG_BTRFS_FS
62134 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
62135 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
62136 +#endif
62137 +
62138 +static inline dev_t __get_dev(const struct dentry *dentry)
62139 +{
62140 +#ifdef CONFIG_BTRFS_FS
62141 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
62142 + return get_btrfs_dev_from_inode(dentry->d_inode);
62143 + else
62144 +#endif
62145 + return dentry->d_inode->i_sb->s_dev;
62146 +}
62147 +
62148 +int
62149 +gr_init_uidset(void)
62150 +{
62151 + uid_set =
62152 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
62153 + uid_used = 0;
62154 +
62155 + return uid_set ? 1 : 0;
62156 +}
62157 +
62158 +void
62159 +gr_free_uidset(void)
62160 +{
62161 + if (uid_set)
62162 + kfree(uid_set);
62163 +
62164 + return;
62165 +}
62166 +
62167 +int
62168 +gr_find_uid(const uid_t uid)
62169 +{
62170 + struct crash_uid *tmp = uid_set;
62171 + uid_t buid;
62172 + int low = 0, high = uid_used - 1, mid;
62173 +
62174 + while (high >= low) {
62175 + mid = (low + high) >> 1;
62176 + buid = tmp[mid].uid;
62177 + if (buid == uid)
62178 + return mid;
62179 + if (buid > uid)
62180 + high = mid - 1;
62181 + if (buid < uid)
62182 + low = mid + 1;
62183 + }
62184 +
62185 + return -1;
62186 +}
62187 +
62188 +static __inline__ void
62189 +gr_insertsort(void)
62190 +{
62191 + unsigned short i, j;
62192 + struct crash_uid index;
62193 +
62194 + for (i = 1; i < uid_used; i++) {
62195 + index = uid_set[i];
62196 + j = i;
62197 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
62198 + uid_set[j] = uid_set[j - 1];
62199 + j--;
62200 + }
62201 + uid_set[j] = index;
62202 + }
62203 +
62204 + return;
62205 +}
62206 +
62207 +static __inline__ void
62208 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
62209 +{
62210 + int loc;
62211 + uid_t uid = GR_GLOBAL_UID(kuid);
62212 +
62213 + if (uid_used == GR_UIDTABLE_MAX)
62214 + return;
62215 +
62216 + loc = gr_find_uid(uid);
62217 +
62218 + if (loc >= 0) {
62219 + uid_set[loc].expires = expires;
62220 + return;
62221 + }
62222 +
62223 + uid_set[uid_used].uid = uid;
62224 + uid_set[uid_used].expires = expires;
62225 + uid_used++;
62226 +
62227 + gr_insertsort();
62228 +
62229 + return;
62230 +}
62231 +
62232 +void
62233 +gr_remove_uid(const unsigned short loc)
62234 +{
62235 + unsigned short i;
62236 +
62237 + for (i = loc + 1; i < uid_used; i++)
62238 + uid_set[i - 1] = uid_set[i];
62239 +
62240 + uid_used--;
62241 +
62242 + return;
62243 +}
62244 +
62245 +int
62246 +gr_check_crash_uid(const kuid_t kuid)
62247 +{
62248 + int loc;
62249 + int ret = 0;
62250 + uid_t uid;
62251 +
62252 + if (unlikely(!gr_acl_is_enabled()))
62253 + return 0;
62254 +
62255 + uid = GR_GLOBAL_UID(kuid);
62256 +
62257 + spin_lock(&gr_uid_lock);
62258 + loc = gr_find_uid(uid);
62259 +
62260 + if (loc < 0)
62261 + goto out_unlock;
62262 +
62263 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
62264 + gr_remove_uid(loc);
62265 + else
62266 + ret = 1;
62267 +
62268 +out_unlock:
62269 + spin_unlock(&gr_uid_lock);
62270 + return ret;
62271 +}
62272 +
62273 +static __inline__ int
62274 +proc_is_setxid(const struct cred *cred)
62275 +{
62276 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
62277 + !uid_eq(cred->uid, cred->fsuid))
62278 + return 1;
62279 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
62280 + !gid_eq(cred->gid, cred->fsgid))
62281 + return 1;
62282 +
62283 + return 0;
62284 +}
62285 +
62286 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
62287 +
62288 +void
62289 +gr_handle_crash(struct task_struct *task, const int sig)
62290 +{
62291 + struct acl_subject_label *curr;
62292 + struct task_struct *tsk, *tsk2;
62293 + const struct cred *cred;
62294 + const struct cred *cred2;
62295 +
62296 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
62297 + return;
62298 +
62299 + if (unlikely(!gr_acl_is_enabled()))
62300 + return;
62301 +
62302 + curr = task->acl;
62303 +
62304 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
62305 + return;
62306 +
62307 + if (time_before_eq(curr->expires, get_seconds())) {
62308 + curr->expires = 0;
62309 + curr->crashes = 0;
62310 + }
62311 +
62312 + curr->crashes++;
62313 +
62314 + if (!curr->expires)
62315 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
62316 +
62317 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62318 + time_after(curr->expires, get_seconds())) {
62319 + rcu_read_lock();
62320 + cred = __task_cred(task);
62321 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
62322 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62323 + spin_lock(&gr_uid_lock);
62324 + gr_insert_uid(cred->uid, curr->expires);
62325 + spin_unlock(&gr_uid_lock);
62326 + curr->expires = 0;
62327 + curr->crashes = 0;
62328 + read_lock(&tasklist_lock);
62329 + do_each_thread(tsk2, tsk) {
62330 + cred2 = __task_cred(tsk);
62331 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
62332 + gr_fake_force_sig(SIGKILL, tsk);
62333 + } while_each_thread(tsk2, tsk);
62334 + read_unlock(&tasklist_lock);
62335 + } else {
62336 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62337 + read_lock(&tasklist_lock);
62338 + read_lock(&grsec_exec_file_lock);
62339 + do_each_thread(tsk2, tsk) {
62340 + if (likely(tsk != task)) {
62341 + // if this thread has the same subject as the one that triggered
62342 + // RES_CRASH and it's the same binary, kill it
62343 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
62344 + gr_fake_force_sig(SIGKILL, tsk);
62345 + }
62346 + } while_each_thread(tsk2, tsk);
62347 + read_unlock(&grsec_exec_file_lock);
62348 + read_unlock(&tasklist_lock);
62349 + }
62350 + rcu_read_unlock();
62351 + }
62352 +
62353 + return;
62354 +}
62355 +
62356 +int
62357 +gr_check_crash_exec(const struct file *filp)
62358 +{
62359 + struct acl_subject_label *curr;
62360 +
62361 + if (unlikely(!gr_acl_is_enabled()))
62362 + return 0;
62363 +
62364 + read_lock(&gr_inode_lock);
62365 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
62366 + __get_dev(filp->f_path.dentry),
62367 + current->role);
62368 + read_unlock(&gr_inode_lock);
62369 +
62370 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
62371 + (!curr->crashes && !curr->expires))
62372 + return 0;
62373 +
62374 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62375 + time_after(curr->expires, get_seconds()))
62376 + return 1;
62377 + else if (time_before_eq(curr->expires, get_seconds())) {
62378 + curr->crashes = 0;
62379 + curr->expires = 0;
62380 + }
62381 +
62382 + return 0;
62383 +}
62384 +
62385 +void
62386 +gr_handle_alertkill(struct task_struct *task)
62387 +{
62388 + struct acl_subject_label *curracl;
62389 + __u32 curr_ip;
62390 + struct task_struct *p, *p2;
62391 +
62392 + if (unlikely(!gr_acl_is_enabled()))
62393 + return;
62394 +
62395 + curracl = task->acl;
62396 + curr_ip = task->signal->curr_ip;
62397 +
62398 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
62399 + read_lock(&tasklist_lock);
62400 + do_each_thread(p2, p) {
62401 + if (p->signal->curr_ip == curr_ip)
62402 + gr_fake_force_sig(SIGKILL, p);
62403 + } while_each_thread(p2, p);
62404 + read_unlock(&tasklist_lock);
62405 + } else if (curracl->mode & GR_KILLPROC)
62406 + gr_fake_force_sig(SIGKILL, task);
62407 +
62408 + return;
62409 +}
62410 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
62411 new file mode 100644
62412 index 0000000..98011b0
62413 --- /dev/null
62414 +++ b/grsecurity/gracl_shm.c
62415 @@ -0,0 +1,40 @@
62416 +#include <linux/kernel.h>
62417 +#include <linux/mm.h>
62418 +#include <linux/sched.h>
62419 +#include <linux/file.h>
62420 +#include <linux/ipc.h>
62421 +#include <linux/gracl.h>
62422 +#include <linux/grsecurity.h>
62423 +#include <linux/grinternal.h>
62424 +
62425 +int
62426 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62427 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
62428 +{
62429 + struct task_struct *task;
62430 +
62431 + if (!gr_acl_is_enabled())
62432 + return 1;
62433 +
62434 + rcu_read_lock();
62435 + read_lock(&tasklist_lock);
62436 +
62437 + task = find_task_by_vpid(shm_cprid);
62438 +
62439 + if (unlikely(!task))
62440 + task = find_task_by_vpid(shm_lapid);
62441 +
62442 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
62443 + (task_pid_nr(task) == shm_lapid)) &&
62444 + (task->acl->mode & GR_PROTSHM) &&
62445 + (task->acl != current->acl))) {
62446 + read_unlock(&tasklist_lock);
62447 + rcu_read_unlock();
62448 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
62449 + return 0;
62450 + }
62451 + read_unlock(&tasklist_lock);
62452 + rcu_read_unlock();
62453 +
62454 + return 1;
62455 +}
62456 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
62457 new file mode 100644
62458 index 0000000..bc0be01
62459 --- /dev/null
62460 +++ b/grsecurity/grsec_chdir.c
62461 @@ -0,0 +1,19 @@
62462 +#include <linux/kernel.h>
62463 +#include <linux/sched.h>
62464 +#include <linux/fs.h>
62465 +#include <linux/file.h>
62466 +#include <linux/grsecurity.h>
62467 +#include <linux/grinternal.h>
62468 +
62469 +void
62470 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
62471 +{
62472 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62473 + if ((grsec_enable_chdir && grsec_enable_group &&
62474 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
62475 + !grsec_enable_group)) {
62476 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
62477 + }
62478 +#endif
62479 + return;
62480 +}
62481 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
62482 new file mode 100644
62483 index 0000000..6d2de57
62484 --- /dev/null
62485 +++ b/grsecurity/grsec_chroot.c
62486 @@ -0,0 +1,357 @@
62487 +#include <linux/kernel.h>
62488 +#include <linux/module.h>
62489 +#include <linux/sched.h>
62490 +#include <linux/file.h>
62491 +#include <linux/fs.h>
62492 +#include <linux/mount.h>
62493 +#include <linux/types.h>
62494 +#include "../fs/mount.h"
62495 +#include <linux/grsecurity.h>
62496 +#include <linux/grinternal.h>
62497 +
62498 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
62499 +{
62500 +#ifdef CONFIG_GRKERNSEC
62501 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
62502 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
62503 + task->gr_is_chrooted = 1;
62504 + else
62505 + task->gr_is_chrooted = 0;
62506 +
62507 + task->gr_chroot_dentry = path->dentry;
62508 +#endif
62509 + return;
62510 +}
62511 +
62512 +void gr_clear_chroot_entries(struct task_struct *task)
62513 +{
62514 +#ifdef CONFIG_GRKERNSEC
62515 + task->gr_is_chrooted = 0;
62516 + task->gr_chroot_dentry = NULL;
62517 +#endif
62518 + return;
62519 +}
62520 +
62521 +int
62522 +gr_handle_chroot_unix(const pid_t pid)
62523 +{
62524 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62525 + struct task_struct *p;
62526 +
62527 + if (unlikely(!grsec_enable_chroot_unix))
62528 + return 1;
62529 +
62530 + if (likely(!proc_is_chrooted(current)))
62531 + return 1;
62532 +
62533 + rcu_read_lock();
62534 + read_lock(&tasklist_lock);
62535 + p = find_task_by_vpid_unrestricted(pid);
62536 + if (unlikely(p && !have_same_root(current, p))) {
62537 + read_unlock(&tasklist_lock);
62538 + rcu_read_unlock();
62539 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
62540 + return 0;
62541 + }
62542 + read_unlock(&tasklist_lock);
62543 + rcu_read_unlock();
62544 +#endif
62545 + return 1;
62546 +}
62547 +
62548 +int
62549 +gr_handle_chroot_nice(void)
62550 +{
62551 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62552 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
62553 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
62554 + return -EPERM;
62555 + }
62556 +#endif
62557 + return 0;
62558 +}
62559 +
62560 +int
62561 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
62562 +{
62563 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62564 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
62565 + && proc_is_chrooted(current)) {
62566 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
62567 + return -EACCES;
62568 + }
62569 +#endif
62570 + return 0;
62571 +}
62572 +
62573 +int
62574 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
62575 +{
62576 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62577 + struct task_struct *p;
62578 + int ret = 0;
62579 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
62580 + return ret;
62581 +
62582 + read_lock(&tasklist_lock);
62583 + do_each_pid_task(pid, type, p) {
62584 + if (!have_same_root(current, p)) {
62585 + ret = 1;
62586 + goto out;
62587 + }
62588 + } while_each_pid_task(pid, type, p);
62589 +out:
62590 + read_unlock(&tasklist_lock);
62591 + return ret;
62592 +#endif
62593 + return 0;
62594 +}
62595 +
62596 +int
62597 +gr_pid_is_chrooted(struct task_struct *p)
62598 +{
62599 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62600 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
62601 + return 0;
62602 +
62603 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
62604 + !have_same_root(current, p)) {
62605 + return 1;
62606 + }
62607 +#endif
62608 + return 0;
62609 +}
62610 +
62611 +EXPORT_SYMBOL(gr_pid_is_chrooted);
62612 +
62613 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
62614 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
62615 +{
62616 + struct path path, currentroot;
62617 + int ret = 0;
62618 +
62619 + path.dentry = (struct dentry *)u_dentry;
62620 + path.mnt = (struct vfsmount *)u_mnt;
62621 + get_fs_root(current->fs, &currentroot);
62622 + if (path_is_under(&path, &currentroot))
62623 + ret = 1;
62624 + path_put(&currentroot);
62625 +
62626 + return ret;
62627 +}
62628 +#endif
62629 +
62630 +int
62631 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
62632 +{
62633 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62634 + if (!grsec_enable_chroot_fchdir)
62635 + return 1;
62636 +
62637 + if (!proc_is_chrooted(current))
62638 + return 1;
62639 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
62640 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
62641 + return 0;
62642 + }
62643 +#endif
62644 + return 1;
62645 +}
62646 +
62647 +int
62648 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62649 + const time_t shm_createtime)
62650 +{
62651 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62652 + struct task_struct *p;
62653 + time_t starttime;
62654 +
62655 + if (unlikely(!grsec_enable_chroot_shmat))
62656 + return 1;
62657 +
62658 + if (likely(!proc_is_chrooted(current)))
62659 + return 1;
62660 +
62661 + rcu_read_lock();
62662 + read_lock(&tasklist_lock);
62663 +
62664 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
62665 + starttime = p->start_time.tv_sec;
62666 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
62667 + if (have_same_root(current, p)) {
62668 + goto allow;
62669 + } else {
62670 + read_unlock(&tasklist_lock);
62671 + rcu_read_unlock();
62672 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
62673 + return 0;
62674 + }
62675 + }
62676 + /* creator exited, pid reuse, fall through to next check */
62677 + }
62678 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
62679 + if (unlikely(!have_same_root(current, p))) {
62680 + read_unlock(&tasklist_lock);
62681 + rcu_read_unlock();
62682 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
62683 + return 0;
62684 + }
62685 + }
62686 +
62687 +allow:
62688 + read_unlock(&tasklist_lock);
62689 + rcu_read_unlock();
62690 +#endif
62691 + return 1;
62692 +}
62693 +
62694 +void
62695 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
62696 +{
62697 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62698 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
62699 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
62700 +#endif
62701 + return;
62702 +}
62703 +
62704 +int
62705 +gr_handle_chroot_mknod(const struct dentry *dentry,
62706 + const struct vfsmount *mnt, const int mode)
62707 +{
62708 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62709 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
62710 + proc_is_chrooted(current)) {
62711 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
62712 + return -EPERM;
62713 + }
62714 +#endif
62715 + return 0;
62716 +}
62717 +
62718 +int
62719 +gr_handle_chroot_mount(const struct dentry *dentry,
62720 + const struct vfsmount *mnt, const char *dev_name)
62721 +{
62722 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62723 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
62724 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
62725 + return -EPERM;
62726 + }
62727 +#endif
62728 + return 0;
62729 +}
62730 +
62731 +int
62732 +gr_handle_chroot_pivot(void)
62733 +{
62734 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62735 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
62736 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
62737 + return -EPERM;
62738 + }
62739 +#endif
62740 + return 0;
62741 +}
62742 +
62743 +int
62744 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
62745 +{
62746 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62747 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
62748 + !gr_is_outside_chroot(dentry, mnt)) {
62749 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
62750 + return -EPERM;
62751 + }
62752 +#endif
62753 + return 0;
62754 +}
62755 +
62756 +extern const char *captab_log[];
62757 +extern int captab_log_entries;
62758 +
62759 +int
62760 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62761 +{
62762 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62763 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
62764 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
62765 + if (cap_raised(chroot_caps, cap)) {
62766 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
62767 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
62768 + }
62769 + return 0;
62770 + }
62771 + }
62772 +#endif
62773 + return 1;
62774 +}
62775 +
62776 +int
62777 +gr_chroot_is_capable(const int cap)
62778 +{
62779 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62780 + return gr_task_chroot_is_capable(current, current_cred(), cap);
62781 +#endif
62782 + return 1;
62783 +}
62784 +
62785 +int
62786 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
62787 +{
62788 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62789 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
62790 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
62791 + if (cap_raised(chroot_caps, cap)) {
62792 + return 0;
62793 + }
62794 + }
62795 +#endif
62796 + return 1;
62797 +}
62798 +
62799 +int
62800 +gr_chroot_is_capable_nolog(const int cap)
62801 +{
62802 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62803 + return gr_task_chroot_is_capable_nolog(current, cap);
62804 +#endif
62805 + return 1;
62806 +}
62807 +
62808 +int
62809 +gr_handle_chroot_sysctl(const int op)
62810 +{
62811 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62812 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
62813 + proc_is_chrooted(current))
62814 + return -EACCES;
62815 +#endif
62816 + return 0;
62817 +}
62818 +
62819 +void
62820 +gr_handle_chroot_chdir(struct path *path)
62821 +{
62822 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62823 + if (grsec_enable_chroot_chdir)
62824 + set_fs_pwd(current->fs, path);
62825 +#endif
62826 + return;
62827 +}
62828 +
62829 +int
62830 +gr_handle_chroot_chmod(const struct dentry *dentry,
62831 + const struct vfsmount *mnt, const int mode)
62832 +{
62833 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62834 + /* allow chmod +s on directories, but not files */
62835 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
62836 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
62837 + proc_is_chrooted(current)) {
62838 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
62839 + return -EPERM;
62840 + }
62841 +#endif
62842 + return 0;
62843 +}
62844 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
62845 new file mode 100644
62846 index 0000000..207d409
62847 --- /dev/null
62848 +++ b/grsecurity/grsec_disabled.c
62849 @@ -0,0 +1,434 @@
62850 +#include <linux/kernel.h>
62851 +#include <linux/module.h>
62852 +#include <linux/sched.h>
62853 +#include <linux/file.h>
62854 +#include <linux/fs.h>
62855 +#include <linux/kdev_t.h>
62856 +#include <linux/net.h>
62857 +#include <linux/in.h>
62858 +#include <linux/ip.h>
62859 +#include <linux/skbuff.h>
62860 +#include <linux/sysctl.h>
62861 +
62862 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62863 +void
62864 +pax_set_initial_flags(struct linux_binprm *bprm)
62865 +{
62866 + return;
62867 +}
62868 +#endif
62869 +
62870 +#ifdef CONFIG_SYSCTL
62871 +__u32
62872 +gr_handle_sysctl(const struct ctl_table * table, const int op)
62873 +{
62874 + return 0;
62875 +}
62876 +#endif
62877 +
62878 +#ifdef CONFIG_TASKSTATS
62879 +int gr_is_taskstats_denied(int pid)
62880 +{
62881 + return 0;
62882 +}
62883 +#endif
62884 +
62885 +int
62886 +gr_acl_is_enabled(void)
62887 +{
62888 + return 0;
62889 +}
62890 +
62891 +void
62892 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
62893 +{
62894 + return;
62895 +}
62896 +
62897 +int
62898 +gr_handle_rawio(const struct inode *inode)
62899 +{
62900 + return 0;
62901 +}
62902 +
62903 +void
62904 +gr_acl_handle_psacct(struct task_struct *task, const long code)
62905 +{
62906 + return;
62907 +}
62908 +
62909 +int
62910 +gr_handle_ptrace(struct task_struct *task, const long request)
62911 +{
62912 + return 0;
62913 +}
62914 +
62915 +int
62916 +gr_handle_proc_ptrace(struct task_struct *task)
62917 +{
62918 + return 0;
62919 +}
62920 +
62921 +int
62922 +gr_set_acls(const int type)
62923 +{
62924 + return 0;
62925 +}
62926 +
62927 +int
62928 +gr_check_hidden_task(const struct task_struct *tsk)
62929 +{
62930 + return 0;
62931 +}
62932 +
62933 +int
62934 +gr_check_protected_task(const struct task_struct *task)
62935 +{
62936 + return 0;
62937 +}
62938 +
62939 +int
62940 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
62941 +{
62942 + return 0;
62943 +}
62944 +
62945 +void
62946 +gr_copy_label(struct task_struct *tsk)
62947 +{
62948 + return;
62949 +}
62950 +
62951 +void
62952 +gr_set_pax_flags(struct task_struct *task)
62953 +{
62954 + return;
62955 +}
62956 +
62957 +int
62958 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
62959 + const int unsafe_share)
62960 +{
62961 + return 0;
62962 +}
62963 +
62964 +void
62965 +gr_handle_delete(const ino_t ino, const dev_t dev)
62966 +{
62967 + return;
62968 +}
62969 +
62970 +void
62971 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
62972 +{
62973 + return;
62974 +}
62975 +
62976 +void
62977 +gr_handle_crash(struct task_struct *task, const int sig)
62978 +{
62979 + return;
62980 +}
62981 +
62982 +int
62983 +gr_check_crash_exec(const struct file *filp)
62984 +{
62985 + return 0;
62986 +}
62987 +
62988 +int
62989 +gr_check_crash_uid(const kuid_t uid)
62990 +{
62991 + return 0;
62992 +}
62993 +
62994 +void
62995 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62996 + struct dentry *old_dentry,
62997 + struct dentry *new_dentry,
62998 + struct vfsmount *mnt, const __u8 replace)
62999 +{
63000 + return;
63001 +}
63002 +
63003 +int
63004 +gr_search_socket(const int family, const int type, const int protocol)
63005 +{
63006 + return 1;
63007 +}
63008 +
63009 +int
63010 +gr_search_connectbind(const int mode, const struct socket *sock,
63011 + const struct sockaddr_in *addr)
63012 +{
63013 + return 0;
63014 +}
63015 +
63016 +void
63017 +gr_handle_alertkill(struct task_struct *task)
63018 +{
63019 + return;
63020 +}
63021 +
63022 +__u32
63023 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
63024 +{
63025 + return 1;
63026 +}
63027 +
63028 +__u32
63029 +gr_acl_handle_hidden_file(const struct dentry * dentry,
63030 + const struct vfsmount * mnt)
63031 +{
63032 + return 1;
63033 +}
63034 +
63035 +__u32
63036 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
63037 + int acc_mode)
63038 +{
63039 + return 1;
63040 +}
63041 +
63042 +__u32
63043 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
63044 +{
63045 + return 1;
63046 +}
63047 +
63048 +__u32
63049 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
63050 +{
63051 + return 1;
63052 +}
63053 +
63054 +int
63055 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
63056 + unsigned int *vm_flags)
63057 +{
63058 + return 1;
63059 +}
63060 +
63061 +__u32
63062 +gr_acl_handle_truncate(const struct dentry * dentry,
63063 + const struct vfsmount * mnt)
63064 +{
63065 + return 1;
63066 +}
63067 +
63068 +__u32
63069 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
63070 +{
63071 + return 1;
63072 +}
63073 +
63074 +__u32
63075 +gr_acl_handle_access(const struct dentry * dentry,
63076 + const struct vfsmount * mnt, const int fmode)
63077 +{
63078 + return 1;
63079 +}
63080 +
63081 +__u32
63082 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
63083 + umode_t *mode)
63084 +{
63085 + return 1;
63086 +}
63087 +
63088 +__u32
63089 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
63090 +{
63091 + return 1;
63092 +}
63093 +
63094 +__u32
63095 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
63096 +{
63097 + return 1;
63098 +}
63099 +
63100 +void
63101 +grsecurity_init(void)
63102 +{
63103 + return;
63104 +}
63105 +
63106 +umode_t gr_acl_umask(void)
63107 +{
63108 + return 0;
63109 +}
63110 +
63111 +__u32
63112 +gr_acl_handle_mknod(const struct dentry * new_dentry,
63113 + const struct dentry * parent_dentry,
63114 + const struct vfsmount * parent_mnt,
63115 + const int mode)
63116 +{
63117 + return 1;
63118 +}
63119 +
63120 +__u32
63121 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
63122 + const struct dentry * parent_dentry,
63123 + const struct vfsmount * parent_mnt)
63124 +{
63125 + return 1;
63126 +}
63127 +
63128 +__u32
63129 +gr_acl_handle_symlink(const struct dentry * new_dentry,
63130 + const struct dentry * parent_dentry,
63131 + const struct vfsmount * parent_mnt, const struct filename *from)
63132 +{
63133 + return 1;
63134 +}
63135 +
63136 +__u32
63137 +gr_acl_handle_link(const struct dentry * new_dentry,
63138 + const struct dentry * parent_dentry,
63139 + const struct vfsmount * parent_mnt,
63140 + const struct dentry * old_dentry,
63141 + const struct vfsmount * old_mnt, const struct filename *to)
63142 +{
63143 + return 1;
63144 +}
63145 +
63146 +int
63147 +gr_acl_handle_rename(const struct dentry *new_dentry,
63148 + const struct dentry *parent_dentry,
63149 + const struct vfsmount *parent_mnt,
63150 + const struct dentry *old_dentry,
63151 + const struct inode *old_parent_inode,
63152 + const struct vfsmount *old_mnt, const struct filename *newname)
63153 +{
63154 + return 0;
63155 +}
63156 +
63157 +int
63158 +gr_acl_handle_filldir(const struct file *file, const char *name,
63159 + const int namelen, const ino_t ino)
63160 +{
63161 + return 1;
63162 +}
63163 +
63164 +int
63165 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63166 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
63167 +{
63168 + return 1;
63169 +}
63170 +
63171 +int
63172 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
63173 +{
63174 + return 0;
63175 +}
63176 +
63177 +int
63178 +gr_search_accept(const struct socket *sock)
63179 +{
63180 + return 0;
63181 +}
63182 +
63183 +int
63184 +gr_search_listen(const struct socket *sock)
63185 +{
63186 + return 0;
63187 +}
63188 +
63189 +int
63190 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
63191 +{
63192 + return 0;
63193 +}
63194 +
63195 +__u32
63196 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
63197 +{
63198 + return 1;
63199 +}
63200 +
63201 +__u32
63202 +gr_acl_handle_creat(const struct dentry * dentry,
63203 + const struct dentry * p_dentry,
63204 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
63205 + const int imode)
63206 +{
63207 + return 1;
63208 +}
63209 +
63210 +void
63211 +gr_acl_handle_exit(void)
63212 +{
63213 + return;
63214 +}
63215 +
63216 +int
63217 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
63218 +{
63219 + return 1;
63220 +}
63221 +
63222 +void
63223 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
63224 +{
63225 + return;
63226 +}
63227 +
63228 +int
63229 +gr_acl_handle_procpidmem(const struct task_struct *task)
63230 +{
63231 + return 0;
63232 +}
63233 +
63234 +int
63235 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
63236 +{
63237 + return 0;
63238 +}
63239 +
63240 +int
63241 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
63242 +{
63243 + return 0;
63244 +}
63245 +
63246 +void
63247 +gr_set_kernel_label(struct task_struct *task)
63248 +{
63249 + return;
63250 +}
63251 +
63252 +int
63253 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
63254 +{
63255 + return 0;
63256 +}
63257 +
63258 +int
63259 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
63260 +{
63261 + return 0;
63262 +}
63263 +
63264 +int gr_acl_enable_at_secure(void)
63265 +{
63266 + return 0;
63267 +}
63268 +
63269 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
63270 +{
63271 + return dentry->d_inode->i_sb->s_dev;
63272 +}
63273 +
63274 +void gr_put_exec_file(struct task_struct *task)
63275 +{
63276 + return;
63277 +}
63278 +
63279 +EXPORT_SYMBOL(gr_set_kernel_label);
63280 +#ifdef CONFIG_SECURITY
63281 +EXPORT_SYMBOL(gr_check_user_change);
63282 +EXPORT_SYMBOL(gr_check_group_change);
63283 +#endif
63284 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
63285 new file mode 100644
63286 index 0000000..abfa971
63287 --- /dev/null
63288 +++ b/grsecurity/grsec_exec.c
63289 @@ -0,0 +1,174 @@
63290 +#include <linux/kernel.h>
63291 +#include <linux/sched.h>
63292 +#include <linux/file.h>
63293 +#include <linux/binfmts.h>
63294 +#include <linux/fs.h>
63295 +#include <linux/types.h>
63296 +#include <linux/grdefs.h>
63297 +#include <linux/grsecurity.h>
63298 +#include <linux/grinternal.h>
63299 +#include <linux/capability.h>
63300 +#include <linux/module.h>
63301 +
63302 +#include <asm/uaccess.h>
63303 +
63304 +#ifdef CONFIG_GRKERNSEC_EXECLOG
63305 +static char gr_exec_arg_buf[132];
63306 +static DEFINE_MUTEX(gr_exec_arg_mutex);
63307 +#endif
63308 +
63309 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
63310 +
63311 +void
63312 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
63313 +{
63314 +#ifdef CONFIG_GRKERNSEC_EXECLOG
63315 + char *grarg = gr_exec_arg_buf;
63316 + unsigned int i, x, execlen = 0;
63317 + char c;
63318 +
63319 + if (!((grsec_enable_execlog && grsec_enable_group &&
63320 + in_group_p(grsec_audit_gid))
63321 + || (grsec_enable_execlog && !grsec_enable_group)))
63322 + return;
63323 +
63324 + mutex_lock(&gr_exec_arg_mutex);
63325 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
63326 +
63327 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
63328 + const char __user *p;
63329 + unsigned int len;
63330 +
63331 + p = get_user_arg_ptr(argv, i);
63332 + if (IS_ERR(p))
63333 + goto log;
63334 +
63335 + len = strnlen_user(p, 128 - execlen);
63336 + if (len > 128 - execlen)
63337 + len = 128 - execlen;
63338 + else if (len > 0)
63339 + len--;
63340 + if (copy_from_user(grarg + execlen, p, len))
63341 + goto log;
63342 +
63343 + /* rewrite unprintable characters */
63344 + for (x = 0; x < len; x++) {
63345 + c = *(grarg + execlen + x);
63346 + if (c < 32 || c > 126)
63347 + *(grarg + execlen + x) = ' ';
63348 + }
63349 +
63350 + execlen += len;
63351 + *(grarg + execlen) = ' ';
63352 + *(grarg + execlen + 1) = '\0';
63353 + execlen++;
63354 + }
63355 +
63356 + log:
63357 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
63358 + bprm->file->f_path.mnt, grarg);
63359 + mutex_unlock(&gr_exec_arg_mutex);
63360 +#endif
63361 + return;
63362 +}
63363 +
63364 +#ifdef CONFIG_GRKERNSEC
63365 +extern int gr_acl_is_capable(const int cap);
63366 +extern int gr_acl_is_capable_nolog(const int cap);
63367 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63368 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
63369 +extern int gr_chroot_is_capable(const int cap);
63370 +extern int gr_chroot_is_capable_nolog(const int cap);
63371 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63372 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
63373 +#endif
63374 +
63375 +const char *captab_log[] = {
63376 + "CAP_CHOWN",
63377 + "CAP_DAC_OVERRIDE",
63378 + "CAP_DAC_READ_SEARCH",
63379 + "CAP_FOWNER",
63380 + "CAP_FSETID",
63381 + "CAP_KILL",
63382 + "CAP_SETGID",
63383 + "CAP_SETUID",
63384 + "CAP_SETPCAP",
63385 + "CAP_LINUX_IMMUTABLE",
63386 + "CAP_NET_BIND_SERVICE",
63387 + "CAP_NET_BROADCAST",
63388 + "CAP_NET_ADMIN",
63389 + "CAP_NET_RAW",
63390 + "CAP_IPC_LOCK",
63391 + "CAP_IPC_OWNER",
63392 + "CAP_SYS_MODULE",
63393 + "CAP_SYS_RAWIO",
63394 + "CAP_SYS_CHROOT",
63395 + "CAP_SYS_PTRACE",
63396 + "CAP_SYS_PACCT",
63397 + "CAP_SYS_ADMIN",
63398 + "CAP_SYS_BOOT",
63399 + "CAP_SYS_NICE",
63400 + "CAP_SYS_RESOURCE",
63401 + "CAP_SYS_TIME",
63402 + "CAP_SYS_TTY_CONFIG",
63403 + "CAP_MKNOD",
63404 + "CAP_LEASE",
63405 + "CAP_AUDIT_WRITE",
63406 + "CAP_AUDIT_CONTROL",
63407 + "CAP_SETFCAP",
63408 + "CAP_MAC_OVERRIDE",
63409 + "CAP_MAC_ADMIN",
63410 + "CAP_SYSLOG",
63411 + "CAP_WAKE_ALARM"
63412 +};
63413 +
63414 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
63415 +
63416 +int gr_is_capable(const int cap)
63417 +{
63418 +#ifdef CONFIG_GRKERNSEC
63419 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
63420 + return 1;
63421 + return 0;
63422 +#else
63423 + return 1;
63424 +#endif
63425 +}
63426 +
63427 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63428 +{
63429 +#ifdef CONFIG_GRKERNSEC
63430 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
63431 + return 1;
63432 + return 0;
63433 +#else
63434 + return 1;
63435 +#endif
63436 +}
63437 +
63438 +int gr_is_capable_nolog(const int cap)
63439 +{
63440 +#ifdef CONFIG_GRKERNSEC
63441 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
63442 + return 1;
63443 + return 0;
63444 +#else
63445 + return 1;
63446 +#endif
63447 +}
63448 +
63449 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
63450 +{
63451 +#ifdef CONFIG_GRKERNSEC
63452 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
63453 + return 1;
63454 + return 0;
63455 +#else
63456 + return 1;
63457 +#endif
63458 +}
63459 +
63460 +EXPORT_SYMBOL(gr_is_capable);
63461 +EXPORT_SYMBOL(gr_is_capable_nolog);
63462 +EXPORT_SYMBOL(gr_task_is_capable);
63463 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
63464 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
63465 new file mode 100644
63466 index 0000000..06cc6ea
63467 --- /dev/null
63468 +++ b/grsecurity/grsec_fifo.c
63469 @@ -0,0 +1,24 @@
63470 +#include <linux/kernel.h>
63471 +#include <linux/sched.h>
63472 +#include <linux/fs.h>
63473 +#include <linux/file.h>
63474 +#include <linux/grinternal.h>
63475 +
63476 +int
63477 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
63478 + const struct dentry *dir, const int flag, const int acc_mode)
63479 +{
63480 +#ifdef CONFIG_GRKERNSEC_FIFO
63481 + const struct cred *cred = current_cred();
63482 +
63483 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
63484 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
63485 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
63486 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
63487 + if (!inode_permission(dentry->d_inode, acc_mode))
63488 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, GR_GLOBAL_UID(dentry->d_inode->i_uid), GR_GLOBAL_GID(dentry->d_inode->i_gid));
63489 + return -EACCES;
63490 + }
63491 +#endif
63492 + return 0;
63493 +}
63494 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
63495 new file mode 100644
63496 index 0000000..8ca18bf
63497 --- /dev/null
63498 +++ b/grsecurity/grsec_fork.c
63499 @@ -0,0 +1,23 @@
63500 +#include <linux/kernel.h>
63501 +#include <linux/sched.h>
63502 +#include <linux/grsecurity.h>
63503 +#include <linux/grinternal.h>
63504 +#include <linux/errno.h>
63505 +
63506 +void
63507 +gr_log_forkfail(const int retval)
63508 +{
63509 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
63510 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
63511 + switch (retval) {
63512 + case -EAGAIN:
63513 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
63514 + break;
63515 + case -ENOMEM:
63516 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
63517 + break;
63518 + }
63519 + }
63520 +#endif
63521 + return;
63522 +}
63523 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
63524 new file mode 100644
63525 index 0000000..a862e9f
63526 --- /dev/null
63527 +++ b/grsecurity/grsec_init.c
63528 @@ -0,0 +1,283 @@
63529 +#include <linux/kernel.h>
63530 +#include <linux/sched.h>
63531 +#include <linux/mm.h>
63532 +#include <linux/gracl.h>
63533 +#include <linux/slab.h>
63534 +#include <linux/vmalloc.h>
63535 +#include <linux/percpu.h>
63536 +#include <linux/module.h>
63537 +
63538 +int grsec_enable_ptrace_readexec;
63539 +int grsec_enable_setxid;
63540 +int grsec_enable_symlinkown;
63541 +kgid_t grsec_symlinkown_gid;
63542 +int grsec_enable_brute;
63543 +int grsec_enable_link;
63544 +int grsec_enable_dmesg;
63545 +int grsec_enable_harden_ptrace;
63546 +int grsec_enable_fifo;
63547 +int grsec_enable_execlog;
63548 +int grsec_enable_signal;
63549 +int grsec_enable_forkfail;
63550 +int grsec_enable_audit_ptrace;
63551 +int grsec_enable_time;
63552 +int grsec_enable_audit_textrel;
63553 +int grsec_enable_group;
63554 +kgid_t grsec_audit_gid;
63555 +int grsec_enable_chdir;
63556 +int grsec_enable_mount;
63557 +int grsec_enable_rofs;
63558 +int grsec_enable_chroot_findtask;
63559 +int grsec_enable_chroot_mount;
63560 +int grsec_enable_chroot_shmat;
63561 +int grsec_enable_chroot_fchdir;
63562 +int grsec_enable_chroot_double;
63563 +int grsec_enable_chroot_pivot;
63564 +int grsec_enable_chroot_chdir;
63565 +int grsec_enable_chroot_chmod;
63566 +int grsec_enable_chroot_mknod;
63567 +int grsec_enable_chroot_nice;
63568 +int grsec_enable_chroot_execlog;
63569 +int grsec_enable_chroot_caps;
63570 +int grsec_enable_chroot_sysctl;
63571 +int grsec_enable_chroot_unix;
63572 +int grsec_enable_tpe;
63573 +kgid_t grsec_tpe_gid;
63574 +int grsec_enable_blackhole;
63575 +#ifdef CONFIG_IPV6_MODULE
63576 +EXPORT_SYMBOL(grsec_enable_blackhole);
63577 +#endif
63578 +int grsec_lastack_retries;
63579 +int grsec_enable_tpe_all;
63580 +int grsec_enable_tpe_invert;
63581 +int grsec_enable_socket_all;
63582 +kgid_t grsec_socket_all_gid;
63583 +int grsec_enable_socket_client;
63584 +kgid_t grsec_socket_client_gid;
63585 +int grsec_enable_socket_server;
63586 +kgid_t grsec_socket_server_gid;
63587 +int grsec_resource_logging;
63588 +int grsec_disable_privio;
63589 +int grsec_enable_log_rwxmaps;
63590 +int grsec_lock;
63591 +
63592 +DEFINE_SPINLOCK(grsec_alert_lock);
63593 +unsigned long grsec_alert_wtime = 0;
63594 +unsigned long grsec_alert_fyet = 0;
63595 +
63596 +DEFINE_SPINLOCK(grsec_audit_lock);
63597 +
63598 +DEFINE_RWLOCK(grsec_exec_file_lock);
63599 +
63600 +char *gr_shared_page[4];
63601 +
63602 +char *gr_alert_log_fmt;
63603 +char *gr_audit_log_fmt;
63604 +char *gr_alert_log_buf;
63605 +char *gr_audit_log_buf;
63606 +
63607 +extern struct gr_arg *gr_usermode;
63608 +extern unsigned char *gr_system_salt;
63609 +extern unsigned char *gr_system_sum;
63610 +
63611 +void __init
63612 +grsecurity_init(void)
63613 +{
63614 + int j;
63615 + /* create the per-cpu shared pages */
63616 +
63617 +#ifdef CONFIG_X86
63618 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
63619 +#endif
63620 +
63621 + for (j = 0; j < 4; j++) {
63622 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
63623 + if (gr_shared_page[j] == NULL) {
63624 + panic("Unable to allocate grsecurity shared page");
63625 + return;
63626 + }
63627 + }
63628 +
63629 + /* allocate log buffers */
63630 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
63631 + if (!gr_alert_log_fmt) {
63632 + panic("Unable to allocate grsecurity alert log format buffer");
63633 + return;
63634 + }
63635 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
63636 + if (!gr_audit_log_fmt) {
63637 + panic("Unable to allocate grsecurity audit log format buffer");
63638 + return;
63639 + }
63640 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
63641 + if (!gr_alert_log_buf) {
63642 + panic("Unable to allocate grsecurity alert log buffer");
63643 + return;
63644 + }
63645 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
63646 + if (!gr_audit_log_buf) {
63647 + panic("Unable to allocate grsecurity audit log buffer");
63648 + return;
63649 + }
63650 +
63651 + /* allocate memory for authentication structure */
63652 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
63653 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
63654 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
63655 +
63656 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
63657 + panic("Unable to allocate grsecurity authentication structure");
63658 + return;
63659 + }
63660 +
63661 +
63662 +#ifdef CONFIG_GRKERNSEC_IO
63663 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
63664 + grsec_disable_privio = 1;
63665 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
63666 + grsec_disable_privio = 1;
63667 +#else
63668 + grsec_disable_privio = 0;
63669 +#endif
63670 +#endif
63671 +
63672 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63673 + /* for backward compatibility, tpe_invert always defaults to on if
63674 + enabled in the kernel
63675 + */
63676 + grsec_enable_tpe_invert = 1;
63677 +#endif
63678 +
63679 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
63680 +#ifndef CONFIG_GRKERNSEC_SYSCTL
63681 + grsec_lock = 1;
63682 +#endif
63683 +
63684 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
63685 + grsec_enable_audit_textrel = 1;
63686 +#endif
63687 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63688 + grsec_enable_log_rwxmaps = 1;
63689 +#endif
63690 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
63691 + grsec_enable_group = 1;
63692 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
63693 +#endif
63694 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
63695 + grsec_enable_ptrace_readexec = 1;
63696 +#endif
63697 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63698 + grsec_enable_chdir = 1;
63699 +#endif
63700 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
63701 + grsec_enable_harden_ptrace = 1;
63702 +#endif
63703 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63704 + grsec_enable_mount = 1;
63705 +#endif
63706 +#ifdef CONFIG_GRKERNSEC_LINK
63707 + grsec_enable_link = 1;
63708 +#endif
63709 +#ifdef CONFIG_GRKERNSEC_BRUTE
63710 + grsec_enable_brute = 1;
63711 +#endif
63712 +#ifdef CONFIG_GRKERNSEC_DMESG
63713 + grsec_enable_dmesg = 1;
63714 +#endif
63715 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
63716 + grsec_enable_blackhole = 1;
63717 + grsec_lastack_retries = 4;
63718 +#endif
63719 +#ifdef CONFIG_GRKERNSEC_FIFO
63720 + grsec_enable_fifo = 1;
63721 +#endif
63722 +#ifdef CONFIG_GRKERNSEC_EXECLOG
63723 + grsec_enable_execlog = 1;
63724 +#endif
63725 +#ifdef CONFIG_GRKERNSEC_SETXID
63726 + grsec_enable_setxid = 1;
63727 +#endif
63728 +#ifdef CONFIG_GRKERNSEC_SIGNAL
63729 + grsec_enable_signal = 1;
63730 +#endif
63731 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
63732 + grsec_enable_forkfail = 1;
63733 +#endif
63734 +#ifdef CONFIG_GRKERNSEC_TIME
63735 + grsec_enable_time = 1;
63736 +#endif
63737 +#ifdef CONFIG_GRKERNSEC_RESLOG
63738 + grsec_resource_logging = 1;
63739 +#endif
63740 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63741 + grsec_enable_chroot_findtask = 1;
63742 +#endif
63743 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63744 + grsec_enable_chroot_unix = 1;
63745 +#endif
63746 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63747 + grsec_enable_chroot_mount = 1;
63748 +#endif
63749 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63750 + grsec_enable_chroot_fchdir = 1;
63751 +#endif
63752 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63753 + grsec_enable_chroot_shmat = 1;
63754 +#endif
63755 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
63756 + grsec_enable_audit_ptrace = 1;
63757 +#endif
63758 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63759 + grsec_enable_chroot_double = 1;
63760 +#endif
63761 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63762 + grsec_enable_chroot_pivot = 1;
63763 +#endif
63764 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63765 + grsec_enable_chroot_chdir = 1;
63766 +#endif
63767 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63768 + grsec_enable_chroot_chmod = 1;
63769 +#endif
63770 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63771 + grsec_enable_chroot_mknod = 1;
63772 +#endif
63773 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63774 + grsec_enable_chroot_nice = 1;
63775 +#endif
63776 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63777 + grsec_enable_chroot_execlog = 1;
63778 +#endif
63779 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63780 + grsec_enable_chroot_caps = 1;
63781 +#endif
63782 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63783 + grsec_enable_chroot_sysctl = 1;
63784 +#endif
63785 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
63786 + grsec_enable_symlinkown = 1;
63787 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
63788 +#endif
63789 +#ifdef CONFIG_GRKERNSEC_TPE
63790 + grsec_enable_tpe = 1;
63791 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
63792 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
63793 + grsec_enable_tpe_all = 1;
63794 +#endif
63795 +#endif
63796 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
63797 + grsec_enable_socket_all = 1;
63798 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
63799 +#endif
63800 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
63801 + grsec_enable_socket_client = 1;
63802 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
63803 +#endif
63804 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63805 + grsec_enable_socket_server = 1;
63806 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
63807 +#endif
63808 +#endif
63809 +
63810 + return;
63811 +}
63812 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
63813 new file mode 100644
63814 index 0000000..5e05e20
63815 --- /dev/null
63816 +++ b/grsecurity/grsec_link.c
63817 @@ -0,0 +1,58 @@
63818 +#include <linux/kernel.h>
63819 +#include <linux/sched.h>
63820 +#include <linux/fs.h>
63821 +#include <linux/file.h>
63822 +#include <linux/grinternal.h>
63823 +
63824 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
63825 +{
63826 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
63827 + const struct inode *link_inode = link->dentry->d_inode;
63828 +
63829 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
63830 + /* ignore root-owned links, e.g. /proc/self */
63831 + gr_is_global_nonroot(link_inode->i_uid) && target &&
63832 + !uid_eq(link_inode->i_uid, target->i_uid)) {
63833 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
63834 + return 1;
63835 + }
63836 +#endif
63837 + return 0;
63838 +}
63839 +
63840 +int
63841 +gr_handle_follow_link(const struct inode *parent,
63842 + const struct inode *inode,
63843 + const struct dentry *dentry, const struct vfsmount *mnt)
63844 +{
63845 +#ifdef CONFIG_GRKERNSEC_LINK
63846 + const struct cred *cred = current_cred();
63847 +
63848 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
63849 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
63850 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
63851 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
63852 + return -EACCES;
63853 + }
63854 +#endif
63855 + return 0;
63856 +}
63857 +
63858 +int
63859 +gr_handle_hardlink(const struct dentry *dentry,
63860 + const struct vfsmount *mnt,
63861 + struct inode *inode, const int mode, const struct filename *to)
63862 +{
63863 +#ifdef CONFIG_GRKERNSEC_LINK
63864 + const struct cred *cred = current_cred();
63865 +
63866 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
63867 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
63868 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
63869 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
63870 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
63871 + return -EPERM;
63872 + }
63873 +#endif
63874 + return 0;
63875 +}
63876 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
63877 new file mode 100644
63878 index 0000000..7c06085
63879 --- /dev/null
63880 +++ b/grsecurity/grsec_log.c
63881 @@ -0,0 +1,326 @@
63882 +#include <linux/kernel.h>
63883 +#include <linux/sched.h>
63884 +#include <linux/file.h>
63885 +#include <linux/tty.h>
63886 +#include <linux/fs.h>
63887 +#include <linux/grinternal.h>
63888 +
63889 +#ifdef CONFIG_TREE_PREEMPT_RCU
63890 +#define DISABLE_PREEMPT() preempt_disable()
63891 +#define ENABLE_PREEMPT() preempt_enable()
63892 +#else
63893 +#define DISABLE_PREEMPT()
63894 +#define ENABLE_PREEMPT()
63895 +#endif
63896 +
63897 +#define BEGIN_LOCKS(x) \
63898 + DISABLE_PREEMPT(); \
63899 + rcu_read_lock(); \
63900 + read_lock(&tasklist_lock); \
63901 + read_lock(&grsec_exec_file_lock); \
63902 + if (x != GR_DO_AUDIT) \
63903 + spin_lock(&grsec_alert_lock); \
63904 + else \
63905 + spin_lock(&grsec_audit_lock)
63906 +
63907 +#define END_LOCKS(x) \
63908 + if (x != GR_DO_AUDIT) \
63909 + spin_unlock(&grsec_alert_lock); \
63910 + else \
63911 + spin_unlock(&grsec_audit_lock); \
63912 + read_unlock(&grsec_exec_file_lock); \
63913 + read_unlock(&tasklist_lock); \
63914 + rcu_read_unlock(); \
63915 + ENABLE_PREEMPT(); \
63916 + if (x == GR_DONT_AUDIT) \
63917 + gr_handle_alertkill(current)
63918 +
63919 +enum {
63920 + FLOODING,
63921 + NO_FLOODING
63922 +};
63923 +
63924 +extern char *gr_alert_log_fmt;
63925 +extern char *gr_audit_log_fmt;
63926 +extern char *gr_alert_log_buf;
63927 +extern char *gr_audit_log_buf;
63928 +
63929 +static int gr_log_start(int audit)
63930 +{
63931 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
63932 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
63933 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63934 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
63935 + unsigned long curr_secs = get_seconds();
63936 +
63937 + if (audit == GR_DO_AUDIT)
63938 + goto set_fmt;
63939 +
63940 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
63941 + grsec_alert_wtime = curr_secs;
63942 + grsec_alert_fyet = 0;
63943 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
63944 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
63945 + grsec_alert_fyet++;
63946 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
63947 + grsec_alert_wtime = curr_secs;
63948 + grsec_alert_fyet++;
63949 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
63950 + return FLOODING;
63951 + }
63952 + else return FLOODING;
63953 +
63954 +set_fmt:
63955 +#endif
63956 + memset(buf, 0, PAGE_SIZE);
63957 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
63958 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
63959 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
63960 + } else if (current->signal->curr_ip) {
63961 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
63962 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
63963 + } else if (gr_acl_is_enabled()) {
63964 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
63965 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
63966 + } else {
63967 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
63968 + strcpy(buf, fmt);
63969 + }
63970 +
63971 + return NO_FLOODING;
63972 +}
63973 +
63974 +static void gr_log_middle(int audit, const char *msg, va_list ap)
63975 + __attribute__ ((format (printf, 2, 0)));
63976 +
63977 +static void gr_log_middle(int audit, const char *msg, va_list ap)
63978 +{
63979 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63980 + unsigned int len = strlen(buf);
63981 +
63982 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
63983 +
63984 + return;
63985 +}
63986 +
63987 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
63988 + __attribute__ ((format (printf, 2, 3)));
63989 +
63990 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
63991 +{
63992 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63993 + unsigned int len = strlen(buf);
63994 + va_list ap;
63995 +
63996 + va_start(ap, msg);
63997 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
63998 + va_end(ap);
63999 +
64000 + return;
64001 +}
64002 +
64003 +static void gr_log_end(int audit, int append_default)
64004 +{
64005 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64006 + if (append_default) {
64007 + struct task_struct *task = current;
64008 + struct task_struct *parent = task->real_parent;
64009 + const struct cred *cred = __task_cred(task);
64010 + const struct cred *pcred = __task_cred(parent);
64011 + unsigned int len = strlen(buf);
64012 +
64013 + 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));
64014 + }
64015 +
64016 + printk("%s\n", buf);
64017 +
64018 + return;
64019 +}
64020 +
64021 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
64022 +{
64023 + int logtype;
64024 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
64025 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
64026 + void *voidptr = NULL;
64027 + int num1 = 0, num2 = 0;
64028 + unsigned long ulong1 = 0, ulong2 = 0;
64029 + struct dentry *dentry = NULL;
64030 + struct vfsmount *mnt = NULL;
64031 + struct file *file = NULL;
64032 + struct task_struct *task = NULL;
64033 + const struct cred *cred, *pcred;
64034 + va_list ap;
64035 +
64036 + BEGIN_LOCKS(audit);
64037 + logtype = gr_log_start(audit);
64038 + if (logtype == FLOODING) {
64039 + END_LOCKS(audit);
64040 + return;
64041 + }
64042 + va_start(ap, argtypes);
64043 + switch (argtypes) {
64044 + case GR_TTYSNIFF:
64045 + task = va_arg(ap, struct task_struct *);
64046 + 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));
64047 + break;
64048 + case GR_SYSCTL_HIDDEN:
64049 + str1 = va_arg(ap, char *);
64050 + gr_log_middle_varargs(audit, msg, result, str1);
64051 + break;
64052 + case GR_RBAC:
64053 + dentry = va_arg(ap, struct dentry *);
64054 + mnt = va_arg(ap, struct vfsmount *);
64055 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
64056 + break;
64057 + case GR_RBAC_STR:
64058 + dentry = va_arg(ap, struct dentry *);
64059 + mnt = va_arg(ap, struct vfsmount *);
64060 + str1 = va_arg(ap, char *);
64061 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
64062 + break;
64063 + case GR_STR_RBAC:
64064 + str1 = va_arg(ap, char *);
64065 + dentry = va_arg(ap, struct dentry *);
64066 + mnt = va_arg(ap, struct vfsmount *);
64067 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
64068 + break;
64069 + case GR_RBAC_MODE2:
64070 + dentry = va_arg(ap, struct dentry *);
64071 + mnt = va_arg(ap, struct vfsmount *);
64072 + str1 = va_arg(ap, char *);
64073 + str2 = va_arg(ap, char *);
64074 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
64075 + break;
64076 + case GR_RBAC_MODE3:
64077 + dentry = va_arg(ap, struct dentry *);
64078 + mnt = va_arg(ap, struct vfsmount *);
64079 + str1 = va_arg(ap, char *);
64080 + str2 = va_arg(ap, char *);
64081 + str3 = va_arg(ap, char *);
64082 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
64083 + break;
64084 + case GR_FILENAME:
64085 + dentry = va_arg(ap, struct dentry *);
64086 + mnt = va_arg(ap, struct vfsmount *);
64087 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
64088 + break;
64089 + case GR_STR_FILENAME:
64090 + str1 = va_arg(ap, char *);
64091 + dentry = va_arg(ap, struct dentry *);
64092 + mnt = va_arg(ap, struct vfsmount *);
64093 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
64094 + break;
64095 + case GR_FILENAME_STR:
64096 + dentry = va_arg(ap, struct dentry *);
64097 + mnt = va_arg(ap, struct vfsmount *);
64098 + str1 = va_arg(ap, char *);
64099 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
64100 + break;
64101 + case GR_FILENAME_TWO_INT:
64102 + dentry = va_arg(ap, struct dentry *);
64103 + mnt = va_arg(ap, struct vfsmount *);
64104 + num1 = va_arg(ap, int);
64105 + num2 = va_arg(ap, int);
64106 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
64107 + break;
64108 + case GR_FILENAME_TWO_INT_STR:
64109 + dentry = va_arg(ap, struct dentry *);
64110 + mnt = va_arg(ap, struct vfsmount *);
64111 + num1 = va_arg(ap, int);
64112 + num2 = va_arg(ap, int);
64113 + str1 = va_arg(ap, char *);
64114 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
64115 + break;
64116 + case GR_TEXTREL:
64117 + file = va_arg(ap, struct file *);
64118 + ulong1 = va_arg(ap, unsigned long);
64119 + ulong2 = va_arg(ap, unsigned long);
64120 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
64121 + break;
64122 + case GR_PTRACE:
64123 + task = va_arg(ap, struct task_struct *);
64124 + 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));
64125 + break;
64126 + case GR_RESOURCE:
64127 + task = va_arg(ap, struct task_struct *);
64128 + cred = __task_cred(task);
64129 + pcred = __task_cred(task->real_parent);
64130 + ulong1 = va_arg(ap, unsigned long);
64131 + str1 = va_arg(ap, char *);
64132 + ulong2 = va_arg(ap, unsigned long);
64133 + 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));
64134 + break;
64135 + case GR_CAP:
64136 + task = va_arg(ap, struct task_struct *);
64137 + cred = __task_cred(task);
64138 + pcred = __task_cred(task->real_parent);
64139 + str1 = va_arg(ap, char *);
64140 + 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));
64141 + break;
64142 + case GR_SIG:
64143 + str1 = va_arg(ap, char *);
64144 + voidptr = va_arg(ap, void *);
64145 + gr_log_middle_varargs(audit, msg, str1, voidptr);
64146 + break;
64147 + case GR_SIG2:
64148 + task = va_arg(ap, struct task_struct *);
64149 + cred = __task_cred(task);
64150 + pcred = __task_cred(task->real_parent);
64151 + num1 = va_arg(ap, int);
64152 + 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));
64153 + break;
64154 + case GR_CRASH1:
64155 + task = va_arg(ap, struct task_struct *);
64156 + cred = __task_cred(task);
64157 + pcred = __task_cred(task->real_parent);
64158 + ulong1 = va_arg(ap, unsigned long);
64159 + 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);
64160 + break;
64161 + case GR_CRASH2:
64162 + task = va_arg(ap, struct task_struct *);
64163 + cred = __task_cred(task);
64164 + pcred = __task_cred(task->real_parent);
64165 + ulong1 = va_arg(ap, unsigned long);
64166 + 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);
64167 + break;
64168 + case GR_RWXMAP:
64169 + file = va_arg(ap, struct file *);
64170 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
64171 + break;
64172 + case GR_PSACCT:
64173 + {
64174 + unsigned int wday, cday;
64175 + __u8 whr, chr;
64176 + __u8 wmin, cmin;
64177 + __u8 wsec, csec;
64178 + char cur_tty[64] = { 0 };
64179 + char parent_tty[64] = { 0 };
64180 +
64181 + task = va_arg(ap, struct task_struct *);
64182 + wday = va_arg(ap, unsigned int);
64183 + cday = va_arg(ap, unsigned int);
64184 + whr = va_arg(ap, int);
64185 + chr = va_arg(ap, int);
64186 + wmin = va_arg(ap, int);
64187 + cmin = va_arg(ap, int);
64188 + wsec = va_arg(ap, int);
64189 + csec = va_arg(ap, int);
64190 + ulong1 = va_arg(ap, unsigned long);
64191 + cred = __task_cred(task);
64192 + pcred = __task_cred(task->real_parent);
64193 +
64194 + 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));
64195 + }
64196 + break;
64197 + default:
64198 + gr_log_middle(audit, msg, ap);
64199 + }
64200 + va_end(ap);
64201 + // these don't need DEFAULTSECARGS printed on the end
64202 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
64203 + gr_log_end(audit, 0);
64204 + else
64205 + gr_log_end(audit, 1);
64206 + END_LOCKS(audit);
64207 +}
64208 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
64209 new file mode 100644
64210 index 0000000..f536303
64211 --- /dev/null
64212 +++ b/grsecurity/grsec_mem.c
64213 @@ -0,0 +1,40 @@
64214 +#include <linux/kernel.h>
64215 +#include <linux/sched.h>
64216 +#include <linux/mm.h>
64217 +#include <linux/mman.h>
64218 +#include <linux/grinternal.h>
64219 +
64220 +void
64221 +gr_handle_ioperm(void)
64222 +{
64223 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
64224 + return;
64225 +}
64226 +
64227 +void
64228 +gr_handle_iopl(void)
64229 +{
64230 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
64231 + return;
64232 +}
64233 +
64234 +void
64235 +gr_handle_mem_readwrite(u64 from, u64 to)
64236 +{
64237 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
64238 + return;
64239 +}
64240 +
64241 +void
64242 +gr_handle_vm86(void)
64243 +{
64244 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
64245 + return;
64246 +}
64247 +
64248 +void
64249 +gr_log_badprocpid(const char *entry)
64250 +{
64251 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
64252 + return;
64253 +}
64254 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
64255 new file mode 100644
64256 index 0000000..2131422
64257 --- /dev/null
64258 +++ b/grsecurity/grsec_mount.c
64259 @@ -0,0 +1,62 @@
64260 +#include <linux/kernel.h>
64261 +#include <linux/sched.h>
64262 +#include <linux/mount.h>
64263 +#include <linux/grsecurity.h>
64264 +#include <linux/grinternal.h>
64265 +
64266 +void
64267 +gr_log_remount(const char *devname, const int retval)
64268 +{
64269 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64270 + if (grsec_enable_mount && (retval >= 0))
64271 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
64272 +#endif
64273 + return;
64274 +}
64275 +
64276 +void
64277 +gr_log_unmount(const char *devname, const int retval)
64278 +{
64279 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64280 + if (grsec_enable_mount && (retval >= 0))
64281 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
64282 +#endif
64283 + return;
64284 +}
64285 +
64286 +void
64287 +gr_log_mount(const char *from, const char *to, const int retval)
64288 +{
64289 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64290 + if (grsec_enable_mount && (retval >= 0))
64291 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
64292 +#endif
64293 + return;
64294 +}
64295 +
64296 +int
64297 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
64298 +{
64299 +#ifdef CONFIG_GRKERNSEC_ROFS
64300 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
64301 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
64302 + return -EPERM;
64303 + } else
64304 + return 0;
64305 +#endif
64306 + return 0;
64307 +}
64308 +
64309 +int
64310 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
64311 +{
64312 +#ifdef CONFIG_GRKERNSEC_ROFS
64313 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
64314 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
64315 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
64316 + return -EPERM;
64317 + } else
64318 + return 0;
64319 +#endif
64320 + return 0;
64321 +}
64322 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
64323 new file mode 100644
64324 index 0000000..a3b12a0
64325 --- /dev/null
64326 +++ b/grsecurity/grsec_pax.c
64327 @@ -0,0 +1,36 @@
64328 +#include <linux/kernel.h>
64329 +#include <linux/sched.h>
64330 +#include <linux/mm.h>
64331 +#include <linux/file.h>
64332 +#include <linux/grinternal.h>
64333 +#include <linux/grsecurity.h>
64334 +
64335 +void
64336 +gr_log_textrel(struct vm_area_struct * vma)
64337 +{
64338 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64339 + if (grsec_enable_audit_textrel)
64340 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
64341 +#endif
64342 + return;
64343 +}
64344 +
64345 +void
64346 +gr_log_rwxmmap(struct file *file)
64347 +{
64348 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64349 + if (grsec_enable_log_rwxmaps)
64350 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
64351 +#endif
64352 + return;
64353 +}
64354 +
64355 +void
64356 +gr_log_rwxmprotect(struct file *file)
64357 +{
64358 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64359 + if (grsec_enable_log_rwxmaps)
64360 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
64361 +#endif
64362 + return;
64363 +}
64364 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
64365 new file mode 100644
64366 index 0000000..f7f29aa
64367 --- /dev/null
64368 +++ b/grsecurity/grsec_ptrace.c
64369 @@ -0,0 +1,30 @@
64370 +#include <linux/kernel.h>
64371 +#include <linux/sched.h>
64372 +#include <linux/grinternal.h>
64373 +#include <linux/security.h>
64374 +
64375 +void
64376 +gr_audit_ptrace(struct task_struct *task)
64377 +{
64378 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64379 + if (grsec_enable_audit_ptrace)
64380 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
64381 +#endif
64382 + return;
64383 +}
64384 +
64385 +int
64386 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
64387 +{
64388 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64389 + const struct dentry *dentry = file->f_path.dentry;
64390 + const struct vfsmount *mnt = file->f_path.mnt;
64391 +
64392 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
64393 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
64394 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
64395 + return -EACCES;
64396 + }
64397 +#endif
64398 + return 0;
64399 +}
64400 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
64401 new file mode 100644
64402 index 0000000..e09715a
64403 --- /dev/null
64404 +++ b/grsecurity/grsec_sig.c
64405 @@ -0,0 +1,222 @@
64406 +#include <linux/kernel.h>
64407 +#include <linux/sched.h>
64408 +#include <linux/delay.h>
64409 +#include <linux/grsecurity.h>
64410 +#include <linux/grinternal.h>
64411 +#include <linux/hardirq.h>
64412 +
64413 +char *signames[] = {
64414 + [SIGSEGV] = "Segmentation fault",
64415 + [SIGILL] = "Illegal instruction",
64416 + [SIGABRT] = "Abort",
64417 + [SIGBUS] = "Invalid alignment/Bus error"
64418 +};
64419 +
64420 +void
64421 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
64422 +{
64423 +#ifdef CONFIG_GRKERNSEC_SIGNAL
64424 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
64425 + (sig == SIGABRT) || (sig == SIGBUS))) {
64426 + if (task_pid_nr(t) == task_pid_nr(current)) {
64427 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
64428 + } else {
64429 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
64430 + }
64431 + }
64432 +#endif
64433 + return;
64434 +}
64435 +
64436 +int
64437 +gr_handle_signal(const struct task_struct *p, const int sig)
64438 +{
64439 +#ifdef CONFIG_GRKERNSEC
64440 + /* ignore the 0 signal for protected task checks */
64441 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
64442 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
64443 + return -EPERM;
64444 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
64445 + return -EPERM;
64446 + }
64447 +#endif
64448 + return 0;
64449 +}
64450 +
64451 +#ifdef CONFIG_GRKERNSEC
64452 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
64453 +
64454 +int gr_fake_force_sig(int sig, struct task_struct *t)
64455 +{
64456 + unsigned long int flags;
64457 + int ret, blocked, ignored;
64458 + struct k_sigaction *action;
64459 +
64460 + spin_lock_irqsave(&t->sighand->siglock, flags);
64461 + action = &t->sighand->action[sig-1];
64462 + ignored = action->sa.sa_handler == SIG_IGN;
64463 + blocked = sigismember(&t->blocked, sig);
64464 + if (blocked || ignored) {
64465 + action->sa.sa_handler = SIG_DFL;
64466 + if (blocked) {
64467 + sigdelset(&t->blocked, sig);
64468 + recalc_sigpending_and_wake(t);
64469 + }
64470 + }
64471 + if (action->sa.sa_handler == SIG_DFL)
64472 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
64473 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
64474 +
64475 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
64476 +
64477 + return ret;
64478 +}
64479 +#endif
64480 +
64481 +#ifdef CONFIG_GRKERNSEC_BRUTE
64482 +#define GR_USER_BAN_TIME (15 * 60)
64483 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
64484 +
64485 +static int __get_dumpable(unsigned long mm_flags)
64486 +{
64487 + int ret;
64488 +
64489 + ret = mm_flags & MMF_DUMPABLE_MASK;
64490 + return (ret >= 2) ? 2 : ret;
64491 +}
64492 +#endif
64493 +
64494 +void gr_handle_brute_attach(unsigned long mm_flags)
64495 +{
64496 +#ifdef CONFIG_GRKERNSEC_BRUTE
64497 + struct task_struct *p = current;
64498 + kuid_t uid = GLOBAL_ROOT_UID;
64499 + int daemon = 0;
64500 +
64501 + if (!grsec_enable_brute)
64502 + return;
64503 +
64504 + rcu_read_lock();
64505 + read_lock(&tasklist_lock);
64506 + read_lock(&grsec_exec_file_lock);
64507 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
64508 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
64509 + p->real_parent->brute = 1;
64510 + daemon = 1;
64511 + } else {
64512 + const struct cred *cred = __task_cred(p), *cred2;
64513 + struct task_struct *tsk, *tsk2;
64514 +
64515 + if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
64516 + struct user_struct *user;
64517 +
64518 + uid = cred->uid;
64519 +
64520 + /* this is put upon execution past expiration */
64521 + user = find_user(uid);
64522 + if (user == NULL)
64523 + goto unlock;
64524 + user->banned = 1;
64525 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
64526 + if (user->ban_expires == ~0UL)
64527 + user->ban_expires--;
64528 +
64529 + do_each_thread(tsk2, tsk) {
64530 + cred2 = __task_cred(tsk);
64531 + if (tsk != p && uid_eq(cred2->uid, uid))
64532 + gr_fake_force_sig(SIGKILL, tsk);
64533 + } while_each_thread(tsk2, tsk);
64534 + }
64535 + }
64536 +unlock:
64537 + read_unlock(&grsec_exec_file_lock);
64538 + read_unlock(&tasklist_lock);
64539 + rcu_read_unlock();
64540 +
64541 + if (gr_is_global_nonroot(uid))
64542 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
64543 + GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
64544 + else if (daemon)
64545 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
64546 +
64547 +#endif
64548 + return;
64549 +}
64550 +
64551 +void gr_handle_brute_check(void)
64552 +{
64553 +#ifdef CONFIG_GRKERNSEC_BRUTE
64554 + struct task_struct *p = current;
64555 +
64556 + if (unlikely(p->brute)) {
64557 + if (!grsec_enable_brute)
64558 + p->brute = 0;
64559 + else if (time_before(get_seconds(), p->brute_expires))
64560 + msleep(30 * 1000);
64561 + }
64562 +#endif
64563 + return;
64564 +}
64565 +
64566 +void gr_handle_kernel_exploit(void)
64567 +{
64568 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
64569 + const struct cred *cred;
64570 + struct task_struct *tsk, *tsk2;
64571 + struct user_struct *user;
64572 + kuid_t uid;
64573 +
64574 + if (in_irq() || in_serving_softirq() || in_nmi())
64575 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
64576 +
64577 + uid = current_uid();
64578 +
64579 + if (gr_is_global_root(uid))
64580 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
64581 + else {
64582 + /* kill all the processes of this user, hold a reference
64583 + to their creds struct, and prevent them from creating
64584 + another process until system reset
64585 + */
64586 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
64587 + GR_GLOBAL_UID(uid));
64588 + /* we intentionally leak this ref */
64589 + user = get_uid(current->cred->user);
64590 + if (user) {
64591 + user->banned = 1;
64592 + user->ban_expires = ~0UL;
64593 + }
64594 +
64595 + read_lock(&tasklist_lock);
64596 + do_each_thread(tsk2, tsk) {
64597 + cred = __task_cred(tsk);
64598 + if (uid_eq(cred->uid, uid))
64599 + gr_fake_force_sig(SIGKILL, tsk);
64600 + } while_each_thread(tsk2, tsk);
64601 + read_unlock(&tasklist_lock);
64602 + }
64603 +#endif
64604 +}
64605 +
64606 +int __gr_process_user_ban(struct user_struct *user)
64607 +{
64608 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64609 + if (unlikely(user->banned)) {
64610 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
64611 + user->banned = 0;
64612 + user->ban_expires = 0;
64613 + free_uid(user);
64614 + } else
64615 + return -EPERM;
64616 + }
64617 +#endif
64618 + return 0;
64619 +}
64620 +
64621 +int gr_process_user_ban(void)
64622 +{
64623 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64624 + return __gr_process_user_ban(current->cred->user);
64625 +#endif
64626 + return 0;
64627 +}
64628 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
64629 new file mode 100644
64630 index 0000000..4030d57
64631 --- /dev/null
64632 +++ b/grsecurity/grsec_sock.c
64633 @@ -0,0 +1,244 @@
64634 +#include <linux/kernel.h>
64635 +#include <linux/module.h>
64636 +#include <linux/sched.h>
64637 +#include <linux/file.h>
64638 +#include <linux/net.h>
64639 +#include <linux/in.h>
64640 +#include <linux/ip.h>
64641 +#include <net/sock.h>
64642 +#include <net/inet_sock.h>
64643 +#include <linux/grsecurity.h>
64644 +#include <linux/grinternal.h>
64645 +#include <linux/gracl.h>
64646 +
64647 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
64648 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
64649 +
64650 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
64651 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
64652 +
64653 +#ifdef CONFIG_UNIX_MODULE
64654 +EXPORT_SYMBOL(gr_acl_handle_unix);
64655 +EXPORT_SYMBOL(gr_acl_handle_mknod);
64656 +EXPORT_SYMBOL(gr_handle_chroot_unix);
64657 +EXPORT_SYMBOL(gr_handle_create);
64658 +#endif
64659 +
64660 +#ifdef CONFIG_GRKERNSEC
64661 +#define gr_conn_table_size 32749
64662 +struct conn_table_entry {
64663 + struct conn_table_entry *next;
64664 + struct signal_struct *sig;
64665 +};
64666 +
64667 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
64668 +DEFINE_SPINLOCK(gr_conn_table_lock);
64669 +
64670 +extern const char * gr_socktype_to_name(unsigned char type);
64671 +extern const char * gr_proto_to_name(unsigned char proto);
64672 +extern const char * gr_sockfamily_to_name(unsigned char family);
64673 +
64674 +static __inline__ int
64675 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
64676 +{
64677 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
64678 +}
64679 +
64680 +static __inline__ int
64681 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
64682 + __u16 sport, __u16 dport)
64683 +{
64684 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
64685 + sig->gr_sport == sport && sig->gr_dport == dport))
64686 + return 1;
64687 + else
64688 + return 0;
64689 +}
64690 +
64691 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
64692 +{
64693 + struct conn_table_entry **match;
64694 + unsigned int index;
64695 +
64696 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
64697 + sig->gr_sport, sig->gr_dport,
64698 + gr_conn_table_size);
64699 +
64700 + newent->sig = sig;
64701 +
64702 + match = &gr_conn_table[index];
64703 + newent->next = *match;
64704 + *match = newent;
64705 +
64706 + return;
64707 +}
64708 +
64709 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
64710 +{
64711 + struct conn_table_entry *match, *last = NULL;
64712 + unsigned int index;
64713 +
64714 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
64715 + sig->gr_sport, sig->gr_dport,
64716 + gr_conn_table_size);
64717 +
64718 + match = gr_conn_table[index];
64719 + while (match && !conn_match(match->sig,
64720 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
64721 + sig->gr_dport)) {
64722 + last = match;
64723 + match = match->next;
64724 + }
64725 +
64726 + if (match) {
64727 + if (last)
64728 + last->next = match->next;
64729 + else
64730 + gr_conn_table[index] = NULL;
64731 + kfree(match);
64732 + }
64733 +
64734 + return;
64735 +}
64736 +
64737 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
64738 + __u16 sport, __u16 dport)
64739 +{
64740 + struct conn_table_entry *match;
64741 + unsigned int index;
64742 +
64743 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
64744 +
64745 + match = gr_conn_table[index];
64746 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
64747 + match = match->next;
64748 +
64749 + if (match)
64750 + return match->sig;
64751 + else
64752 + return NULL;
64753 +}
64754 +
64755 +#endif
64756 +
64757 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
64758 +{
64759 +#ifdef CONFIG_GRKERNSEC
64760 + struct signal_struct *sig = task->signal;
64761 + struct conn_table_entry *newent;
64762 +
64763 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
64764 + if (newent == NULL)
64765 + return;
64766 + /* no bh lock needed since we are called with bh disabled */
64767 + spin_lock(&gr_conn_table_lock);
64768 + gr_del_task_from_ip_table_nolock(sig);
64769 + sig->gr_saddr = inet->inet_rcv_saddr;
64770 + sig->gr_daddr = inet->inet_daddr;
64771 + sig->gr_sport = inet->inet_sport;
64772 + sig->gr_dport = inet->inet_dport;
64773 + gr_add_to_task_ip_table_nolock(sig, newent);
64774 + spin_unlock(&gr_conn_table_lock);
64775 +#endif
64776 + return;
64777 +}
64778 +
64779 +void gr_del_task_from_ip_table(struct task_struct *task)
64780 +{
64781 +#ifdef CONFIG_GRKERNSEC
64782 + spin_lock_bh(&gr_conn_table_lock);
64783 + gr_del_task_from_ip_table_nolock(task->signal);
64784 + spin_unlock_bh(&gr_conn_table_lock);
64785 +#endif
64786 + return;
64787 +}
64788 +
64789 +void
64790 +gr_attach_curr_ip(const struct sock *sk)
64791 +{
64792 +#ifdef CONFIG_GRKERNSEC
64793 + struct signal_struct *p, *set;
64794 + const struct inet_sock *inet = inet_sk(sk);
64795 +
64796 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
64797 + return;
64798 +
64799 + set = current->signal;
64800 +
64801 + spin_lock_bh(&gr_conn_table_lock);
64802 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
64803 + inet->inet_dport, inet->inet_sport);
64804 + if (unlikely(p != NULL)) {
64805 + set->curr_ip = p->curr_ip;
64806 + set->used_accept = 1;
64807 + gr_del_task_from_ip_table_nolock(p);
64808 + spin_unlock_bh(&gr_conn_table_lock);
64809 + return;
64810 + }
64811 + spin_unlock_bh(&gr_conn_table_lock);
64812 +
64813 + set->curr_ip = inet->inet_daddr;
64814 + set->used_accept = 1;
64815 +#endif
64816 + return;
64817 +}
64818 +
64819 +int
64820 +gr_handle_sock_all(const int family, const int type, const int protocol)
64821 +{
64822 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
64823 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
64824 + (family != AF_UNIX)) {
64825 + if (family == AF_INET)
64826 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
64827 + else
64828 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
64829 + return -EACCES;
64830 + }
64831 +#endif
64832 + return 0;
64833 +}
64834 +
64835 +int
64836 +gr_handle_sock_server(const struct sockaddr *sck)
64837 +{
64838 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64839 + if (grsec_enable_socket_server &&
64840 + in_group_p(grsec_socket_server_gid) &&
64841 + sck && (sck->sa_family != AF_UNIX) &&
64842 + (sck->sa_family != AF_LOCAL)) {
64843 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
64844 + return -EACCES;
64845 + }
64846 +#endif
64847 + return 0;
64848 +}
64849 +
64850 +int
64851 +gr_handle_sock_server_other(const struct sock *sck)
64852 +{
64853 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64854 + if (grsec_enable_socket_server &&
64855 + in_group_p(grsec_socket_server_gid) &&
64856 + sck && (sck->sk_family != AF_UNIX) &&
64857 + (sck->sk_family != AF_LOCAL)) {
64858 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
64859 + return -EACCES;
64860 + }
64861 +#endif
64862 + return 0;
64863 +}
64864 +
64865 +int
64866 +gr_handle_sock_client(const struct sockaddr *sck)
64867 +{
64868 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64869 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
64870 + sck && (sck->sa_family != AF_UNIX) &&
64871 + (sck->sa_family != AF_LOCAL)) {
64872 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
64873 + return -EACCES;
64874 + }
64875 +#endif
64876 + return 0;
64877 +}
64878 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
64879 new file mode 100644
64880 index 0000000..f55ef0f
64881 --- /dev/null
64882 +++ b/grsecurity/grsec_sysctl.c
64883 @@ -0,0 +1,469 @@
64884 +#include <linux/kernel.h>
64885 +#include <linux/sched.h>
64886 +#include <linux/sysctl.h>
64887 +#include <linux/grsecurity.h>
64888 +#include <linux/grinternal.h>
64889 +
64890 +int
64891 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
64892 +{
64893 +#ifdef CONFIG_GRKERNSEC_SYSCTL
64894 + if (dirname == NULL || name == NULL)
64895 + return 0;
64896 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
64897 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
64898 + return -EACCES;
64899 + }
64900 +#endif
64901 + return 0;
64902 +}
64903 +
64904 +#ifdef CONFIG_GRKERNSEC_ROFS
64905 +static int __maybe_unused one = 1;
64906 +#endif
64907 +
64908 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
64909 +struct ctl_table grsecurity_table[] = {
64910 +#ifdef CONFIG_GRKERNSEC_SYSCTL
64911 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
64912 +#ifdef CONFIG_GRKERNSEC_IO
64913 + {
64914 + .procname = "disable_priv_io",
64915 + .data = &grsec_disable_privio,
64916 + .maxlen = sizeof(int),
64917 + .mode = 0600,
64918 + .proc_handler = &proc_dointvec,
64919 + },
64920 +#endif
64921 +#endif
64922 +#ifdef CONFIG_GRKERNSEC_LINK
64923 + {
64924 + .procname = "linking_restrictions",
64925 + .data = &grsec_enable_link,
64926 + .maxlen = sizeof(int),
64927 + .mode = 0600,
64928 + .proc_handler = &proc_dointvec,
64929 + },
64930 +#endif
64931 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64932 + {
64933 + .procname = "enforce_symlinksifowner",
64934 + .data = &grsec_enable_symlinkown,
64935 + .maxlen = sizeof(int),
64936 + .mode = 0600,
64937 + .proc_handler = &proc_dointvec,
64938 + },
64939 + {
64940 + .procname = "symlinkown_gid",
64941 + .data = &grsec_symlinkown_gid,
64942 + .maxlen = sizeof(int),
64943 + .mode = 0600,
64944 + .proc_handler = &proc_dointvec,
64945 + },
64946 +#endif
64947 +#ifdef CONFIG_GRKERNSEC_BRUTE
64948 + {
64949 + .procname = "deter_bruteforce",
64950 + .data = &grsec_enable_brute,
64951 + .maxlen = sizeof(int),
64952 + .mode = 0600,
64953 + .proc_handler = &proc_dointvec,
64954 + },
64955 +#endif
64956 +#ifdef CONFIG_GRKERNSEC_FIFO
64957 + {
64958 + .procname = "fifo_restrictions",
64959 + .data = &grsec_enable_fifo,
64960 + .maxlen = sizeof(int),
64961 + .mode = 0600,
64962 + .proc_handler = &proc_dointvec,
64963 + },
64964 +#endif
64965 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64966 + {
64967 + .procname = "ptrace_readexec",
64968 + .data = &grsec_enable_ptrace_readexec,
64969 + .maxlen = sizeof(int),
64970 + .mode = 0600,
64971 + .proc_handler = &proc_dointvec,
64972 + },
64973 +#endif
64974 +#ifdef CONFIG_GRKERNSEC_SETXID
64975 + {
64976 + .procname = "consistent_setxid",
64977 + .data = &grsec_enable_setxid,
64978 + .maxlen = sizeof(int),
64979 + .mode = 0600,
64980 + .proc_handler = &proc_dointvec,
64981 + },
64982 +#endif
64983 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
64984 + {
64985 + .procname = "ip_blackhole",
64986 + .data = &grsec_enable_blackhole,
64987 + .maxlen = sizeof(int),
64988 + .mode = 0600,
64989 + .proc_handler = &proc_dointvec,
64990 + },
64991 + {
64992 + .procname = "lastack_retries",
64993 + .data = &grsec_lastack_retries,
64994 + .maxlen = sizeof(int),
64995 + .mode = 0600,
64996 + .proc_handler = &proc_dointvec,
64997 + },
64998 +#endif
64999 +#ifdef CONFIG_GRKERNSEC_EXECLOG
65000 + {
65001 + .procname = "exec_logging",
65002 + .data = &grsec_enable_execlog,
65003 + .maxlen = sizeof(int),
65004 + .mode = 0600,
65005 + .proc_handler = &proc_dointvec,
65006 + },
65007 +#endif
65008 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65009 + {
65010 + .procname = "rwxmap_logging",
65011 + .data = &grsec_enable_log_rwxmaps,
65012 + .maxlen = sizeof(int),
65013 + .mode = 0600,
65014 + .proc_handler = &proc_dointvec,
65015 + },
65016 +#endif
65017 +#ifdef CONFIG_GRKERNSEC_SIGNAL
65018 + {
65019 + .procname = "signal_logging",
65020 + .data = &grsec_enable_signal,
65021 + .maxlen = sizeof(int),
65022 + .mode = 0600,
65023 + .proc_handler = &proc_dointvec,
65024 + },
65025 +#endif
65026 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
65027 + {
65028 + .procname = "forkfail_logging",
65029 + .data = &grsec_enable_forkfail,
65030 + .maxlen = sizeof(int),
65031 + .mode = 0600,
65032 + .proc_handler = &proc_dointvec,
65033 + },
65034 +#endif
65035 +#ifdef CONFIG_GRKERNSEC_TIME
65036 + {
65037 + .procname = "timechange_logging",
65038 + .data = &grsec_enable_time,
65039 + .maxlen = sizeof(int),
65040 + .mode = 0600,
65041 + .proc_handler = &proc_dointvec,
65042 + },
65043 +#endif
65044 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65045 + {
65046 + .procname = "chroot_deny_shmat",
65047 + .data = &grsec_enable_chroot_shmat,
65048 + .maxlen = sizeof(int),
65049 + .mode = 0600,
65050 + .proc_handler = &proc_dointvec,
65051 + },
65052 +#endif
65053 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65054 + {
65055 + .procname = "chroot_deny_unix",
65056 + .data = &grsec_enable_chroot_unix,
65057 + .maxlen = sizeof(int),
65058 + .mode = 0600,
65059 + .proc_handler = &proc_dointvec,
65060 + },
65061 +#endif
65062 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65063 + {
65064 + .procname = "chroot_deny_mount",
65065 + .data = &grsec_enable_chroot_mount,
65066 + .maxlen = sizeof(int),
65067 + .mode = 0600,
65068 + .proc_handler = &proc_dointvec,
65069 + },
65070 +#endif
65071 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65072 + {
65073 + .procname = "chroot_deny_fchdir",
65074 + .data = &grsec_enable_chroot_fchdir,
65075 + .maxlen = sizeof(int),
65076 + .mode = 0600,
65077 + .proc_handler = &proc_dointvec,
65078 + },
65079 +#endif
65080 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65081 + {
65082 + .procname = "chroot_deny_chroot",
65083 + .data = &grsec_enable_chroot_double,
65084 + .maxlen = sizeof(int),
65085 + .mode = 0600,
65086 + .proc_handler = &proc_dointvec,
65087 + },
65088 +#endif
65089 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65090 + {
65091 + .procname = "chroot_deny_pivot",
65092 + .data = &grsec_enable_chroot_pivot,
65093 + .maxlen = sizeof(int),
65094 + .mode = 0600,
65095 + .proc_handler = &proc_dointvec,
65096 + },
65097 +#endif
65098 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65099 + {
65100 + .procname = "chroot_enforce_chdir",
65101 + .data = &grsec_enable_chroot_chdir,
65102 + .maxlen = sizeof(int),
65103 + .mode = 0600,
65104 + .proc_handler = &proc_dointvec,
65105 + },
65106 +#endif
65107 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65108 + {
65109 + .procname = "chroot_deny_chmod",
65110 + .data = &grsec_enable_chroot_chmod,
65111 + .maxlen = sizeof(int),
65112 + .mode = 0600,
65113 + .proc_handler = &proc_dointvec,
65114 + },
65115 +#endif
65116 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65117 + {
65118 + .procname = "chroot_deny_mknod",
65119 + .data = &grsec_enable_chroot_mknod,
65120 + .maxlen = sizeof(int),
65121 + .mode = 0600,
65122 + .proc_handler = &proc_dointvec,
65123 + },
65124 +#endif
65125 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65126 + {
65127 + .procname = "chroot_restrict_nice",
65128 + .data = &grsec_enable_chroot_nice,
65129 + .maxlen = sizeof(int),
65130 + .mode = 0600,
65131 + .proc_handler = &proc_dointvec,
65132 + },
65133 +#endif
65134 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65135 + {
65136 + .procname = "chroot_execlog",
65137 + .data = &grsec_enable_chroot_execlog,
65138 + .maxlen = sizeof(int),
65139 + .mode = 0600,
65140 + .proc_handler = &proc_dointvec,
65141 + },
65142 +#endif
65143 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65144 + {
65145 + .procname = "chroot_caps",
65146 + .data = &grsec_enable_chroot_caps,
65147 + .maxlen = sizeof(int),
65148 + .mode = 0600,
65149 + .proc_handler = &proc_dointvec,
65150 + },
65151 +#endif
65152 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65153 + {
65154 + .procname = "chroot_deny_sysctl",
65155 + .data = &grsec_enable_chroot_sysctl,
65156 + .maxlen = sizeof(int),
65157 + .mode = 0600,
65158 + .proc_handler = &proc_dointvec,
65159 + },
65160 +#endif
65161 +#ifdef CONFIG_GRKERNSEC_TPE
65162 + {
65163 + .procname = "tpe",
65164 + .data = &grsec_enable_tpe,
65165 + .maxlen = sizeof(int),
65166 + .mode = 0600,
65167 + .proc_handler = &proc_dointvec,
65168 + },
65169 + {
65170 + .procname = "tpe_gid",
65171 + .data = &grsec_tpe_gid,
65172 + .maxlen = sizeof(int),
65173 + .mode = 0600,
65174 + .proc_handler = &proc_dointvec,
65175 + },
65176 +#endif
65177 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65178 + {
65179 + .procname = "tpe_invert",
65180 + .data = &grsec_enable_tpe_invert,
65181 + .maxlen = sizeof(int),
65182 + .mode = 0600,
65183 + .proc_handler = &proc_dointvec,
65184 + },
65185 +#endif
65186 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
65187 + {
65188 + .procname = "tpe_restrict_all",
65189 + .data = &grsec_enable_tpe_all,
65190 + .maxlen = sizeof(int),
65191 + .mode = 0600,
65192 + .proc_handler = &proc_dointvec,
65193 + },
65194 +#endif
65195 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65196 + {
65197 + .procname = "socket_all",
65198 + .data = &grsec_enable_socket_all,
65199 + .maxlen = sizeof(int),
65200 + .mode = 0600,
65201 + .proc_handler = &proc_dointvec,
65202 + },
65203 + {
65204 + .procname = "socket_all_gid",
65205 + .data = &grsec_socket_all_gid,
65206 + .maxlen = sizeof(int),
65207 + .mode = 0600,
65208 + .proc_handler = &proc_dointvec,
65209 + },
65210 +#endif
65211 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65212 + {
65213 + .procname = "socket_client",
65214 + .data = &grsec_enable_socket_client,
65215 + .maxlen = sizeof(int),
65216 + .mode = 0600,
65217 + .proc_handler = &proc_dointvec,
65218 + },
65219 + {
65220 + .procname = "socket_client_gid",
65221 + .data = &grsec_socket_client_gid,
65222 + .maxlen = sizeof(int),
65223 + .mode = 0600,
65224 + .proc_handler = &proc_dointvec,
65225 + },
65226 +#endif
65227 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65228 + {
65229 + .procname = "socket_server",
65230 + .data = &grsec_enable_socket_server,
65231 + .maxlen = sizeof(int),
65232 + .mode = 0600,
65233 + .proc_handler = &proc_dointvec,
65234 + },
65235 + {
65236 + .procname = "socket_server_gid",
65237 + .data = &grsec_socket_server_gid,
65238 + .maxlen = sizeof(int),
65239 + .mode = 0600,
65240 + .proc_handler = &proc_dointvec,
65241 + },
65242 +#endif
65243 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65244 + {
65245 + .procname = "audit_group",
65246 + .data = &grsec_enable_group,
65247 + .maxlen = sizeof(int),
65248 + .mode = 0600,
65249 + .proc_handler = &proc_dointvec,
65250 + },
65251 + {
65252 + .procname = "audit_gid",
65253 + .data = &grsec_audit_gid,
65254 + .maxlen = sizeof(int),
65255 + .mode = 0600,
65256 + .proc_handler = &proc_dointvec,
65257 + },
65258 +#endif
65259 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65260 + {
65261 + .procname = "audit_chdir",
65262 + .data = &grsec_enable_chdir,
65263 + .maxlen = sizeof(int),
65264 + .mode = 0600,
65265 + .proc_handler = &proc_dointvec,
65266 + },
65267 +#endif
65268 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65269 + {
65270 + .procname = "audit_mount",
65271 + .data = &grsec_enable_mount,
65272 + .maxlen = sizeof(int),
65273 + .mode = 0600,
65274 + .proc_handler = &proc_dointvec,
65275 + },
65276 +#endif
65277 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65278 + {
65279 + .procname = "audit_textrel",
65280 + .data = &grsec_enable_audit_textrel,
65281 + .maxlen = sizeof(int),
65282 + .mode = 0600,
65283 + .proc_handler = &proc_dointvec,
65284 + },
65285 +#endif
65286 +#ifdef CONFIG_GRKERNSEC_DMESG
65287 + {
65288 + .procname = "dmesg",
65289 + .data = &grsec_enable_dmesg,
65290 + .maxlen = sizeof(int),
65291 + .mode = 0600,
65292 + .proc_handler = &proc_dointvec,
65293 + },
65294 +#endif
65295 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65296 + {
65297 + .procname = "chroot_findtask",
65298 + .data = &grsec_enable_chroot_findtask,
65299 + .maxlen = sizeof(int),
65300 + .mode = 0600,
65301 + .proc_handler = &proc_dointvec,
65302 + },
65303 +#endif
65304 +#ifdef CONFIG_GRKERNSEC_RESLOG
65305 + {
65306 + .procname = "resource_logging",
65307 + .data = &grsec_resource_logging,
65308 + .maxlen = sizeof(int),
65309 + .mode = 0600,
65310 + .proc_handler = &proc_dointvec,
65311 + },
65312 +#endif
65313 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65314 + {
65315 + .procname = "audit_ptrace",
65316 + .data = &grsec_enable_audit_ptrace,
65317 + .maxlen = sizeof(int),
65318 + .mode = 0600,
65319 + .proc_handler = &proc_dointvec,
65320 + },
65321 +#endif
65322 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65323 + {
65324 + .procname = "harden_ptrace",
65325 + .data = &grsec_enable_harden_ptrace,
65326 + .maxlen = sizeof(int),
65327 + .mode = 0600,
65328 + .proc_handler = &proc_dointvec,
65329 + },
65330 +#endif
65331 + {
65332 + .procname = "grsec_lock",
65333 + .data = &grsec_lock,
65334 + .maxlen = sizeof(int),
65335 + .mode = 0600,
65336 + .proc_handler = &proc_dointvec,
65337 + },
65338 +#endif
65339 +#ifdef CONFIG_GRKERNSEC_ROFS
65340 + {
65341 + .procname = "romount_protect",
65342 + .data = &grsec_enable_rofs,
65343 + .maxlen = sizeof(int),
65344 + .mode = 0600,
65345 + .proc_handler = &proc_dointvec_minmax,
65346 + .extra1 = &one,
65347 + .extra2 = &one,
65348 + },
65349 +#endif
65350 + { }
65351 +};
65352 +#endif
65353 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
65354 new file mode 100644
65355 index 0000000..0dc13c3
65356 --- /dev/null
65357 +++ b/grsecurity/grsec_time.c
65358 @@ -0,0 +1,16 @@
65359 +#include <linux/kernel.h>
65360 +#include <linux/sched.h>
65361 +#include <linux/grinternal.h>
65362 +#include <linux/module.h>
65363 +
65364 +void
65365 +gr_log_timechange(void)
65366 +{
65367 +#ifdef CONFIG_GRKERNSEC_TIME
65368 + if (grsec_enable_time)
65369 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
65370 +#endif
65371 + return;
65372 +}
65373 +
65374 +EXPORT_SYMBOL(gr_log_timechange);
65375 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
65376 new file mode 100644
65377 index 0000000..ee57dcf
65378 --- /dev/null
65379 +++ b/grsecurity/grsec_tpe.c
65380 @@ -0,0 +1,73 @@
65381 +#include <linux/kernel.h>
65382 +#include <linux/sched.h>
65383 +#include <linux/file.h>
65384 +#include <linux/fs.h>
65385 +#include <linux/grinternal.h>
65386 +
65387 +extern int gr_acl_tpe_check(void);
65388 +
65389 +int
65390 +gr_tpe_allow(const struct file *file)
65391 +{
65392 +#ifdef CONFIG_GRKERNSEC
65393 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
65394 + const struct cred *cred = current_cred();
65395 + char *msg = NULL;
65396 + char *msg2 = NULL;
65397 +
65398 + // never restrict root
65399 + if (gr_is_global_root(cred->uid))
65400 + return 1;
65401 +
65402 + if (grsec_enable_tpe) {
65403 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65404 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
65405 + msg = "not being in trusted group";
65406 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
65407 + msg = "being in untrusted group";
65408 +#else
65409 + if (in_group_p(grsec_tpe_gid))
65410 + msg = "being in untrusted group";
65411 +#endif
65412 + }
65413 + if (!msg && gr_acl_tpe_check())
65414 + msg = "being in untrusted role";
65415 +
65416 + // not in any affected group/role
65417 + if (!msg)
65418 + goto next_check;
65419 +
65420 + if (gr_is_global_nonroot(inode->i_uid))
65421 + msg2 = "file in non-root-owned directory";
65422 + else if (inode->i_mode & S_IWOTH)
65423 + msg2 = "file in world-writable directory";
65424 + else if (inode->i_mode & S_IWGRP)
65425 + msg2 = "file in group-writable directory";
65426 +
65427 + if (msg && msg2) {
65428 + char fullmsg[70] = {0};
65429 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
65430 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
65431 + return 0;
65432 + }
65433 + msg = NULL;
65434 +next_check:
65435 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
65436 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
65437 + return 1;
65438 +
65439 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
65440 + msg = "directory not owned by user";
65441 + else if (inode->i_mode & S_IWOTH)
65442 + msg = "file in world-writable directory";
65443 + else if (inode->i_mode & S_IWGRP)
65444 + msg = "file in group-writable directory";
65445 +
65446 + if (msg) {
65447 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
65448 + return 0;
65449 + }
65450 +#endif
65451 +#endif
65452 + return 1;
65453 +}
65454 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
65455 new file mode 100644
65456 index 0000000..9f7b1ac
65457 --- /dev/null
65458 +++ b/grsecurity/grsum.c
65459 @@ -0,0 +1,61 @@
65460 +#include <linux/err.h>
65461 +#include <linux/kernel.h>
65462 +#include <linux/sched.h>
65463 +#include <linux/mm.h>
65464 +#include <linux/scatterlist.h>
65465 +#include <linux/crypto.h>
65466 +#include <linux/gracl.h>
65467 +
65468 +
65469 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
65470 +#error "crypto and sha256 must be built into the kernel"
65471 +#endif
65472 +
65473 +int
65474 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
65475 +{
65476 + char *p;
65477 + struct crypto_hash *tfm;
65478 + struct hash_desc desc;
65479 + struct scatterlist sg;
65480 + unsigned char temp_sum[GR_SHA_LEN];
65481 + volatile int retval = 0;
65482 + volatile int dummy = 0;
65483 + unsigned int i;
65484 +
65485 + sg_init_table(&sg, 1);
65486 +
65487 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
65488 + if (IS_ERR(tfm)) {
65489 + /* should never happen, since sha256 should be built in */
65490 + return 1;
65491 + }
65492 +
65493 + desc.tfm = tfm;
65494 + desc.flags = 0;
65495 +
65496 + crypto_hash_init(&desc);
65497 +
65498 + p = salt;
65499 + sg_set_buf(&sg, p, GR_SALT_LEN);
65500 + crypto_hash_update(&desc, &sg, sg.length);
65501 +
65502 + p = entry->pw;
65503 + sg_set_buf(&sg, p, strlen(p));
65504 +
65505 + crypto_hash_update(&desc, &sg, sg.length);
65506 +
65507 + crypto_hash_final(&desc, temp_sum);
65508 +
65509 + memset(entry->pw, 0, GR_PW_LEN);
65510 +
65511 + for (i = 0; i < GR_SHA_LEN; i++)
65512 + if (sum[i] != temp_sum[i])
65513 + retval = 1;
65514 + else
65515 + dummy = 1; // waste a cycle
65516 +
65517 + crypto_free_hash(tfm);
65518 +
65519 + return retval;
65520 +}
65521 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
65522 index 77ff547..181834f 100644
65523 --- a/include/asm-generic/4level-fixup.h
65524 +++ b/include/asm-generic/4level-fixup.h
65525 @@ -13,8 +13,10 @@
65526 #define pmd_alloc(mm, pud, address) \
65527 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
65528 NULL: pmd_offset(pud, address))
65529 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
65530
65531 #define pud_alloc(mm, pgd, address) (pgd)
65532 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
65533 #define pud_offset(pgd, start) (pgd)
65534 #define pud_none(pud) 0
65535 #define pud_bad(pud) 0
65536 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
65537 index b7babf0..04ad282 100644
65538 --- a/include/asm-generic/atomic-long.h
65539 +++ b/include/asm-generic/atomic-long.h
65540 @@ -22,6 +22,12 @@
65541
65542 typedef atomic64_t atomic_long_t;
65543
65544 +#ifdef CONFIG_PAX_REFCOUNT
65545 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
65546 +#else
65547 +typedef atomic64_t atomic_long_unchecked_t;
65548 +#endif
65549 +
65550 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
65551
65552 static inline long atomic_long_read(atomic_long_t *l)
65553 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
65554 return (long)atomic64_read(v);
65555 }
65556
65557 +#ifdef CONFIG_PAX_REFCOUNT
65558 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
65559 +{
65560 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65561 +
65562 + return (long)atomic64_read_unchecked(v);
65563 +}
65564 +#endif
65565 +
65566 static inline void atomic_long_set(atomic_long_t *l, long i)
65567 {
65568 atomic64_t *v = (atomic64_t *)l;
65569 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
65570 atomic64_set(v, i);
65571 }
65572
65573 +#ifdef CONFIG_PAX_REFCOUNT
65574 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
65575 +{
65576 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65577 +
65578 + atomic64_set_unchecked(v, i);
65579 +}
65580 +#endif
65581 +
65582 static inline void atomic_long_inc(atomic_long_t *l)
65583 {
65584 atomic64_t *v = (atomic64_t *)l;
65585 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
65586 atomic64_inc(v);
65587 }
65588
65589 +#ifdef CONFIG_PAX_REFCOUNT
65590 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
65591 +{
65592 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65593 +
65594 + atomic64_inc_unchecked(v);
65595 +}
65596 +#endif
65597 +
65598 static inline void atomic_long_dec(atomic_long_t *l)
65599 {
65600 atomic64_t *v = (atomic64_t *)l;
65601 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
65602 atomic64_dec(v);
65603 }
65604
65605 +#ifdef CONFIG_PAX_REFCOUNT
65606 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
65607 +{
65608 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65609 +
65610 + atomic64_dec_unchecked(v);
65611 +}
65612 +#endif
65613 +
65614 static inline void atomic_long_add(long i, atomic_long_t *l)
65615 {
65616 atomic64_t *v = (atomic64_t *)l;
65617 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
65618 atomic64_add(i, v);
65619 }
65620
65621 +#ifdef CONFIG_PAX_REFCOUNT
65622 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
65623 +{
65624 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65625 +
65626 + atomic64_add_unchecked(i, v);
65627 +}
65628 +#endif
65629 +
65630 static inline void atomic_long_sub(long i, atomic_long_t *l)
65631 {
65632 atomic64_t *v = (atomic64_t *)l;
65633 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
65634 atomic64_sub(i, v);
65635 }
65636
65637 +#ifdef CONFIG_PAX_REFCOUNT
65638 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
65639 +{
65640 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65641 +
65642 + atomic64_sub_unchecked(i, v);
65643 +}
65644 +#endif
65645 +
65646 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
65647 {
65648 atomic64_t *v = (atomic64_t *)l;
65649 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
65650 return (long)atomic64_add_return(i, v);
65651 }
65652
65653 +#ifdef CONFIG_PAX_REFCOUNT
65654 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
65655 +{
65656 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65657 +
65658 + return (long)atomic64_add_return_unchecked(i, v);
65659 +}
65660 +#endif
65661 +
65662 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
65663 {
65664 atomic64_t *v = (atomic64_t *)l;
65665 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
65666 return (long)atomic64_inc_return(v);
65667 }
65668
65669 +#ifdef CONFIG_PAX_REFCOUNT
65670 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
65671 +{
65672 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65673 +
65674 + return (long)atomic64_inc_return_unchecked(v);
65675 +}
65676 +#endif
65677 +
65678 static inline long atomic_long_dec_return(atomic_long_t *l)
65679 {
65680 atomic64_t *v = (atomic64_t *)l;
65681 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
65682
65683 typedef atomic_t atomic_long_t;
65684
65685 +#ifdef CONFIG_PAX_REFCOUNT
65686 +typedef atomic_unchecked_t atomic_long_unchecked_t;
65687 +#else
65688 +typedef atomic_t atomic_long_unchecked_t;
65689 +#endif
65690 +
65691 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
65692 static inline long atomic_long_read(atomic_long_t *l)
65693 {
65694 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
65695 return (long)atomic_read(v);
65696 }
65697
65698 +#ifdef CONFIG_PAX_REFCOUNT
65699 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
65700 +{
65701 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65702 +
65703 + return (long)atomic_read_unchecked(v);
65704 +}
65705 +#endif
65706 +
65707 static inline void atomic_long_set(atomic_long_t *l, long i)
65708 {
65709 atomic_t *v = (atomic_t *)l;
65710 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
65711 atomic_set(v, i);
65712 }
65713
65714 +#ifdef CONFIG_PAX_REFCOUNT
65715 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
65716 +{
65717 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65718 +
65719 + atomic_set_unchecked(v, i);
65720 +}
65721 +#endif
65722 +
65723 static inline void atomic_long_inc(atomic_long_t *l)
65724 {
65725 atomic_t *v = (atomic_t *)l;
65726 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
65727 atomic_inc(v);
65728 }
65729
65730 +#ifdef CONFIG_PAX_REFCOUNT
65731 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
65732 +{
65733 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65734 +
65735 + atomic_inc_unchecked(v);
65736 +}
65737 +#endif
65738 +
65739 static inline void atomic_long_dec(atomic_long_t *l)
65740 {
65741 atomic_t *v = (atomic_t *)l;
65742 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
65743 atomic_dec(v);
65744 }
65745
65746 +#ifdef CONFIG_PAX_REFCOUNT
65747 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
65748 +{
65749 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65750 +
65751 + atomic_dec_unchecked(v);
65752 +}
65753 +#endif
65754 +
65755 static inline void atomic_long_add(long i, atomic_long_t *l)
65756 {
65757 atomic_t *v = (atomic_t *)l;
65758 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
65759 atomic_add(i, v);
65760 }
65761
65762 +#ifdef CONFIG_PAX_REFCOUNT
65763 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
65764 +{
65765 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65766 +
65767 + atomic_add_unchecked(i, v);
65768 +}
65769 +#endif
65770 +
65771 static inline void atomic_long_sub(long i, atomic_long_t *l)
65772 {
65773 atomic_t *v = (atomic_t *)l;
65774 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
65775 atomic_sub(i, v);
65776 }
65777
65778 +#ifdef CONFIG_PAX_REFCOUNT
65779 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
65780 +{
65781 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65782 +
65783 + atomic_sub_unchecked(i, v);
65784 +}
65785 +#endif
65786 +
65787 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
65788 {
65789 atomic_t *v = (atomic_t *)l;
65790 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
65791 return (long)atomic_add_return(i, v);
65792 }
65793
65794 +#ifdef CONFIG_PAX_REFCOUNT
65795 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
65796 +{
65797 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65798 +
65799 + return (long)atomic_add_return_unchecked(i, v);
65800 +}
65801 +
65802 +#endif
65803 +
65804 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
65805 {
65806 atomic_t *v = (atomic_t *)l;
65807 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
65808 return (long)atomic_inc_return(v);
65809 }
65810
65811 +#ifdef CONFIG_PAX_REFCOUNT
65812 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
65813 +{
65814 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65815 +
65816 + return (long)atomic_inc_return_unchecked(v);
65817 +}
65818 +#endif
65819 +
65820 static inline long atomic_long_dec_return(atomic_long_t *l)
65821 {
65822 atomic_t *v = (atomic_t *)l;
65823 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
65824
65825 #endif /* BITS_PER_LONG == 64 */
65826
65827 +#ifdef CONFIG_PAX_REFCOUNT
65828 +static inline void pax_refcount_needs_these_functions(void)
65829 +{
65830 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
65831 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
65832 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
65833 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
65834 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
65835 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
65836 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
65837 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
65838 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
65839 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
65840 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
65841 +#ifdef CONFIG_X86
65842 + atomic_clear_mask_unchecked(0, NULL);
65843 + atomic_set_mask_unchecked(0, NULL);
65844 +#endif
65845 +
65846 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
65847 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
65848 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
65849 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
65850 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
65851 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
65852 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
65853 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
65854 +}
65855 +#else
65856 +#define atomic_read_unchecked(v) atomic_read(v)
65857 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
65858 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
65859 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
65860 +#define atomic_inc_unchecked(v) atomic_inc(v)
65861 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
65862 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
65863 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
65864 +#define atomic_dec_unchecked(v) atomic_dec(v)
65865 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
65866 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
65867 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
65868 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
65869 +
65870 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
65871 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
65872 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
65873 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
65874 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
65875 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
65876 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
65877 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
65878 +#endif
65879 +
65880 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
65881 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
65882 index 1ced641..c896ee8 100644
65883 --- a/include/asm-generic/atomic.h
65884 +++ b/include/asm-generic/atomic.h
65885 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
65886 * Atomically clears the bits set in @mask from @v
65887 */
65888 #ifndef atomic_clear_mask
65889 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
65890 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
65891 {
65892 unsigned long flags;
65893
65894 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
65895 index b18ce4f..2ee2843 100644
65896 --- a/include/asm-generic/atomic64.h
65897 +++ b/include/asm-generic/atomic64.h
65898 @@ -16,6 +16,8 @@ typedef struct {
65899 long long counter;
65900 } atomic64_t;
65901
65902 +typedef atomic64_t atomic64_unchecked_t;
65903 +
65904 #define ATOMIC64_INIT(i) { (i) }
65905
65906 extern long long atomic64_read(const atomic64_t *v);
65907 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
65908 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
65909 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
65910
65911 +#define atomic64_read_unchecked(v) atomic64_read(v)
65912 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
65913 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
65914 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
65915 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
65916 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
65917 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
65918 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
65919 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
65920 +
65921 #endif /* _ASM_GENERIC_ATOMIC64_H */
65922 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
65923 index 1bfcfe5..e04c5c9 100644
65924 --- a/include/asm-generic/cache.h
65925 +++ b/include/asm-generic/cache.h
65926 @@ -6,7 +6,7 @@
65927 * cache lines need to provide their own cache.h.
65928 */
65929
65930 -#define L1_CACHE_SHIFT 5
65931 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
65932 +#define L1_CACHE_SHIFT 5UL
65933 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
65934
65935 #endif /* __ASM_GENERIC_CACHE_H */
65936 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
65937 index 0d68a1e..b74a761 100644
65938 --- a/include/asm-generic/emergency-restart.h
65939 +++ b/include/asm-generic/emergency-restart.h
65940 @@ -1,7 +1,7 @@
65941 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
65942 #define _ASM_GENERIC_EMERGENCY_RESTART_H
65943
65944 -static inline void machine_emergency_restart(void)
65945 +static inline __noreturn void machine_emergency_restart(void)
65946 {
65947 machine_restart(NULL);
65948 }
65949 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
65950 index 90f99c7..00ce236 100644
65951 --- a/include/asm-generic/kmap_types.h
65952 +++ b/include/asm-generic/kmap_types.h
65953 @@ -2,9 +2,9 @@
65954 #define _ASM_GENERIC_KMAP_TYPES_H
65955
65956 #ifdef __WITH_KM_FENCE
65957 -# define KM_TYPE_NR 41
65958 +# define KM_TYPE_NR 42
65959 #else
65960 -# define KM_TYPE_NR 20
65961 +# define KM_TYPE_NR 21
65962 #endif
65963
65964 #endif
65965 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
65966 index 9ceb03b..62b0b8f 100644
65967 --- a/include/asm-generic/local.h
65968 +++ b/include/asm-generic/local.h
65969 @@ -23,24 +23,37 @@ typedef struct
65970 atomic_long_t a;
65971 } local_t;
65972
65973 +typedef struct {
65974 + atomic_long_unchecked_t a;
65975 +} local_unchecked_t;
65976 +
65977 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
65978
65979 #define local_read(l) atomic_long_read(&(l)->a)
65980 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
65981 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
65982 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
65983 #define local_inc(l) atomic_long_inc(&(l)->a)
65984 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
65985 #define local_dec(l) atomic_long_dec(&(l)->a)
65986 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
65987 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
65988 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
65989 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
65990 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
65991
65992 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
65993 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
65994 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
65995 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
65996 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
65997 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
65998 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
65999 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
66000 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
66001
66002 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66003 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66004 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
66005 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
66006 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
66007 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
66008 index 725612b..9cc513a 100644
66009 --- a/include/asm-generic/pgtable-nopmd.h
66010 +++ b/include/asm-generic/pgtable-nopmd.h
66011 @@ -1,14 +1,19 @@
66012 #ifndef _PGTABLE_NOPMD_H
66013 #define _PGTABLE_NOPMD_H
66014
66015 -#ifndef __ASSEMBLY__
66016 -
66017 #include <asm-generic/pgtable-nopud.h>
66018
66019 -struct mm_struct;
66020 -
66021 #define __PAGETABLE_PMD_FOLDED
66022
66023 +#define PMD_SHIFT PUD_SHIFT
66024 +#define PTRS_PER_PMD 1
66025 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
66026 +#define PMD_MASK (~(PMD_SIZE-1))
66027 +
66028 +#ifndef __ASSEMBLY__
66029 +
66030 +struct mm_struct;
66031 +
66032 /*
66033 * Having the pmd type consist of a pud gets the size right, and allows
66034 * us to conceptually access the pud entry that this pmd is folded into
66035 @@ -16,11 +21,6 @@ struct mm_struct;
66036 */
66037 typedef struct { pud_t pud; } pmd_t;
66038
66039 -#define PMD_SHIFT PUD_SHIFT
66040 -#define PTRS_PER_PMD 1
66041 -#define PMD_SIZE (1UL << PMD_SHIFT)
66042 -#define PMD_MASK (~(PMD_SIZE-1))
66043 -
66044 /*
66045 * The "pud_xxx()" functions here are trivial for a folded two-level
66046 * setup: the pmd is never bad, and a pmd always exists (as it's folded
66047 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
66048 index 810431d..0ec4804f 100644
66049 --- a/include/asm-generic/pgtable-nopud.h
66050 +++ b/include/asm-generic/pgtable-nopud.h
66051 @@ -1,10 +1,15 @@
66052 #ifndef _PGTABLE_NOPUD_H
66053 #define _PGTABLE_NOPUD_H
66054
66055 -#ifndef __ASSEMBLY__
66056 -
66057 #define __PAGETABLE_PUD_FOLDED
66058
66059 +#define PUD_SHIFT PGDIR_SHIFT
66060 +#define PTRS_PER_PUD 1
66061 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
66062 +#define PUD_MASK (~(PUD_SIZE-1))
66063 +
66064 +#ifndef __ASSEMBLY__
66065 +
66066 /*
66067 * Having the pud type consist of a pgd gets the size right, and allows
66068 * us to conceptually access the pgd entry that this pud is folded into
66069 @@ -12,11 +17,6 @@
66070 */
66071 typedef struct { pgd_t pgd; } pud_t;
66072
66073 -#define PUD_SHIFT PGDIR_SHIFT
66074 -#define PTRS_PER_PUD 1
66075 -#define PUD_SIZE (1UL << PUD_SHIFT)
66076 -#define PUD_MASK (~(PUD_SIZE-1))
66077 -
66078 /*
66079 * The "pgd_xxx()" functions here are trivial for a folded two-level
66080 * setup: the pud is never bad, and a pud always exists (as it's folded
66081 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
66082 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
66083
66084 #define pgd_populate(mm, pgd, pud) do { } while (0)
66085 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
66086 /*
66087 * (puds are folded into pgds so this doesn't get actually called,
66088 * but the define is needed for a generic inline function.)
66089 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
66090 index 5cf680a..4b74d62 100644
66091 --- a/include/asm-generic/pgtable.h
66092 +++ b/include/asm-generic/pgtable.h
66093 @@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
66094 }
66095 #endif /* CONFIG_NUMA_BALANCING */
66096
66097 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
66098 +static inline unsigned long pax_open_kernel(void) { return 0; }
66099 +#endif
66100 +
66101 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
66102 +static inline unsigned long pax_close_kernel(void) { return 0; }
66103 +#endif
66104 +
66105 #endif /* CONFIG_MMU */
66106
66107 #endif /* !__ASSEMBLY__ */
66108 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
66109 index d1ea7ce..b1ebf2a 100644
66110 --- a/include/asm-generic/vmlinux.lds.h
66111 +++ b/include/asm-generic/vmlinux.lds.h
66112 @@ -218,6 +218,7 @@
66113 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
66114 VMLINUX_SYMBOL(__start_rodata) = .; \
66115 *(.rodata) *(.rodata.*) \
66116 + *(.data..read_only) \
66117 *(__vermagic) /* Kernel version magic */ \
66118 . = ALIGN(8); \
66119 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
66120 @@ -725,17 +726,18 @@
66121 * section in the linker script will go there too. @phdr should have
66122 * a leading colon.
66123 *
66124 - * Note that this macros defines __per_cpu_load as an absolute symbol.
66125 + * Note that this macros defines per_cpu_load as an absolute symbol.
66126 * If there is no need to put the percpu section at a predetermined
66127 * address, use PERCPU_SECTION.
66128 */
66129 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
66130 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
66131 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
66132 + per_cpu_load = .; \
66133 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
66134 - LOAD_OFFSET) { \
66135 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
66136 PERCPU_INPUT(cacheline) \
66137 } phdr \
66138 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
66139 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
66140
66141 /**
66142 * PERCPU_SECTION - define output section for percpu area, simple version
66143 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
66144 index 418d270..bfd2794 100644
66145 --- a/include/crypto/algapi.h
66146 +++ b/include/crypto/algapi.h
66147 @@ -34,7 +34,7 @@ struct crypto_type {
66148 unsigned int maskclear;
66149 unsigned int maskset;
66150 unsigned int tfmsize;
66151 -};
66152 +} __do_const;
66153
66154 struct crypto_instance {
66155 struct crypto_alg alg;
66156 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
66157 index fad21c9..ab858bc 100644
66158 --- a/include/drm/drmP.h
66159 +++ b/include/drm/drmP.h
66160 @@ -72,6 +72,7 @@
66161 #include <linux/workqueue.h>
66162 #include <linux/poll.h>
66163 #include <asm/pgalloc.h>
66164 +#include <asm/local.h>
66165 #include <drm/drm.h>
66166 #include <drm/drm_sarea.h>
66167
66168 @@ -293,10 +294,12 @@ do { \
66169 * \param cmd command.
66170 * \param arg argument.
66171 */
66172 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
66173 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
66174 + struct drm_file *file_priv);
66175 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
66176 struct drm_file *file_priv);
66177
66178 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66179 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
66180 unsigned long arg);
66181
66182 #define DRM_IOCTL_NR(n) _IOC_NR(n)
66183 @@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66184 struct drm_ioctl_desc {
66185 unsigned int cmd;
66186 int flags;
66187 - drm_ioctl_t *func;
66188 + drm_ioctl_t func;
66189 unsigned int cmd_drv;
66190 -};
66191 +} __do_const;
66192
66193 /**
66194 * Creates a driver or general drm_ioctl_desc array entry for the given
66195 @@ -995,7 +998,7 @@ struct drm_info_list {
66196 int (*show)(struct seq_file*, void*); /** show callback */
66197 u32 driver_features; /**< Required driver features for this entry */
66198 void *data;
66199 -};
66200 +} __do_const;
66201
66202 /**
66203 * debugfs node structure. This structure represents a debugfs file.
66204 @@ -1068,7 +1071,7 @@ struct drm_device {
66205
66206 /** \name Usage Counters */
66207 /*@{ */
66208 - int open_count; /**< Outstanding files open */
66209 + local_t open_count; /**< Outstanding files open */
66210 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
66211 atomic_t vma_count; /**< Outstanding vma areas open */
66212 int buf_use; /**< Buffers in use -- cannot alloc */
66213 @@ -1079,7 +1082,7 @@ struct drm_device {
66214 /*@{ */
66215 unsigned long counters;
66216 enum drm_stat_type types[15];
66217 - atomic_t counts[15];
66218 + atomic_unchecked_t counts[15];
66219 /*@} */
66220
66221 struct list_head filelist;
66222 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
66223 index f43d556..94d9343 100644
66224 --- a/include/drm/drm_crtc_helper.h
66225 +++ b/include/drm/drm_crtc_helper.h
66226 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
66227 struct drm_connector *connector);
66228 /* disable encoder when not in use - more explicit than dpms off */
66229 void (*disable)(struct drm_encoder *encoder);
66230 -};
66231 +} __no_const;
66232
66233 /**
66234 * drm_connector_helper_funcs - helper operations for connectors
66235 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
66236 index 72dcbe8..8db58d7 100644
66237 --- a/include/drm/ttm/ttm_memory.h
66238 +++ b/include/drm/ttm/ttm_memory.h
66239 @@ -48,7 +48,7 @@
66240
66241 struct ttm_mem_shrink {
66242 int (*do_shrink) (struct ttm_mem_shrink *);
66243 -};
66244 +} __no_const;
66245
66246 /**
66247 * struct ttm_mem_global - Global memory accounting structure.
66248 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
66249 index 4b840e8..155d235 100644
66250 --- a/include/keys/asymmetric-subtype.h
66251 +++ b/include/keys/asymmetric-subtype.h
66252 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
66253 /* Verify the signature on a key of this subtype (optional) */
66254 int (*verify_signature)(const struct key *key,
66255 const struct public_key_signature *sig);
66256 -};
66257 +} __do_const;
66258
66259 /**
66260 * asymmetric_key_subtype - Get the subtype from an asymmetric key
66261 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
66262 index c1da539..1dcec55 100644
66263 --- a/include/linux/atmdev.h
66264 +++ b/include/linux/atmdev.h
66265 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
66266 #endif
66267
66268 struct k_atm_aal_stats {
66269 -#define __HANDLE_ITEM(i) atomic_t i
66270 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
66271 __AAL_STAT_ITEMS
66272 #undef __HANDLE_ITEM
66273 };
66274 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
66275 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
66276 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
66277 struct module *owner;
66278 -};
66279 +} __do_const ;
66280
66281 struct atmphy_ops {
66282 int (*start)(struct atm_dev *dev);
66283 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
66284 index 0530b98..96a8ac0 100644
66285 --- a/include/linux/binfmts.h
66286 +++ b/include/linux/binfmts.h
66287 @@ -73,8 +73,9 @@ struct linux_binfmt {
66288 int (*load_binary)(struct linux_binprm *);
66289 int (*load_shlib)(struct file *);
66290 int (*core_dump)(struct coredump_params *cprm);
66291 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
66292 unsigned long min_coredump; /* minimal dump size */
66293 -};
66294 +} __do_const;
66295
66296 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
66297
66298 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
66299 index f94bc83..62b9cfe 100644
66300 --- a/include/linux/blkdev.h
66301 +++ b/include/linux/blkdev.h
66302 @@ -1498,7 +1498,7 @@ struct block_device_operations {
66303 /* this callback is with swap_lock and sometimes page table lock held */
66304 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
66305 struct module *owner;
66306 -};
66307 +} __do_const;
66308
66309 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
66310 unsigned long);
66311 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
66312 index 7c2e030..b72475d 100644
66313 --- a/include/linux/blktrace_api.h
66314 +++ b/include/linux/blktrace_api.h
66315 @@ -23,7 +23,7 @@ struct blk_trace {
66316 struct dentry *dir;
66317 struct dentry *dropped_file;
66318 struct dentry *msg_file;
66319 - atomic_t dropped;
66320 + atomic_unchecked_t dropped;
66321 };
66322
66323 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
66324 diff --git a/include/linux/cache.h b/include/linux/cache.h
66325 index 4c57065..4307975 100644
66326 --- a/include/linux/cache.h
66327 +++ b/include/linux/cache.h
66328 @@ -16,6 +16,10 @@
66329 #define __read_mostly
66330 #endif
66331
66332 +#ifndef __read_only
66333 +#define __read_only __read_mostly
66334 +#endif
66335 +
66336 #ifndef ____cacheline_aligned
66337 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
66338 #endif
66339 diff --git a/include/linux/capability.h b/include/linux/capability.h
66340 index 98503b7..cc36d18 100644
66341 --- a/include/linux/capability.h
66342 +++ b/include/linux/capability.h
66343 @@ -211,8 +211,13 @@ extern bool capable(int cap);
66344 extern bool ns_capable(struct user_namespace *ns, int cap);
66345 extern bool nsown_capable(int cap);
66346 extern bool inode_capable(const struct inode *inode, int cap);
66347 +extern bool capable_nolog(int cap);
66348 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
66349 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
66350
66351 /* audit system wants to get cap info from files as well */
66352 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
66353
66354 +extern int is_privileged_binary(const struct dentry *dentry);
66355 +
66356 #endif /* !_LINUX_CAPABILITY_H */
66357 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
66358 index 8609d57..86e4d79 100644
66359 --- a/include/linux/cdrom.h
66360 +++ b/include/linux/cdrom.h
66361 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
66362
66363 /* driver specifications */
66364 const int capability; /* capability flags */
66365 - int n_minors; /* number of active minor devices */
66366 /* handle uniform packets for scsi type devices (scsi,atapi) */
66367 int (*generic_packet) (struct cdrom_device_info *,
66368 struct packet_command *);
66369 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
66370 index 42e55de..1cd0e66 100644
66371 --- a/include/linux/cleancache.h
66372 +++ b/include/linux/cleancache.h
66373 @@ -31,7 +31,7 @@ struct cleancache_ops {
66374 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
66375 void (*invalidate_inode)(int, struct cleancache_filekey);
66376 void (*invalidate_fs)(int);
66377 -};
66378 +} __no_const;
66379
66380 extern struct cleancache_ops
66381 cleancache_register_ops(struct cleancache_ops *ops);
66382 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
66383 index 662fd1b..e801992 100644
66384 --- a/include/linux/compiler-gcc4.h
66385 +++ b/include/linux/compiler-gcc4.h
66386 @@ -34,6 +34,21 @@
66387 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
66388
66389 #if __GNUC_MINOR__ >= 5
66390 +
66391 +#ifdef CONSTIFY_PLUGIN
66392 +#define __no_const __attribute__((no_const))
66393 +#define __do_const __attribute__((do_const))
66394 +#endif
66395 +
66396 +#ifdef SIZE_OVERFLOW_PLUGIN
66397 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
66398 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
66399 +#endif
66400 +
66401 +#ifdef LATENT_ENTROPY_PLUGIN
66402 +#define __latent_entropy __attribute__((latent_entropy))
66403 +#endif
66404 +
66405 /*
66406 * Mark a position in code as unreachable. This can be used to
66407 * suppress control flow warnings after asm blocks that transfer
66408 @@ -49,6 +64,11 @@
66409 #define __noclone __attribute__((__noclone__))
66410
66411 #endif
66412 +
66413 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
66414 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
66415 +#define __bos0(ptr) __bos((ptr), 0)
66416 +#define __bos1(ptr) __bos((ptr), 1)
66417 #endif
66418
66419 #if __GNUC_MINOR__ >= 6
66420 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
66421 index dd852b7..72924c0 100644
66422 --- a/include/linux/compiler.h
66423 +++ b/include/linux/compiler.h
66424 @@ -5,11 +5,14 @@
66425
66426 #ifdef __CHECKER__
66427 # define __user __attribute__((noderef, address_space(1)))
66428 +# define __force_user __force __user
66429 # define __kernel __attribute__((address_space(0)))
66430 +# define __force_kernel __force __kernel
66431 # define __safe __attribute__((safe))
66432 # define __force __attribute__((force))
66433 # define __nocast __attribute__((nocast))
66434 # define __iomem __attribute__((noderef, address_space(2)))
66435 +# define __force_iomem __force __iomem
66436 # define __must_hold(x) __attribute__((context(x,1,1)))
66437 # define __acquires(x) __attribute__((context(x,0,1)))
66438 # define __releases(x) __attribute__((context(x,1,0)))
66439 @@ -17,20 +20,48 @@
66440 # define __release(x) __context__(x,-1)
66441 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
66442 # define __percpu __attribute__((noderef, address_space(3)))
66443 +# define __force_percpu __force __percpu
66444 #ifdef CONFIG_SPARSE_RCU_POINTER
66445 # define __rcu __attribute__((noderef, address_space(4)))
66446 +# define __force_rcu __force __rcu
66447 #else
66448 # define __rcu
66449 +# define __force_rcu
66450 #endif
66451 extern void __chk_user_ptr(const volatile void __user *);
66452 extern void __chk_io_ptr(const volatile void __iomem *);
66453 +#elif defined(CHECKER_PLUGIN)
66454 +//# define __user
66455 +//# define __force_user
66456 +//# define __kernel
66457 +//# define __force_kernel
66458 +# define __safe
66459 +# define __force
66460 +# define __nocast
66461 +# define __iomem
66462 +# define __force_iomem
66463 +# define __chk_user_ptr(x) (void)0
66464 +# define __chk_io_ptr(x) (void)0
66465 +# define __builtin_warning(x, y...) (1)
66466 +# define __acquires(x)
66467 +# define __releases(x)
66468 +# define __acquire(x) (void)0
66469 +# define __release(x) (void)0
66470 +# define __cond_lock(x,c) (c)
66471 +# define __percpu
66472 +# define __force_percpu
66473 +# define __rcu
66474 +# define __force_rcu
66475 #else
66476 # define __user
66477 +# define __force_user
66478 # define __kernel
66479 +# define __force_kernel
66480 # define __safe
66481 # define __force
66482 # define __nocast
66483 # define __iomem
66484 +# define __force_iomem
66485 # define __chk_user_ptr(x) (void)0
66486 # define __chk_io_ptr(x) (void)0
66487 # define __builtin_warning(x, y...) (1)
66488 @@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
66489 # define __release(x) (void)0
66490 # define __cond_lock(x,c) (c)
66491 # define __percpu
66492 +# define __force_percpu
66493 # define __rcu
66494 +# define __force_rcu
66495 #endif
66496
66497 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
66498 @@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66499 # define __attribute_const__ /* unimplemented */
66500 #endif
66501
66502 +#ifndef __no_const
66503 +# define __no_const
66504 +#endif
66505 +
66506 +#ifndef __do_const
66507 +# define __do_const
66508 +#endif
66509 +
66510 +#ifndef __size_overflow
66511 +# define __size_overflow(...)
66512 +#endif
66513 +
66514 +#ifndef __intentional_overflow
66515 +# define __intentional_overflow(...)
66516 +#endif
66517 +
66518 +#ifndef __latent_entropy
66519 +# define __latent_entropy
66520 +#endif
66521 +
66522 /*
66523 * Tell gcc if a function is cold. The compiler will assume any path
66524 * directly leading to the call is unlikely.
66525 @@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66526 #define __cold
66527 #endif
66528
66529 +#ifndef __alloc_size
66530 +#define __alloc_size(...)
66531 +#endif
66532 +
66533 +#ifndef __bos
66534 +#define __bos(ptr, arg)
66535 +#endif
66536 +
66537 +#ifndef __bos0
66538 +#define __bos0(ptr)
66539 +#endif
66540 +
66541 +#ifndef __bos1
66542 +#define __bos1(ptr)
66543 +#endif
66544 +
66545 /* Simple shorthand for a section definition */
66546 #ifndef __section
66547 # define __section(S) __attribute__ ((__section__(#S)))
66548 @@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66549 * use is to mediate communication between process-level code and irq/NMI
66550 * handlers, all running on the same CPU.
66551 */
66552 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
66553 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
66554 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
66555
66556 #endif /* __LINUX_COMPILER_H */
66557 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
66558 index 34025df..d94bbbc 100644
66559 --- a/include/linux/configfs.h
66560 +++ b/include/linux/configfs.h
66561 @@ -125,7 +125,7 @@ struct configfs_attribute {
66562 const char *ca_name;
66563 struct module *ca_owner;
66564 umode_t ca_mode;
66565 -};
66566 +} __do_const;
66567
66568 /*
66569 * Users often need to create attribute structures for their configurable
66570 diff --git a/include/linux/cpu.h b/include/linux/cpu.h
66571 index ce7a074..01ab8ac 100644
66572 --- a/include/linux/cpu.h
66573 +++ b/include/linux/cpu.h
66574 @@ -115,7 +115,7 @@ enum {
66575 /* Need to know about CPUs going up/down? */
66576 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
66577 #define cpu_notifier(fn, pri) { \
66578 - static struct notifier_block fn##_nb __cpuinitdata = \
66579 + static struct notifier_block fn##_nb = \
66580 { .notifier_call = fn, .priority = pri }; \
66581 register_cpu_notifier(&fn##_nb); \
66582 }
66583 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
66584 index a55b88e..fba90c5 100644
66585 --- a/include/linux/cpufreq.h
66586 +++ b/include/linux/cpufreq.h
66587 @@ -240,7 +240,7 @@ struct cpufreq_driver {
66588 int (*suspend) (struct cpufreq_policy *policy);
66589 int (*resume) (struct cpufreq_policy *policy);
66590 struct freq_attr **attr;
66591 -};
66592 +} __do_const;
66593
66594 /* flags */
66595
66596 @@ -299,6 +299,7 @@ struct global_attr {
66597 ssize_t (*store)(struct kobject *a, struct attribute *b,
66598 const char *c, size_t count);
66599 };
66600 +typedef struct global_attr __no_const global_attr_no_const;
66601
66602 #define define_one_global_ro(_name) \
66603 static struct global_attr _name = \
66604 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
66605 index 24cd1037..20a63aae 100644
66606 --- a/include/linux/cpuidle.h
66607 +++ b/include/linux/cpuidle.h
66608 @@ -54,7 +54,8 @@ struct cpuidle_state {
66609 int index);
66610
66611 int (*enter_dead) (struct cpuidle_device *dev, int index);
66612 -};
66613 +} __do_const;
66614 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
66615
66616 /* Idle State Flags */
66617 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
66618 @@ -216,7 +217,7 @@ struct cpuidle_governor {
66619 void (*reflect) (struct cpuidle_device *dev, int index);
66620
66621 struct module *owner;
66622 -};
66623 +} __do_const;
66624
66625 #ifdef CONFIG_CPU_IDLE
66626
66627 diff --git a/include/linux/cred.h b/include/linux/cred.h
66628 index 04421e8..6bce4ef 100644
66629 --- a/include/linux/cred.h
66630 +++ b/include/linux/cred.h
66631 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
66632 static inline void validate_process_creds(void)
66633 {
66634 }
66635 +static inline void validate_task_creds(struct task_struct *task)
66636 +{
66637 +}
66638 #endif
66639
66640 /**
66641 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
66642 index b92eadf..b4ecdc1 100644
66643 --- a/include/linux/crypto.h
66644 +++ b/include/linux/crypto.h
66645 @@ -373,7 +373,7 @@ struct cipher_tfm {
66646 const u8 *key, unsigned int keylen);
66647 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
66648 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
66649 -};
66650 +} __no_const;
66651
66652 struct hash_tfm {
66653 int (*init)(struct hash_desc *desc);
66654 @@ -394,13 +394,13 @@ struct compress_tfm {
66655 int (*cot_decompress)(struct crypto_tfm *tfm,
66656 const u8 *src, unsigned int slen,
66657 u8 *dst, unsigned int *dlen);
66658 -};
66659 +} __no_const;
66660
66661 struct rng_tfm {
66662 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
66663 unsigned int dlen);
66664 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
66665 -};
66666 +} __no_const;
66667
66668 #define crt_ablkcipher crt_u.ablkcipher
66669 #define crt_aead crt_u.aead
66670 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
66671 index 7925bf0..d5143d2 100644
66672 --- a/include/linux/decompress/mm.h
66673 +++ b/include/linux/decompress/mm.h
66674 @@ -77,7 +77,7 @@ static void free(void *where)
66675 * warnings when not needed (indeed large_malloc / large_free are not
66676 * needed by inflate */
66677
66678 -#define malloc(a) kmalloc(a, GFP_KERNEL)
66679 +#define malloc(a) kmalloc((a), GFP_KERNEL)
66680 #define free(a) kfree(a)
66681
66682 #define large_malloc(a) vmalloc(a)
66683 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
66684 index e83ef39..33e0eb3 100644
66685 --- a/include/linux/devfreq.h
66686 +++ b/include/linux/devfreq.h
66687 @@ -114,7 +114,7 @@ struct devfreq_governor {
66688 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
66689 int (*event_handler)(struct devfreq *devfreq,
66690 unsigned int event, void *data);
66691 -};
66692 +} __do_const;
66693
66694 /**
66695 * struct devfreq - Device devfreq structure
66696 diff --git a/include/linux/device.h b/include/linux/device.h
66697 index 43dcda9..7a1fb65 100644
66698 --- a/include/linux/device.h
66699 +++ b/include/linux/device.h
66700 @@ -294,7 +294,7 @@ struct subsys_interface {
66701 struct list_head node;
66702 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
66703 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
66704 -};
66705 +} __do_const;
66706
66707 int subsys_interface_register(struct subsys_interface *sif);
66708 void subsys_interface_unregister(struct subsys_interface *sif);
66709 @@ -474,7 +474,7 @@ struct device_type {
66710 void (*release)(struct device *dev);
66711
66712 const struct dev_pm_ops *pm;
66713 -};
66714 +} __do_const;
66715
66716 /* interface for exporting device attributes */
66717 struct device_attribute {
66718 @@ -484,11 +484,12 @@ struct device_attribute {
66719 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
66720 const char *buf, size_t count);
66721 };
66722 +typedef struct device_attribute __no_const device_attribute_no_const;
66723
66724 struct dev_ext_attribute {
66725 struct device_attribute attr;
66726 void *var;
66727 -};
66728 +} __do_const;
66729
66730 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
66731 char *buf);
66732 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
66733 index 94af418..b1ca7a2 100644
66734 --- a/include/linux/dma-mapping.h
66735 +++ b/include/linux/dma-mapping.h
66736 @@ -54,7 +54,7 @@ struct dma_map_ops {
66737 u64 (*get_required_mask)(struct device *dev);
66738 #endif
66739 int is_phys;
66740 -};
66741 +} __do_const;
66742
66743 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
66744
66745 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
66746 index d3201e4..8281e63 100644
66747 --- a/include/linux/dmaengine.h
66748 +++ b/include/linux/dmaengine.h
66749 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
66750 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
66751 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
66752
66753 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
66754 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
66755 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
66756 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
66757 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
66758 struct dma_pinned_list *pinned_list, struct page *page,
66759 unsigned int offset, size_t len);
66760
66761 diff --git a/include/linux/efi.h b/include/linux/efi.h
66762 index 7a9498a..155713d 100644
66763 --- a/include/linux/efi.h
66764 +++ b/include/linux/efi.h
66765 @@ -733,6 +733,7 @@ struct efivar_operations {
66766 efi_set_variable_t *set_variable;
66767 efi_query_variable_info_t *query_variable_info;
66768 };
66769 +typedef struct efivar_operations __no_const efivar_operations_no_const;
66770
66771 struct efivars {
66772 /*
66773 diff --git a/include/linux/elf.h b/include/linux/elf.h
66774 index 8c9048e..16a4665 100644
66775 --- a/include/linux/elf.h
66776 +++ b/include/linux/elf.h
66777 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
66778 #define elf_note elf32_note
66779 #define elf_addr_t Elf32_Off
66780 #define Elf_Half Elf32_Half
66781 +#define elf_dyn Elf32_Dyn
66782
66783 #else
66784
66785 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
66786 #define elf_note elf64_note
66787 #define elf_addr_t Elf64_Off
66788 #define Elf_Half Elf64_Half
66789 +#define elf_dyn Elf64_Dyn
66790
66791 #endif
66792
66793 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
66794 index fcb51c8..bdafcf6 100644
66795 --- a/include/linux/extcon.h
66796 +++ b/include/linux/extcon.h
66797 @@ -134,7 +134,7 @@ struct extcon_dev {
66798 /* /sys/class/extcon/.../mutually_exclusive/... */
66799 struct attribute_group attr_g_muex;
66800 struct attribute **attrs_muex;
66801 - struct device_attribute *d_attrs_muex;
66802 + device_attribute_no_const *d_attrs_muex;
66803 };
66804
66805 /**
66806 diff --git a/include/linux/fb.h b/include/linux/fb.h
66807 index c7a9571..02eeffe 100644
66808 --- a/include/linux/fb.h
66809 +++ b/include/linux/fb.h
66810 @@ -302,7 +302,7 @@ struct fb_ops {
66811 /* called at KDB enter and leave time to prepare the console */
66812 int (*fb_debug_enter)(struct fb_info *info);
66813 int (*fb_debug_leave)(struct fb_info *info);
66814 -};
66815 +} __do_const;
66816
66817 #ifdef CONFIG_FB_TILEBLITTING
66818 #define FB_TILE_CURSOR_NONE 0
66819 diff --git a/include/linux/filter.h b/include/linux/filter.h
66820 index c45eabc..baa0be5 100644
66821 --- a/include/linux/filter.h
66822 +++ b/include/linux/filter.h
66823 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
66824
66825 struct sk_buff;
66826 struct sock;
66827 +struct bpf_jit_work;
66828
66829 struct sk_filter
66830 {
66831 @@ -27,6 +28,9 @@ struct sk_filter
66832 unsigned int len; /* Number of filter blocks */
66833 unsigned int (*bpf_func)(const struct sk_buff *skb,
66834 const struct sock_filter *filter);
66835 +#ifdef CONFIG_BPF_JIT
66836 + struct bpf_jit_work *work;
66837 +#endif
66838 struct rcu_head rcu;
66839 struct sock_filter insns[0];
66840 };
66841 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
66842 index 3044254..9767f41 100644
66843 --- a/include/linux/frontswap.h
66844 +++ b/include/linux/frontswap.h
66845 @@ -11,7 +11,7 @@ struct frontswap_ops {
66846 int (*load)(unsigned, pgoff_t, struct page *);
66847 void (*invalidate_page)(unsigned, pgoff_t);
66848 void (*invalidate_area)(unsigned);
66849 -};
66850 +} __no_const;
66851
66852 extern bool frontswap_enabled;
66853 extern struct frontswap_ops
66854 diff --git a/include/linux/fs.h b/include/linux/fs.h
66855 index 7617ee0..b575199 100644
66856 --- a/include/linux/fs.h
66857 +++ b/include/linux/fs.h
66858 @@ -1541,7 +1541,8 @@ struct file_operations {
66859 long (*fallocate)(struct file *file, int mode, loff_t offset,
66860 loff_t len);
66861 int (*show_fdinfo)(struct seq_file *m, struct file *f);
66862 -};
66863 +} __do_const;
66864 +typedef struct file_operations __no_const file_operations_no_const;
66865
66866 struct inode_operations {
66867 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
66868 @@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
66869 inode->i_flags |= S_NOSEC;
66870 }
66871
66872 +static inline bool is_sidechannel_device(const struct inode *inode)
66873 +{
66874 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
66875 + umode_t mode = inode->i_mode;
66876 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
66877 +#else
66878 + return false;
66879 +#endif
66880 +}
66881 +
66882 #endif /* _LINUX_FS_H */
66883 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
66884 index d0ae3a8..0244b34 100644
66885 --- a/include/linux/fs_struct.h
66886 +++ b/include/linux/fs_struct.h
66887 @@ -6,7 +6,7 @@
66888 #include <linux/seqlock.h>
66889
66890 struct fs_struct {
66891 - int users;
66892 + atomic_t users;
66893 spinlock_t lock;
66894 seqcount_t seq;
66895 int umask;
66896 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
66897 index 5dfa0aa..6acf322 100644
66898 --- a/include/linux/fscache-cache.h
66899 +++ b/include/linux/fscache-cache.h
66900 @@ -112,7 +112,7 @@ struct fscache_operation {
66901 fscache_operation_release_t release;
66902 };
66903
66904 -extern atomic_t fscache_op_debug_id;
66905 +extern atomic_unchecked_t fscache_op_debug_id;
66906 extern void fscache_op_work_func(struct work_struct *work);
66907
66908 extern void fscache_enqueue_operation(struct fscache_operation *);
66909 @@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
66910 INIT_WORK(&op->work, fscache_op_work_func);
66911 atomic_set(&op->usage, 1);
66912 op->state = FSCACHE_OP_ST_INITIALISED;
66913 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
66914 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
66915 op->processor = processor;
66916 op->release = release;
66917 INIT_LIST_HEAD(&op->pend_link);
66918 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
66919 index 7a08623..4c07b0f 100644
66920 --- a/include/linux/fscache.h
66921 +++ b/include/linux/fscache.h
66922 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
66923 * - this is mandatory for any object that may have data
66924 */
66925 void (*now_uncached)(void *cookie_netfs_data);
66926 -};
66927 +} __do_const;
66928
66929 /*
66930 * fscache cached network filesystem type
66931 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
66932 index 0fbfb46..508eb0d 100644
66933 --- a/include/linux/fsnotify.h
66934 +++ b/include/linux/fsnotify.h
66935 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
66936 struct inode *inode = path->dentry->d_inode;
66937 __u32 mask = FS_ACCESS;
66938
66939 + if (is_sidechannel_device(inode))
66940 + return;
66941 +
66942 if (S_ISDIR(inode->i_mode))
66943 mask |= FS_ISDIR;
66944
66945 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
66946 struct inode *inode = path->dentry->d_inode;
66947 __u32 mask = FS_MODIFY;
66948
66949 + if (is_sidechannel_device(inode))
66950 + return;
66951 +
66952 if (S_ISDIR(inode->i_mode))
66953 mask |= FS_ISDIR;
66954
66955 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
66956 */
66957 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
66958 {
66959 - return kstrdup(name, GFP_KERNEL);
66960 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
66961 }
66962
66963 /*
66964 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
66965 index a3d4895..ddd2a50 100644
66966 --- a/include/linux/ftrace_event.h
66967 +++ b/include/linux/ftrace_event.h
66968 @@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
66969 extern int trace_add_event_call(struct ftrace_event_call *call);
66970 extern void trace_remove_event_call(struct ftrace_event_call *call);
66971
66972 -#define is_signed_type(type) (((type)(-1)) < 0)
66973 +#define is_signed_type(type) (((type)(-1)) < (type)1)
66974
66975 int trace_set_clr_event(const char *system, const char *event, int set);
66976
66977 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
66978 index 79b8bba..86b539e 100644
66979 --- a/include/linux/genhd.h
66980 +++ b/include/linux/genhd.h
66981 @@ -194,7 +194,7 @@ struct gendisk {
66982 struct kobject *slave_dir;
66983
66984 struct timer_rand_state *random;
66985 - atomic_t sync_io; /* RAID */
66986 + atomic_unchecked_t sync_io; /* RAID */
66987 struct disk_events *ev;
66988 #ifdef CONFIG_BLK_DEV_INTEGRITY
66989 struct blk_integrity *integrity;
66990 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
66991 index 023bc34..b02b46a 100644
66992 --- a/include/linux/genl_magic_func.h
66993 +++ b/include/linux/genl_magic_func.h
66994 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
66995 },
66996
66997 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
66998 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
66999 +static struct genl_ops ZZZ_genl_ops[] = {
67000 #include GENL_MAGIC_INCLUDE_FILE
67001 };
67002
67003 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
67004 index 0f615eb..5c3832f 100644
67005 --- a/include/linux/gfp.h
67006 +++ b/include/linux/gfp.h
67007 @@ -35,6 +35,13 @@ struct vm_area_struct;
67008 #define ___GFP_NO_KSWAPD 0x400000u
67009 #define ___GFP_OTHER_NODE 0x800000u
67010 #define ___GFP_WRITE 0x1000000u
67011 +
67012 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67013 +#define ___GFP_USERCOPY 0x2000000u
67014 +#else
67015 +#define ___GFP_USERCOPY 0
67016 +#endif
67017 +
67018 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
67019
67020 /*
67021 @@ -92,6 +99,7 @@ struct vm_area_struct;
67022 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
67023 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
67024 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
67025 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
67026
67027 /*
67028 * This may seem redundant, but it's a way of annotating false positives vs.
67029 @@ -99,7 +107,7 @@ struct vm_area_struct;
67030 */
67031 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
67032
67033 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
67034 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
67035 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
67036
67037 /* This equals 0, but use constants in case they ever change */
67038 @@ -153,6 +161,8 @@ struct vm_area_struct;
67039 /* 4GB DMA on some platforms */
67040 #define GFP_DMA32 __GFP_DMA32
67041
67042 +#define GFP_USERCOPY __GFP_USERCOPY
67043 +
67044 /* Convert GFP flags to their corresponding migrate type */
67045 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
67046 {
67047 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
67048 new file mode 100644
67049 index 0000000..ebe6d72
67050 --- /dev/null
67051 +++ b/include/linux/gracl.h
67052 @@ -0,0 +1,319 @@
67053 +#ifndef GR_ACL_H
67054 +#define GR_ACL_H
67055 +
67056 +#include <linux/grdefs.h>
67057 +#include <linux/resource.h>
67058 +#include <linux/capability.h>
67059 +#include <linux/dcache.h>
67060 +#include <asm/resource.h>
67061 +
67062 +/* Major status information */
67063 +
67064 +#define GR_VERSION "grsecurity 2.9.1"
67065 +#define GRSECURITY_VERSION 0x2901
67066 +
67067 +enum {
67068 + GR_SHUTDOWN = 0,
67069 + GR_ENABLE = 1,
67070 + GR_SPROLE = 2,
67071 + GR_RELOAD = 3,
67072 + GR_SEGVMOD = 4,
67073 + GR_STATUS = 5,
67074 + GR_UNSPROLE = 6,
67075 + GR_PASSSET = 7,
67076 + GR_SPROLEPAM = 8,
67077 +};
67078 +
67079 +/* Password setup definitions
67080 + * kernel/grhash.c */
67081 +enum {
67082 + GR_PW_LEN = 128,
67083 + GR_SALT_LEN = 16,
67084 + GR_SHA_LEN = 32,
67085 +};
67086 +
67087 +enum {
67088 + GR_SPROLE_LEN = 64,
67089 +};
67090 +
67091 +enum {
67092 + GR_NO_GLOB = 0,
67093 + GR_REG_GLOB,
67094 + GR_CREATE_GLOB
67095 +};
67096 +
67097 +#define GR_NLIMITS 32
67098 +
67099 +/* Begin Data Structures */
67100 +
67101 +struct sprole_pw {
67102 + unsigned char *rolename;
67103 + unsigned char salt[GR_SALT_LEN];
67104 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
67105 +};
67106 +
67107 +struct name_entry {
67108 + __u32 key;
67109 + ino_t inode;
67110 + dev_t device;
67111 + char *name;
67112 + __u16 len;
67113 + __u8 deleted;
67114 + struct name_entry *prev;
67115 + struct name_entry *next;
67116 +};
67117 +
67118 +struct inodev_entry {
67119 + struct name_entry *nentry;
67120 + struct inodev_entry *prev;
67121 + struct inodev_entry *next;
67122 +};
67123 +
67124 +struct acl_role_db {
67125 + struct acl_role_label **r_hash;
67126 + __u32 r_size;
67127 +};
67128 +
67129 +struct inodev_db {
67130 + struct inodev_entry **i_hash;
67131 + __u32 i_size;
67132 +};
67133 +
67134 +struct name_db {
67135 + struct name_entry **n_hash;
67136 + __u32 n_size;
67137 +};
67138 +
67139 +struct crash_uid {
67140 + uid_t uid;
67141 + unsigned long expires;
67142 +};
67143 +
67144 +struct gr_hash_struct {
67145 + void **table;
67146 + void **nametable;
67147 + void *first;
67148 + __u32 table_size;
67149 + __u32 used_size;
67150 + int type;
67151 +};
67152 +
67153 +/* Userspace Grsecurity ACL data structures */
67154 +
67155 +struct acl_subject_label {
67156 + char *filename;
67157 + ino_t inode;
67158 + dev_t device;
67159 + __u32 mode;
67160 + kernel_cap_t cap_mask;
67161 + kernel_cap_t cap_lower;
67162 + kernel_cap_t cap_invert_audit;
67163 +
67164 + struct rlimit res[GR_NLIMITS];
67165 + __u32 resmask;
67166 +
67167 + __u8 user_trans_type;
67168 + __u8 group_trans_type;
67169 + uid_t *user_transitions;
67170 + gid_t *group_transitions;
67171 + __u16 user_trans_num;
67172 + __u16 group_trans_num;
67173 +
67174 + __u32 sock_families[2];
67175 + __u32 ip_proto[8];
67176 + __u32 ip_type;
67177 + struct acl_ip_label **ips;
67178 + __u32 ip_num;
67179 + __u32 inaddr_any_override;
67180 +
67181 + __u32 crashes;
67182 + unsigned long expires;
67183 +
67184 + struct acl_subject_label *parent_subject;
67185 + struct gr_hash_struct *hash;
67186 + struct acl_subject_label *prev;
67187 + struct acl_subject_label *next;
67188 +
67189 + struct acl_object_label **obj_hash;
67190 + __u32 obj_hash_size;
67191 + __u16 pax_flags;
67192 +};
67193 +
67194 +struct role_allowed_ip {
67195 + __u32 addr;
67196 + __u32 netmask;
67197 +
67198 + struct role_allowed_ip *prev;
67199 + struct role_allowed_ip *next;
67200 +};
67201 +
67202 +struct role_transition {
67203 + char *rolename;
67204 +
67205 + struct role_transition *prev;
67206 + struct role_transition *next;
67207 +};
67208 +
67209 +struct acl_role_label {
67210 + char *rolename;
67211 + uid_t uidgid;
67212 + __u16 roletype;
67213 +
67214 + __u16 auth_attempts;
67215 + unsigned long expires;
67216 +
67217 + struct acl_subject_label *root_label;
67218 + struct gr_hash_struct *hash;
67219 +
67220 + struct acl_role_label *prev;
67221 + struct acl_role_label *next;
67222 +
67223 + struct role_transition *transitions;
67224 + struct role_allowed_ip *allowed_ips;
67225 + uid_t *domain_children;
67226 + __u16 domain_child_num;
67227 +
67228 + umode_t umask;
67229 +
67230 + struct acl_subject_label **subj_hash;
67231 + __u32 subj_hash_size;
67232 +};
67233 +
67234 +struct user_acl_role_db {
67235 + struct acl_role_label **r_table;
67236 + __u32 num_pointers; /* Number of allocations to track */
67237 + __u32 num_roles; /* Number of roles */
67238 + __u32 num_domain_children; /* Number of domain children */
67239 + __u32 num_subjects; /* Number of subjects */
67240 + __u32 num_objects; /* Number of objects */
67241 +};
67242 +
67243 +struct acl_object_label {
67244 + char *filename;
67245 + ino_t inode;
67246 + dev_t device;
67247 + __u32 mode;
67248 +
67249 + struct acl_subject_label *nested;
67250 + struct acl_object_label *globbed;
67251 +
67252 + /* next two structures not used */
67253 +
67254 + struct acl_object_label *prev;
67255 + struct acl_object_label *next;
67256 +};
67257 +
67258 +struct acl_ip_label {
67259 + char *iface;
67260 + __u32 addr;
67261 + __u32 netmask;
67262 + __u16 low, high;
67263 + __u8 mode;
67264 + __u32 type;
67265 + __u32 proto[8];
67266 +
67267 + /* next two structures not used */
67268 +
67269 + struct acl_ip_label *prev;
67270 + struct acl_ip_label *next;
67271 +};
67272 +
67273 +struct gr_arg {
67274 + struct user_acl_role_db role_db;
67275 + unsigned char pw[GR_PW_LEN];
67276 + unsigned char salt[GR_SALT_LEN];
67277 + unsigned char sum[GR_SHA_LEN];
67278 + unsigned char sp_role[GR_SPROLE_LEN];
67279 + struct sprole_pw *sprole_pws;
67280 + dev_t segv_device;
67281 + ino_t segv_inode;
67282 + uid_t segv_uid;
67283 + __u16 num_sprole_pws;
67284 + __u16 mode;
67285 +};
67286 +
67287 +struct gr_arg_wrapper {
67288 + struct gr_arg *arg;
67289 + __u32 version;
67290 + __u32 size;
67291 +};
67292 +
67293 +struct subject_map {
67294 + struct acl_subject_label *user;
67295 + struct acl_subject_label *kernel;
67296 + struct subject_map *prev;
67297 + struct subject_map *next;
67298 +};
67299 +
67300 +struct acl_subj_map_db {
67301 + struct subject_map **s_hash;
67302 + __u32 s_size;
67303 +};
67304 +
67305 +/* End Data Structures Section */
67306 +
67307 +/* Hash functions generated by empirical testing by Brad Spengler
67308 + Makes good use of the low bits of the inode. Generally 0-1 times
67309 + in loop for successful match. 0-3 for unsuccessful match.
67310 + Shift/add algorithm with modulus of table size and an XOR*/
67311 +
67312 +static __inline__ unsigned int
67313 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
67314 +{
67315 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
67316 +}
67317 +
67318 + static __inline__ unsigned int
67319 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
67320 +{
67321 + return ((const unsigned long)userp % sz);
67322 +}
67323 +
67324 +static __inline__ unsigned int
67325 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
67326 +{
67327 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
67328 +}
67329 +
67330 +static __inline__ unsigned int
67331 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
67332 +{
67333 + return full_name_hash((const unsigned char *)name, len) % sz;
67334 +}
67335 +
67336 +#define FOR_EACH_ROLE_START(role) \
67337 + role = role_list; \
67338 + while (role) {
67339 +
67340 +#define FOR_EACH_ROLE_END(role) \
67341 + role = role->prev; \
67342 + }
67343 +
67344 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
67345 + subj = NULL; \
67346 + iter = 0; \
67347 + while (iter < role->subj_hash_size) { \
67348 + if (subj == NULL) \
67349 + subj = role->subj_hash[iter]; \
67350 + if (subj == NULL) { \
67351 + iter++; \
67352 + continue; \
67353 + }
67354 +
67355 +#define FOR_EACH_SUBJECT_END(subj,iter) \
67356 + subj = subj->next; \
67357 + if (subj == NULL) \
67358 + iter++; \
67359 + }
67360 +
67361 +
67362 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
67363 + subj = role->hash->first; \
67364 + while (subj != NULL) {
67365 +
67366 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
67367 + subj = subj->next; \
67368 + }
67369 +
67370 +#endif
67371 +
67372 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
67373 new file mode 100644
67374 index 0000000..323ecf2
67375 --- /dev/null
67376 +++ b/include/linux/gralloc.h
67377 @@ -0,0 +1,9 @@
67378 +#ifndef __GRALLOC_H
67379 +#define __GRALLOC_H
67380 +
67381 +void acl_free_all(void);
67382 +int acl_alloc_stack_init(unsigned long size);
67383 +void *acl_alloc(unsigned long len);
67384 +void *acl_alloc_num(unsigned long num, unsigned long len);
67385 +
67386 +#endif
67387 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
67388 new file mode 100644
67389 index 0000000..be66033
67390 --- /dev/null
67391 +++ b/include/linux/grdefs.h
67392 @@ -0,0 +1,140 @@
67393 +#ifndef GRDEFS_H
67394 +#define GRDEFS_H
67395 +
67396 +/* Begin grsecurity status declarations */
67397 +
67398 +enum {
67399 + GR_READY = 0x01,
67400 + GR_STATUS_INIT = 0x00 // disabled state
67401 +};
67402 +
67403 +/* Begin ACL declarations */
67404 +
67405 +/* Role flags */
67406 +
67407 +enum {
67408 + GR_ROLE_USER = 0x0001,
67409 + GR_ROLE_GROUP = 0x0002,
67410 + GR_ROLE_DEFAULT = 0x0004,
67411 + GR_ROLE_SPECIAL = 0x0008,
67412 + GR_ROLE_AUTH = 0x0010,
67413 + GR_ROLE_NOPW = 0x0020,
67414 + GR_ROLE_GOD = 0x0040,
67415 + GR_ROLE_LEARN = 0x0080,
67416 + GR_ROLE_TPE = 0x0100,
67417 + GR_ROLE_DOMAIN = 0x0200,
67418 + GR_ROLE_PAM = 0x0400,
67419 + GR_ROLE_PERSIST = 0x0800
67420 +};
67421 +
67422 +/* ACL Subject and Object mode flags */
67423 +enum {
67424 + GR_DELETED = 0x80000000
67425 +};
67426 +
67427 +/* ACL Object-only mode flags */
67428 +enum {
67429 + GR_READ = 0x00000001,
67430 + GR_APPEND = 0x00000002,
67431 + GR_WRITE = 0x00000004,
67432 + GR_EXEC = 0x00000008,
67433 + GR_FIND = 0x00000010,
67434 + GR_INHERIT = 0x00000020,
67435 + GR_SETID = 0x00000040,
67436 + GR_CREATE = 0x00000080,
67437 + GR_DELETE = 0x00000100,
67438 + GR_LINK = 0x00000200,
67439 + GR_AUDIT_READ = 0x00000400,
67440 + GR_AUDIT_APPEND = 0x00000800,
67441 + GR_AUDIT_WRITE = 0x00001000,
67442 + GR_AUDIT_EXEC = 0x00002000,
67443 + GR_AUDIT_FIND = 0x00004000,
67444 + GR_AUDIT_INHERIT= 0x00008000,
67445 + GR_AUDIT_SETID = 0x00010000,
67446 + GR_AUDIT_CREATE = 0x00020000,
67447 + GR_AUDIT_DELETE = 0x00040000,
67448 + GR_AUDIT_LINK = 0x00080000,
67449 + GR_PTRACERD = 0x00100000,
67450 + GR_NOPTRACE = 0x00200000,
67451 + GR_SUPPRESS = 0x00400000,
67452 + GR_NOLEARN = 0x00800000,
67453 + GR_INIT_TRANSFER= 0x01000000
67454 +};
67455 +
67456 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
67457 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
67458 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
67459 +
67460 +/* ACL subject-only mode flags */
67461 +enum {
67462 + GR_KILL = 0x00000001,
67463 + GR_VIEW = 0x00000002,
67464 + GR_PROTECTED = 0x00000004,
67465 + GR_LEARN = 0x00000008,
67466 + GR_OVERRIDE = 0x00000010,
67467 + /* just a placeholder, this mode is only used in userspace */
67468 + GR_DUMMY = 0x00000020,
67469 + GR_PROTSHM = 0x00000040,
67470 + GR_KILLPROC = 0x00000080,
67471 + GR_KILLIPPROC = 0x00000100,
67472 + /* just a placeholder, this mode is only used in userspace */
67473 + GR_NOTROJAN = 0x00000200,
67474 + GR_PROTPROCFD = 0x00000400,
67475 + GR_PROCACCT = 0x00000800,
67476 + GR_RELAXPTRACE = 0x00001000,
67477 + //GR_NESTED = 0x00002000,
67478 + GR_INHERITLEARN = 0x00004000,
67479 + GR_PROCFIND = 0x00008000,
67480 + GR_POVERRIDE = 0x00010000,
67481 + GR_KERNELAUTH = 0x00020000,
67482 + GR_ATSECURE = 0x00040000,
67483 + GR_SHMEXEC = 0x00080000
67484 +};
67485 +
67486 +enum {
67487 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
67488 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
67489 + GR_PAX_ENABLE_MPROTECT = 0x0004,
67490 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
67491 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
67492 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
67493 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
67494 + GR_PAX_DISABLE_MPROTECT = 0x0400,
67495 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
67496 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
67497 +};
67498 +
67499 +enum {
67500 + GR_ID_USER = 0x01,
67501 + GR_ID_GROUP = 0x02,
67502 +};
67503 +
67504 +enum {
67505 + GR_ID_ALLOW = 0x01,
67506 + GR_ID_DENY = 0x02,
67507 +};
67508 +
67509 +#define GR_CRASH_RES 31
67510 +#define GR_UIDTABLE_MAX 500
67511 +
67512 +/* begin resource learning section */
67513 +enum {
67514 + GR_RLIM_CPU_BUMP = 60,
67515 + GR_RLIM_FSIZE_BUMP = 50000,
67516 + GR_RLIM_DATA_BUMP = 10000,
67517 + GR_RLIM_STACK_BUMP = 1000,
67518 + GR_RLIM_CORE_BUMP = 10000,
67519 + GR_RLIM_RSS_BUMP = 500000,
67520 + GR_RLIM_NPROC_BUMP = 1,
67521 + GR_RLIM_NOFILE_BUMP = 5,
67522 + GR_RLIM_MEMLOCK_BUMP = 50000,
67523 + GR_RLIM_AS_BUMP = 500000,
67524 + GR_RLIM_LOCKS_BUMP = 2,
67525 + GR_RLIM_SIGPENDING_BUMP = 5,
67526 + GR_RLIM_MSGQUEUE_BUMP = 10000,
67527 + GR_RLIM_NICE_BUMP = 1,
67528 + GR_RLIM_RTPRIO_BUMP = 1,
67529 + GR_RLIM_RTTIME_BUMP = 1000000
67530 +};
67531 +
67532 +#endif
67533 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
67534 new file mode 100644
67535 index 0000000..9bb6662
67536 --- /dev/null
67537 +++ b/include/linux/grinternal.h
67538 @@ -0,0 +1,215 @@
67539 +#ifndef __GRINTERNAL_H
67540 +#define __GRINTERNAL_H
67541 +
67542 +#ifdef CONFIG_GRKERNSEC
67543 +
67544 +#include <linux/fs.h>
67545 +#include <linux/mnt_namespace.h>
67546 +#include <linux/nsproxy.h>
67547 +#include <linux/gracl.h>
67548 +#include <linux/grdefs.h>
67549 +#include <linux/grmsg.h>
67550 +
67551 +void gr_add_learn_entry(const char *fmt, ...)
67552 + __attribute__ ((format (printf, 1, 2)));
67553 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
67554 + const struct vfsmount *mnt);
67555 +__u32 gr_check_create(const struct dentry *new_dentry,
67556 + const struct dentry *parent,
67557 + const struct vfsmount *mnt, const __u32 mode);
67558 +int gr_check_protected_task(const struct task_struct *task);
67559 +__u32 to_gr_audit(const __u32 reqmode);
67560 +int gr_set_acls(const int type);
67561 +int gr_apply_subject_to_task(struct task_struct *task);
67562 +int gr_acl_is_enabled(void);
67563 +char gr_roletype_to_char(void);
67564 +
67565 +void gr_handle_alertkill(struct task_struct *task);
67566 +char *gr_to_filename(const struct dentry *dentry,
67567 + const struct vfsmount *mnt);
67568 +char *gr_to_filename1(const struct dentry *dentry,
67569 + const struct vfsmount *mnt);
67570 +char *gr_to_filename2(const struct dentry *dentry,
67571 + const struct vfsmount *mnt);
67572 +char *gr_to_filename3(const struct dentry *dentry,
67573 + const struct vfsmount *mnt);
67574 +
67575 +extern int grsec_enable_ptrace_readexec;
67576 +extern int grsec_enable_harden_ptrace;
67577 +extern int grsec_enable_link;
67578 +extern int grsec_enable_fifo;
67579 +extern int grsec_enable_execve;
67580 +extern int grsec_enable_shm;
67581 +extern int grsec_enable_execlog;
67582 +extern int grsec_enable_signal;
67583 +extern int grsec_enable_audit_ptrace;
67584 +extern int grsec_enable_forkfail;
67585 +extern int grsec_enable_time;
67586 +extern int grsec_enable_rofs;
67587 +extern int grsec_enable_chroot_shmat;
67588 +extern int grsec_enable_chroot_mount;
67589 +extern int grsec_enable_chroot_double;
67590 +extern int grsec_enable_chroot_pivot;
67591 +extern int grsec_enable_chroot_chdir;
67592 +extern int grsec_enable_chroot_chmod;
67593 +extern int grsec_enable_chroot_mknod;
67594 +extern int grsec_enable_chroot_fchdir;
67595 +extern int grsec_enable_chroot_nice;
67596 +extern int grsec_enable_chroot_execlog;
67597 +extern int grsec_enable_chroot_caps;
67598 +extern int grsec_enable_chroot_sysctl;
67599 +extern int grsec_enable_chroot_unix;
67600 +extern int grsec_enable_symlinkown;
67601 +extern kgid_t grsec_symlinkown_gid;
67602 +extern int grsec_enable_tpe;
67603 +extern kgid_t grsec_tpe_gid;
67604 +extern int grsec_enable_tpe_all;
67605 +extern int grsec_enable_tpe_invert;
67606 +extern int grsec_enable_socket_all;
67607 +extern kgid_t grsec_socket_all_gid;
67608 +extern int grsec_enable_socket_client;
67609 +extern kgid_t grsec_socket_client_gid;
67610 +extern int grsec_enable_socket_server;
67611 +extern kgid_t grsec_socket_server_gid;
67612 +extern kgid_t grsec_audit_gid;
67613 +extern int grsec_enable_group;
67614 +extern int grsec_enable_audit_textrel;
67615 +extern int grsec_enable_log_rwxmaps;
67616 +extern int grsec_enable_mount;
67617 +extern int grsec_enable_chdir;
67618 +extern int grsec_resource_logging;
67619 +extern int grsec_enable_blackhole;
67620 +extern int grsec_lastack_retries;
67621 +extern int grsec_enable_brute;
67622 +extern int grsec_lock;
67623 +
67624 +extern spinlock_t grsec_alert_lock;
67625 +extern unsigned long grsec_alert_wtime;
67626 +extern unsigned long grsec_alert_fyet;
67627 +
67628 +extern spinlock_t grsec_audit_lock;
67629 +
67630 +extern rwlock_t grsec_exec_file_lock;
67631 +
67632 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
67633 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
67634 + (tsk)->exec_file->f_vfsmnt) : "/")
67635 +
67636 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
67637 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
67638 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
67639 +
67640 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
67641 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
67642 + (tsk)->exec_file->f_vfsmnt) : "/")
67643 +
67644 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
67645 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
67646 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
67647 +
67648 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
67649 +
67650 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
67651 +
67652 +#define GR_CHROOT_CAPS {{ \
67653 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
67654 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
67655 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
67656 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
67657 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
67658 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
67659 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
67660 +
67661 +#define security_learn(normal_msg,args...) \
67662 +({ \
67663 + read_lock(&grsec_exec_file_lock); \
67664 + gr_add_learn_entry(normal_msg "\n", ## args); \
67665 + read_unlock(&grsec_exec_file_lock); \
67666 +})
67667 +
67668 +enum {
67669 + GR_DO_AUDIT,
67670 + GR_DONT_AUDIT,
67671 + /* used for non-audit messages that we shouldn't kill the task on */
67672 + GR_DONT_AUDIT_GOOD
67673 +};
67674 +
67675 +enum {
67676 + GR_TTYSNIFF,
67677 + GR_RBAC,
67678 + GR_RBAC_STR,
67679 + GR_STR_RBAC,
67680 + GR_RBAC_MODE2,
67681 + GR_RBAC_MODE3,
67682 + GR_FILENAME,
67683 + GR_SYSCTL_HIDDEN,
67684 + GR_NOARGS,
67685 + GR_ONE_INT,
67686 + GR_ONE_INT_TWO_STR,
67687 + GR_ONE_STR,
67688 + GR_STR_INT,
67689 + GR_TWO_STR_INT,
67690 + GR_TWO_INT,
67691 + GR_TWO_U64,
67692 + GR_THREE_INT,
67693 + GR_FIVE_INT_TWO_STR,
67694 + GR_TWO_STR,
67695 + GR_THREE_STR,
67696 + GR_FOUR_STR,
67697 + GR_STR_FILENAME,
67698 + GR_FILENAME_STR,
67699 + GR_FILENAME_TWO_INT,
67700 + GR_FILENAME_TWO_INT_STR,
67701 + GR_TEXTREL,
67702 + GR_PTRACE,
67703 + GR_RESOURCE,
67704 + GR_CAP,
67705 + GR_SIG,
67706 + GR_SIG2,
67707 + GR_CRASH1,
67708 + GR_CRASH2,
67709 + GR_PSACCT,
67710 + GR_RWXMAP
67711 +};
67712 +
67713 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
67714 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
67715 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
67716 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
67717 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
67718 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
67719 +#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)
67720 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
67721 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
67722 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
67723 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
67724 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
67725 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
67726 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
67727 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
67728 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
67729 +#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)
67730 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
67731 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
67732 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
67733 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
67734 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
67735 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
67736 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
67737 +#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)
67738 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
67739 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
67740 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
67741 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
67742 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
67743 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
67744 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
67745 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
67746 +#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)
67747 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
67748 +
67749 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
67750 +
67751 +#endif
67752 +
67753 +#endif
67754 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
67755 new file mode 100644
67756 index 0000000..2bd4c8d
67757 --- /dev/null
67758 +++ b/include/linux/grmsg.h
67759 @@ -0,0 +1,111 @@
67760 +#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"
67761 +#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"
67762 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
67763 +#define GR_STOPMOD_MSG "denied modification of module state by "
67764 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
67765 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
67766 +#define GR_IOPERM_MSG "denied use of ioperm() by "
67767 +#define GR_IOPL_MSG "denied use of iopl() by "
67768 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
67769 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
67770 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
67771 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
67772 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
67773 +#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"
67774 +#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"
67775 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
67776 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
67777 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
67778 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
67779 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
67780 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
67781 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
67782 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
67783 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
67784 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
67785 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
67786 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
67787 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
67788 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
67789 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
67790 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
67791 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
67792 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
67793 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
67794 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
67795 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
67796 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
67797 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
67798 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
67799 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
67800 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
67801 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
67802 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
67803 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
67804 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
67805 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
67806 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
67807 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
67808 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
67809 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
67810 +#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"
67811 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
67812 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
67813 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
67814 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
67815 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
67816 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
67817 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
67818 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
67819 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
67820 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
67821 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
67822 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
67823 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
67824 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
67825 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
67826 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
67827 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
67828 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
67829 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
67830 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
67831 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
67832 +#define GR_NICE_CHROOT_MSG "denied priority change by "
67833 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
67834 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
67835 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
67836 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
67837 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
67838 +#define GR_TIME_MSG "time set by "
67839 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
67840 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
67841 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
67842 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
67843 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
67844 +#define GR_BIND_MSG "denied bind() by "
67845 +#define GR_CONNECT_MSG "denied connect() by "
67846 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
67847 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
67848 +#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"
67849 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
67850 +#define GR_CAP_ACL_MSG "use of %s denied for "
67851 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
67852 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
67853 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
67854 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
67855 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
67856 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
67857 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
67858 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
67859 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
67860 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
67861 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
67862 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
67863 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
67864 +#define GR_VM86_MSG "denied use of vm86 by "
67865 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
67866 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
67867 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
67868 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
67869 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
67870 +#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 "
67871 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
67872 new file mode 100644
67873 index 0000000..1ae241a
67874 --- /dev/null
67875 +++ b/include/linux/grsecurity.h
67876 @@ -0,0 +1,257 @@
67877 +#ifndef GR_SECURITY_H
67878 +#define GR_SECURITY_H
67879 +#include <linux/fs.h>
67880 +#include <linux/fs_struct.h>
67881 +#include <linux/binfmts.h>
67882 +#include <linux/gracl.h>
67883 +
67884 +/* notify of brain-dead configs */
67885 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67886 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
67887 +#endif
67888 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
67889 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
67890 +#endif
67891 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
67892 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
67893 +#endif
67894 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
67895 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
67896 +#endif
67897 +
67898 +#include <linux/compat.h>
67899 +
67900 +struct user_arg_ptr {
67901 +#ifdef CONFIG_COMPAT
67902 + bool is_compat;
67903 +#endif
67904 + union {
67905 + const char __user *const __user *native;
67906 +#ifdef CONFIG_COMPAT
67907 + const compat_uptr_t __user *compat;
67908 +#endif
67909 + } ptr;
67910 +};
67911 +
67912 +void gr_handle_brute_attach(unsigned long mm_flags);
67913 +void gr_handle_brute_check(void);
67914 +void gr_handle_kernel_exploit(void);
67915 +int gr_process_user_ban(void);
67916 +
67917 +char gr_roletype_to_char(void);
67918 +
67919 +int gr_acl_enable_at_secure(void);
67920 +
67921 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
67922 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
67923 +
67924 +void gr_del_task_from_ip_table(struct task_struct *p);
67925 +
67926 +int gr_pid_is_chrooted(struct task_struct *p);
67927 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
67928 +int gr_handle_chroot_nice(void);
67929 +int gr_handle_chroot_sysctl(const int op);
67930 +int gr_handle_chroot_setpriority(struct task_struct *p,
67931 + const int niceval);
67932 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
67933 +int gr_handle_chroot_chroot(const struct dentry *dentry,
67934 + const struct vfsmount *mnt);
67935 +void gr_handle_chroot_chdir(struct path *path);
67936 +int gr_handle_chroot_chmod(const struct dentry *dentry,
67937 + const struct vfsmount *mnt, const int mode);
67938 +int gr_handle_chroot_mknod(const struct dentry *dentry,
67939 + const struct vfsmount *mnt, const int mode);
67940 +int gr_handle_chroot_mount(const struct dentry *dentry,
67941 + const struct vfsmount *mnt,
67942 + const char *dev_name);
67943 +int gr_handle_chroot_pivot(void);
67944 +int gr_handle_chroot_unix(const pid_t pid);
67945 +
67946 +int gr_handle_rawio(const struct inode *inode);
67947 +
67948 +void gr_handle_ioperm(void);
67949 +void gr_handle_iopl(void);
67950 +
67951 +umode_t gr_acl_umask(void);
67952 +
67953 +int gr_tpe_allow(const struct file *file);
67954 +
67955 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
67956 +void gr_clear_chroot_entries(struct task_struct *task);
67957 +
67958 +void gr_log_forkfail(const int retval);
67959 +void gr_log_timechange(void);
67960 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
67961 +void gr_log_chdir(const struct dentry *dentry,
67962 + const struct vfsmount *mnt);
67963 +void gr_log_chroot_exec(const struct dentry *dentry,
67964 + const struct vfsmount *mnt);
67965 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
67966 +void gr_log_remount(const char *devname, const int retval);
67967 +void gr_log_unmount(const char *devname, const int retval);
67968 +void gr_log_mount(const char *from, const char *to, const int retval);
67969 +void gr_log_textrel(struct vm_area_struct *vma);
67970 +void gr_log_rwxmmap(struct file *file);
67971 +void gr_log_rwxmprotect(struct file *file);
67972 +
67973 +int gr_handle_follow_link(const struct inode *parent,
67974 + const struct inode *inode,
67975 + const struct dentry *dentry,
67976 + const struct vfsmount *mnt);
67977 +int gr_handle_fifo(const struct dentry *dentry,
67978 + const struct vfsmount *mnt,
67979 + const struct dentry *dir, const int flag,
67980 + const int acc_mode);
67981 +int gr_handle_hardlink(const struct dentry *dentry,
67982 + const struct vfsmount *mnt,
67983 + struct inode *inode,
67984 + const int mode, const struct filename *to);
67985 +
67986 +int gr_is_capable(const int cap);
67987 +int gr_is_capable_nolog(const int cap);
67988 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
67989 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
67990 +
67991 +void gr_copy_label(struct task_struct *tsk);
67992 +void gr_handle_crash(struct task_struct *task, const int sig);
67993 +int gr_handle_signal(const struct task_struct *p, const int sig);
67994 +int gr_check_crash_uid(const kuid_t uid);
67995 +int gr_check_protected_task(const struct task_struct *task);
67996 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
67997 +int gr_acl_handle_mmap(const struct file *file,
67998 + const unsigned long prot);
67999 +int gr_acl_handle_mprotect(const struct file *file,
68000 + const unsigned long prot);
68001 +int gr_check_hidden_task(const struct task_struct *tsk);
68002 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
68003 + const struct vfsmount *mnt);
68004 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
68005 + const struct vfsmount *mnt);
68006 +__u32 gr_acl_handle_access(const struct dentry *dentry,
68007 + const struct vfsmount *mnt, const int fmode);
68008 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
68009 + const struct vfsmount *mnt, umode_t *mode);
68010 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
68011 + const struct vfsmount *mnt);
68012 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
68013 + const struct vfsmount *mnt);
68014 +int gr_handle_ptrace(struct task_struct *task, const long request);
68015 +int gr_handle_proc_ptrace(struct task_struct *task);
68016 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
68017 + const struct vfsmount *mnt);
68018 +int gr_check_crash_exec(const struct file *filp);
68019 +int gr_acl_is_enabled(void);
68020 +void gr_set_kernel_label(struct task_struct *task);
68021 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
68022 + const kgid_t gid);
68023 +int gr_set_proc_label(const struct dentry *dentry,
68024 + const struct vfsmount *mnt,
68025 + const int unsafe_flags);
68026 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
68027 + const struct vfsmount *mnt);
68028 +__u32 gr_acl_handle_open(const struct dentry *dentry,
68029 + const struct vfsmount *mnt, int acc_mode);
68030 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
68031 + const struct dentry *p_dentry,
68032 + const struct vfsmount *p_mnt,
68033 + int open_flags, int acc_mode, const int imode);
68034 +void gr_handle_create(const struct dentry *dentry,
68035 + const struct vfsmount *mnt);
68036 +void gr_handle_proc_create(const struct dentry *dentry,
68037 + const struct inode *inode);
68038 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
68039 + const struct dentry *parent_dentry,
68040 + const struct vfsmount *parent_mnt,
68041 + const int mode);
68042 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
68043 + const struct dentry *parent_dentry,
68044 + const struct vfsmount *parent_mnt);
68045 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
68046 + const struct vfsmount *mnt);
68047 +void gr_handle_delete(const ino_t ino, const dev_t dev);
68048 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
68049 + const struct vfsmount *mnt);
68050 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
68051 + const struct dentry *parent_dentry,
68052 + const struct vfsmount *parent_mnt,
68053 + const struct filename *from);
68054 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
68055 + const struct dentry *parent_dentry,
68056 + const struct vfsmount *parent_mnt,
68057 + const struct dentry *old_dentry,
68058 + const struct vfsmount *old_mnt, const struct filename *to);
68059 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
68060 +int gr_acl_handle_rename(struct dentry *new_dentry,
68061 + struct dentry *parent_dentry,
68062 + const struct vfsmount *parent_mnt,
68063 + struct dentry *old_dentry,
68064 + struct inode *old_parent_inode,
68065 + struct vfsmount *old_mnt, const struct filename *newname);
68066 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68067 + struct dentry *old_dentry,
68068 + struct dentry *new_dentry,
68069 + struct vfsmount *mnt, const __u8 replace);
68070 +__u32 gr_check_link(const struct dentry *new_dentry,
68071 + const struct dentry *parent_dentry,
68072 + const struct vfsmount *parent_mnt,
68073 + const struct dentry *old_dentry,
68074 + const struct vfsmount *old_mnt);
68075 +int gr_acl_handle_filldir(const struct file *file, const char *name,
68076 + const unsigned int namelen, const ino_t ino);
68077 +
68078 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
68079 + const struct vfsmount *mnt);
68080 +void gr_acl_handle_exit(void);
68081 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
68082 +int gr_acl_handle_procpidmem(const struct task_struct *task);
68083 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
68084 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
68085 +void gr_audit_ptrace(struct task_struct *task);
68086 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
68087 +void gr_put_exec_file(struct task_struct *task);
68088 +
68089 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
68090 +
68091 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
68092 +extern void gr_learn_resource(const struct task_struct *task, const int res,
68093 + const unsigned long wanted, const int gt);
68094 +#else
68095 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
68096 + const unsigned long wanted, const int gt)
68097 +{
68098 +}
68099 +#endif
68100 +
68101 +#ifdef CONFIG_GRKERNSEC_RESLOG
68102 +extern void gr_log_resource(const struct task_struct *task, const int res,
68103 + const unsigned long wanted, const int gt);
68104 +#else
68105 +static inline void gr_log_resource(const struct task_struct *task, const int res,
68106 + const unsigned long wanted, const int gt)
68107 +{
68108 +}
68109 +#endif
68110 +
68111 +#ifdef CONFIG_GRKERNSEC
68112 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
68113 +void gr_handle_vm86(void);
68114 +void gr_handle_mem_readwrite(u64 from, u64 to);
68115 +
68116 +void gr_log_badprocpid(const char *entry);
68117 +
68118 +extern int grsec_enable_dmesg;
68119 +extern int grsec_disable_privio;
68120 +
68121 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68122 +extern kgid_t grsec_proc_gid;
68123 +#endif
68124 +
68125 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68126 +extern int grsec_enable_chroot_findtask;
68127 +#endif
68128 +#ifdef CONFIG_GRKERNSEC_SETXID
68129 +extern int grsec_enable_setxid;
68130 +#endif
68131 +#endif
68132 +
68133 +#endif
68134 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
68135 new file mode 100644
68136 index 0000000..e7ffaaf
68137 --- /dev/null
68138 +++ b/include/linux/grsock.h
68139 @@ -0,0 +1,19 @@
68140 +#ifndef __GRSOCK_H
68141 +#define __GRSOCK_H
68142 +
68143 +extern void gr_attach_curr_ip(const struct sock *sk);
68144 +extern int gr_handle_sock_all(const int family, const int type,
68145 + const int protocol);
68146 +extern int gr_handle_sock_server(const struct sockaddr *sck);
68147 +extern int gr_handle_sock_server_other(const struct sock *sck);
68148 +extern int gr_handle_sock_client(const struct sockaddr *sck);
68149 +extern int gr_search_connect(struct socket * sock,
68150 + struct sockaddr_in * addr);
68151 +extern int gr_search_bind(struct socket * sock,
68152 + struct sockaddr_in * addr);
68153 +extern int gr_search_listen(struct socket * sock);
68154 +extern int gr_search_accept(struct socket * sock);
68155 +extern int gr_search_socket(const int domain, const int type,
68156 + const int protocol);
68157 +
68158 +#endif
68159 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
68160 index ef788b5..ac41b7b 100644
68161 --- a/include/linux/highmem.h
68162 +++ b/include/linux/highmem.h
68163 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
68164 kunmap_atomic(kaddr);
68165 }
68166
68167 +static inline void sanitize_highpage(struct page *page)
68168 +{
68169 + void *kaddr;
68170 + unsigned long flags;
68171 +
68172 + local_irq_save(flags);
68173 + kaddr = kmap_atomic(page);
68174 + clear_page(kaddr);
68175 + kunmap_atomic(kaddr);
68176 + local_irq_restore(flags);
68177 +}
68178 +
68179 static inline void zero_user_segments(struct page *page,
68180 unsigned start1, unsigned end1,
68181 unsigned start2, unsigned end2)
68182 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
68183 index 1c7b89a..7f52502 100644
68184 --- a/include/linux/hwmon-sysfs.h
68185 +++ b/include/linux/hwmon-sysfs.h
68186 @@ -25,7 +25,8 @@
68187 struct sensor_device_attribute{
68188 struct device_attribute dev_attr;
68189 int index;
68190 -};
68191 +} __do_const;
68192 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
68193 #define to_sensor_dev_attr(_dev_attr) \
68194 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
68195
68196 @@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
68197 struct device_attribute dev_attr;
68198 u8 index;
68199 u8 nr;
68200 -};
68201 +} __do_const;
68202 #define to_sensor_dev_attr_2(_dev_attr) \
68203 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
68204
68205 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
68206 index d0c4db7..61b3577 100644
68207 --- a/include/linux/i2c.h
68208 +++ b/include/linux/i2c.h
68209 @@ -369,6 +369,7 @@ struct i2c_algorithm {
68210 /* To determine what the adapter supports */
68211 u32 (*functionality) (struct i2c_adapter *);
68212 };
68213 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
68214
68215 /*
68216 * i2c_adapter is the structure used to identify a physical i2c bus along
68217 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
68218 index d23c3c2..eb63c81 100644
68219 --- a/include/linux/i2o.h
68220 +++ b/include/linux/i2o.h
68221 @@ -565,7 +565,7 @@ struct i2o_controller {
68222 struct i2o_device *exec; /* Executive */
68223 #if BITS_PER_LONG == 64
68224 spinlock_t context_list_lock; /* lock for context_list */
68225 - atomic_t context_list_counter; /* needed for unique contexts */
68226 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
68227 struct list_head context_list; /* list of context id's
68228 and pointers */
68229 #endif
68230 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
68231 index aff7ad8..3942bbd 100644
68232 --- a/include/linux/if_pppox.h
68233 +++ b/include/linux/if_pppox.h
68234 @@ -76,7 +76,7 @@ struct pppox_proto {
68235 int (*ioctl)(struct socket *sock, unsigned int cmd,
68236 unsigned long arg);
68237 struct module *owner;
68238 -};
68239 +} __do_const;
68240
68241 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
68242 extern void unregister_pppox_proto(int proto_num);
68243 diff --git a/include/linux/init.h b/include/linux/init.h
68244 index 10ed4f4..8e8490d 100644
68245 --- a/include/linux/init.h
68246 +++ b/include/linux/init.h
68247 @@ -39,9 +39,36 @@
68248 * Also note, that this data cannot be "const".
68249 */
68250
68251 +#ifdef MODULE
68252 +#define add_init_latent_entropy
68253 +#define add_devinit_latent_entropy
68254 +#define add_cpuinit_latent_entropy
68255 +#define add_meminit_latent_entropy
68256 +#else
68257 +#define add_init_latent_entropy __latent_entropy
68258 +
68259 +#ifdef CONFIG_HOTPLUG
68260 +#define add_devinit_latent_entropy
68261 +#else
68262 +#define add_devinit_latent_entropy __latent_entropy
68263 +#endif
68264 +
68265 +#ifdef CONFIG_HOTPLUG_CPU
68266 +#define add_cpuinit_latent_entropy
68267 +#else
68268 +#define add_cpuinit_latent_entropy __latent_entropy
68269 +#endif
68270 +
68271 +#ifdef CONFIG_MEMORY_HOTPLUG
68272 +#define add_meminit_latent_entropy
68273 +#else
68274 +#define add_meminit_latent_entropy __latent_entropy
68275 +#endif
68276 +#endif
68277 +
68278 /* These are for everybody (although not all archs will actually
68279 discard it in modules) */
68280 -#define __init __section(.init.text) __cold notrace
68281 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
68282 #define __initdata __section(.init.data)
68283 #define __initconst __constsection(.init.rodata)
68284 #define __exitdata __section(.exit.data)
68285 @@ -94,7 +121,7 @@
68286 #define __exit __section(.exit.text) __exitused __cold notrace
68287
68288 /* Used for HOTPLUG_CPU */
68289 -#define __cpuinit __section(.cpuinit.text) __cold notrace
68290 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
68291 #define __cpuinitdata __section(.cpuinit.data)
68292 #define __cpuinitconst __constsection(.cpuinit.rodata)
68293 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
68294 @@ -102,7 +129,7 @@
68295 #define __cpuexitconst __constsection(.cpuexit.rodata)
68296
68297 /* Used for MEMORY_HOTPLUG */
68298 -#define __meminit __section(.meminit.text) __cold notrace
68299 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
68300 #define __meminitdata __section(.meminit.data)
68301 #define __meminitconst __constsection(.meminit.rodata)
68302 #define __memexit __section(.memexit.text) __exitused __cold notrace
68303 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
68304 index 6d087c5..401cab8 100644
68305 --- a/include/linux/init_task.h
68306 +++ b/include/linux/init_task.h
68307 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
68308
68309 #define INIT_TASK_COMM "swapper"
68310
68311 +#ifdef CONFIG_X86
68312 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
68313 +#else
68314 +#define INIT_TASK_THREAD_INFO
68315 +#endif
68316 +
68317 /*
68318 * INIT_TASK is used to set up the first task table, touch at
68319 * your own risk!. Base=0, limit=0x1fffff (=2MB)
68320 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
68321 RCU_POINTER_INITIALIZER(cred, &init_cred), \
68322 .comm = INIT_TASK_COMM, \
68323 .thread = INIT_THREAD, \
68324 + INIT_TASK_THREAD_INFO \
68325 .fs = &init_fs, \
68326 .files = &init_files, \
68327 .signal = &init_signals, \
68328 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
68329 index 5fa5afe..ac55b25 100644
68330 --- a/include/linux/interrupt.h
68331 +++ b/include/linux/interrupt.h
68332 @@ -430,7 +430,7 @@ enum
68333 /* map softirq index to softirq name. update 'softirq_to_name' in
68334 * kernel/softirq.c when adding a new softirq.
68335 */
68336 -extern char *softirq_to_name[NR_SOFTIRQS];
68337 +extern const char * const softirq_to_name[NR_SOFTIRQS];
68338
68339 /* softirq mask and active fields moved to irq_cpustat_t in
68340 * asm/hardirq.h to get better cache usage. KAO
68341 @@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
68342
68343 struct softirq_action
68344 {
68345 - void (*action)(struct softirq_action *);
68346 -};
68347 + void (*action)(void);
68348 +} __no_const;
68349
68350 asmlinkage void do_softirq(void);
68351 asmlinkage void __do_softirq(void);
68352 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
68353 +extern void open_softirq(int nr, void (*action)(void));
68354 extern void softirq_init(void);
68355 extern void __raise_softirq_irqoff(unsigned int nr);
68356
68357 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
68358 index f3b99e1..9b73cee 100644
68359 --- a/include/linux/iommu.h
68360 +++ b/include/linux/iommu.h
68361 @@ -101,7 +101,7 @@ struct iommu_ops {
68362 int (*domain_set_attr)(struct iommu_domain *domain,
68363 enum iommu_attr attr, void *data);
68364 unsigned long pgsize_bitmap;
68365 -};
68366 +} __do_const;
68367
68368 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
68369 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
68370 diff --git a/include/linux/irq.h b/include/linux/irq.h
68371 index fdf2c4a..5332486 100644
68372 --- a/include/linux/irq.h
68373 +++ b/include/linux/irq.h
68374 @@ -328,7 +328,8 @@ struct irq_chip {
68375 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
68376
68377 unsigned long flags;
68378 -};
68379 +} __do_const;
68380 +typedef struct irq_chip __no_const irq_chip_no_const;
68381
68382 /*
68383 * irq_chip specific flags
68384 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
68385 index 6883e19..06992b1 100644
68386 --- a/include/linux/kallsyms.h
68387 +++ b/include/linux/kallsyms.h
68388 @@ -15,7 +15,8 @@
68389
68390 struct module;
68391
68392 -#ifdef CONFIG_KALLSYMS
68393 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
68394 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68395 /* Lookup the address for a symbol. Returns 0 if not found. */
68396 unsigned long kallsyms_lookup_name(const char *name);
68397
68398 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
68399 /* Stupid that this does nothing, but I didn't create this mess. */
68400 #define __print_symbol(fmt, addr)
68401 #endif /*CONFIG_KALLSYMS*/
68402 +#else /* when included by kallsyms.c, vsnprintf.c, or
68403 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
68404 +extern void __print_symbol(const char *fmt, unsigned long address);
68405 +extern int sprint_backtrace(char *buffer, unsigned long address);
68406 +extern int sprint_symbol(char *buffer, unsigned long address);
68407 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
68408 +const char *kallsyms_lookup(unsigned long addr,
68409 + unsigned long *symbolsize,
68410 + unsigned long *offset,
68411 + char **modname, char *namebuf);
68412 +#endif
68413
68414 /* This macro allows us to keep printk typechecking */
68415 static __printf(1, 2)
68416 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
68417 index 518a53a..5e28358 100644
68418 --- a/include/linux/key-type.h
68419 +++ b/include/linux/key-type.h
68420 @@ -125,7 +125,7 @@ struct key_type {
68421 /* internal fields */
68422 struct list_head link; /* link in types list */
68423 struct lock_class_key lock_class; /* key->sem lock class */
68424 -};
68425 +} __do_const;
68426
68427 extern struct key_type key_type_keyring;
68428
68429 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
68430 index 4dff0c6..1ca9b72 100644
68431 --- a/include/linux/kgdb.h
68432 +++ b/include/linux/kgdb.h
68433 @@ -53,7 +53,7 @@ extern int kgdb_connected;
68434 extern int kgdb_io_module_registered;
68435
68436 extern atomic_t kgdb_setting_breakpoint;
68437 -extern atomic_t kgdb_cpu_doing_single_step;
68438 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
68439
68440 extern struct task_struct *kgdb_usethread;
68441 extern struct task_struct *kgdb_contthread;
68442 @@ -255,7 +255,7 @@ struct kgdb_arch {
68443 void (*correct_hw_break)(void);
68444
68445 void (*enable_nmi)(bool on);
68446 -};
68447 +} __do_const;
68448
68449 /**
68450 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
68451 @@ -280,7 +280,7 @@ struct kgdb_io {
68452 void (*pre_exception) (void);
68453 void (*post_exception) (void);
68454 int is_console;
68455 -};
68456 +} __do_const;
68457
68458 extern struct kgdb_arch arch_kgdb_ops;
68459
68460 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
68461 index 5398d58..5883a34 100644
68462 --- a/include/linux/kmod.h
68463 +++ b/include/linux/kmod.h
68464 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
68465 * usually useless though. */
68466 extern __printf(2, 3)
68467 int __request_module(bool wait, const char *name, ...);
68468 +extern __printf(3, 4)
68469 +int ___request_module(bool wait, char *param_name, const char *name, ...);
68470 #define request_module(mod...) __request_module(true, mod)
68471 #define request_module_nowait(mod...) __request_module(false, mod)
68472 #define try_then_request_module(x, mod...) \
68473 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
68474 index 939b112..ed6ed51 100644
68475 --- a/include/linux/kobject.h
68476 +++ b/include/linux/kobject.h
68477 @@ -111,7 +111,7 @@ struct kobj_type {
68478 struct attribute **default_attrs;
68479 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
68480 const void *(*namespace)(struct kobject *kobj);
68481 -};
68482 +} __do_const;
68483
68484 struct kobj_uevent_env {
68485 char *envp[UEVENT_NUM_ENVP];
68486 @@ -134,6 +134,7 @@ struct kobj_attribute {
68487 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
68488 const char *buf, size_t count);
68489 };
68490 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
68491
68492 extern const struct sysfs_ops kobj_sysfs_ops;
68493
68494 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
68495 index f66b065..c2c29b4 100644
68496 --- a/include/linux/kobject_ns.h
68497 +++ b/include/linux/kobject_ns.h
68498 @@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
68499 const void *(*netlink_ns)(struct sock *sk);
68500 const void *(*initial_ns)(void);
68501 void (*drop_ns)(void *);
68502 -};
68503 +} __do_const;
68504
68505 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
68506 int kobj_ns_type_registered(enum kobj_ns_type type);
68507 diff --git a/include/linux/kref.h b/include/linux/kref.h
68508 index 4972e6e..de4d19b 100644
68509 --- a/include/linux/kref.h
68510 +++ b/include/linux/kref.h
68511 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
68512 static inline int kref_sub(struct kref *kref, unsigned int count,
68513 void (*release)(struct kref *kref))
68514 {
68515 - WARN_ON(release == NULL);
68516 + BUG_ON(release == NULL);
68517
68518 if (atomic_sub_and_test((int) count, &kref->refcount)) {
68519 release(kref);
68520 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
68521 index 2c497ab..afe32f5 100644
68522 --- a/include/linux/kvm_host.h
68523 +++ b/include/linux/kvm_host.h
68524 @@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
68525 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
68526 void vcpu_put(struct kvm_vcpu *vcpu);
68527
68528 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
68529 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
68530 struct module *module);
68531 void kvm_exit(void);
68532
68533 @@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
68534 struct kvm_guest_debug *dbg);
68535 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
68536
68537 -int kvm_arch_init(void *opaque);
68538 +int kvm_arch_init(const void *opaque);
68539 void kvm_arch_exit(void);
68540
68541 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
68542 diff --git a/include/linux/libata.h b/include/linux/libata.h
68543 index 649e5f8..ead5194 100644
68544 --- a/include/linux/libata.h
68545 +++ b/include/linux/libata.h
68546 @@ -915,7 +915,7 @@ struct ata_port_operations {
68547 * fields must be pointers.
68548 */
68549 const struct ata_port_operations *inherits;
68550 -};
68551 +} __do_const;
68552
68553 struct ata_port_info {
68554 unsigned long flags;
68555 diff --git a/include/linux/list.h b/include/linux/list.h
68556 index cc6d2aa..c10ee83 100644
68557 --- a/include/linux/list.h
68558 +++ b/include/linux/list.h
68559 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
68560 extern void list_del(struct list_head *entry);
68561 #endif
68562
68563 +extern void __pax_list_add(struct list_head *new,
68564 + struct list_head *prev,
68565 + struct list_head *next);
68566 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
68567 +{
68568 + __pax_list_add(new, head, head->next);
68569 +}
68570 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
68571 +{
68572 + __pax_list_add(new, head->prev, head);
68573 +}
68574 +extern void pax_list_del(struct list_head *entry);
68575 +
68576 /**
68577 * list_replace - replace old entry by new one
68578 * @old : the element to be replaced
68579 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
68580 INIT_LIST_HEAD(entry);
68581 }
68582
68583 +extern void pax_list_del_init(struct list_head *entry);
68584 +
68585 /**
68586 * list_move - delete from one list and add as another's head
68587 * @list: the entry to move
68588 diff --git a/include/linux/mm.h b/include/linux/mm.h
68589 index 66e2f7c..ea88001 100644
68590 --- a/include/linux/mm.h
68591 +++ b/include/linux/mm.h
68592 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
68593 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
68594 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
68595 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
68596 +
68597 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68598 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
68599 +#endif
68600 +
68601 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
68602
68603 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
68604 @@ -231,6 +236,7 @@ struct vm_operations_struct {
68605 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
68606 unsigned long size, pgoff_t pgoff);
68607 };
68608 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
68609
68610 struct mmu_gather;
68611 struct inode;
68612 @@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
68613 int set_page_dirty_lock(struct page *page);
68614 int clear_page_dirty_for_io(struct page *page);
68615
68616 -/* Is the vma a continuation of the stack vma above it? */
68617 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
68618 -{
68619 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
68620 -}
68621 -
68622 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
68623 - unsigned long addr)
68624 -{
68625 - return (vma->vm_flags & VM_GROWSDOWN) &&
68626 - (vma->vm_start == addr) &&
68627 - !vma_growsdown(vma->vm_prev, addr);
68628 -}
68629 -
68630 -/* Is the vma a continuation of the stack vma below it? */
68631 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
68632 -{
68633 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
68634 -}
68635 -
68636 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
68637 - unsigned long addr)
68638 -{
68639 - return (vma->vm_flags & VM_GROWSUP) &&
68640 - (vma->vm_end == addr) &&
68641 - !vma_growsup(vma->vm_next, addr);
68642 -}
68643 -
68644 extern pid_t
68645 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
68646
68647 @@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
68648 }
68649 #endif
68650
68651 +#ifdef CONFIG_MMU
68652 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
68653 +#else
68654 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
68655 +{
68656 + return __pgprot(0);
68657 +}
68658 +#endif
68659 +
68660 int vma_wants_writenotify(struct vm_area_struct *vma);
68661
68662 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
68663 @@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
68664 {
68665 return 0;
68666 }
68667 +
68668 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
68669 + unsigned long address)
68670 +{
68671 + return 0;
68672 +}
68673 #else
68674 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
68675 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
68676 #endif
68677
68678 #ifdef __PAGETABLE_PMD_FOLDED
68679 @@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
68680 {
68681 return 0;
68682 }
68683 +
68684 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
68685 + unsigned long address)
68686 +{
68687 + return 0;
68688 +}
68689 #else
68690 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
68691 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
68692 #endif
68693
68694 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
68695 @@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
68696 NULL: pud_offset(pgd, address);
68697 }
68698
68699 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
68700 +{
68701 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
68702 + NULL: pud_offset(pgd, address);
68703 +}
68704 +
68705 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
68706 {
68707 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
68708 NULL: pmd_offset(pud, address);
68709 }
68710 +
68711 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
68712 +{
68713 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
68714 + NULL: pmd_offset(pud, address);
68715 +}
68716 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
68717
68718 #if USE_SPLIT_PTLOCKS
68719 @@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
68720 unsigned long, unsigned long,
68721 unsigned long, unsigned long);
68722 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
68723 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
68724
68725 /* These take the mm semaphore themselves */
68726 extern unsigned long vm_brk(unsigned long, unsigned long);
68727 @@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
68728 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
68729 struct vm_area_struct **pprev);
68730
68731 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
68732 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
68733 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
68734 +
68735 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
68736 NULL if none. Assume start_addr < end_addr. */
68737 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
68738 @@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
68739 return vma;
68740 }
68741
68742 -#ifdef CONFIG_MMU
68743 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
68744 -#else
68745 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
68746 -{
68747 - return __pgprot(0);
68748 -}
68749 -#endif
68750 -
68751 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
68752 unsigned long change_prot_numa(struct vm_area_struct *vma,
68753 unsigned long start, unsigned long end);
68754 @@ -1721,7 +1730,7 @@ extern int unpoison_memory(unsigned long pfn);
68755 extern int sysctl_memory_failure_early_kill;
68756 extern int sysctl_memory_failure_recovery;
68757 extern void shake_page(struct page *p, int access);
68758 -extern atomic_long_t mce_bad_pages;
68759 +extern atomic_long_unchecked_t mce_bad_pages;
68760 extern int soft_offline_page(struct page *page, int flags);
68761
68762 extern void dump_page(struct page *page);
68763 @@ -1752,5 +1761,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
68764 static inline bool page_is_guard(struct page *page) { return false; }
68765 #endif /* CONFIG_DEBUG_PAGEALLOC */
68766
68767 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
68768 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
68769 +#else
68770 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
68771 +#endif
68772 +
68773 #endif /* __KERNEL__ */
68774 #endif /* _LINUX_MM_H */
68775 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
68776 index f8f5162..a039af9 100644
68777 --- a/include/linux/mm_types.h
68778 +++ b/include/linux/mm_types.h
68779 @@ -288,6 +288,8 @@ struct vm_area_struct {
68780 #ifdef CONFIG_NUMA
68781 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
68782 #endif
68783 +
68784 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
68785 };
68786
68787 struct core_thread {
68788 @@ -362,7 +364,7 @@ struct mm_struct {
68789 unsigned long def_flags;
68790 unsigned long nr_ptes; /* Page table pages */
68791 unsigned long start_code, end_code, start_data, end_data;
68792 - unsigned long start_brk, brk, start_stack;
68793 + unsigned long aslr_gap, start_brk, brk, start_stack;
68794 unsigned long arg_start, arg_end, env_start, env_end;
68795
68796 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
68797 @@ -436,6 +438,24 @@ struct mm_struct {
68798 int first_nid;
68799 #endif
68800 struct uprobes_state uprobes_state;
68801 +
68802 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
68803 + unsigned long pax_flags;
68804 +#endif
68805 +
68806 +#ifdef CONFIG_PAX_DLRESOLVE
68807 + unsigned long call_dl_resolve;
68808 +#endif
68809 +
68810 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
68811 + unsigned long call_syscall;
68812 +#endif
68813 +
68814 +#ifdef CONFIG_PAX_ASLR
68815 + unsigned long delta_mmap; /* randomized offset */
68816 + unsigned long delta_stack; /* randomized offset */
68817 +#endif
68818 +
68819 };
68820
68821 /* first nid will either be a valid NID or one of these values */
68822 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
68823 index c5d5278..f0b68c8 100644
68824 --- a/include/linux/mmiotrace.h
68825 +++ b/include/linux/mmiotrace.h
68826 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
68827 /* Called from ioremap.c */
68828 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
68829 void __iomem *addr);
68830 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
68831 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
68832
68833 /* For anyone to insert markers. Remember trailing newline. */
68834 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
68835 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
68836 {
68837 }
68838
68839 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
68840 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
68841 {
68842 }
68843
68844 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
68845 index 73b64a3..6562925 100644
68846 --- a/include/linux/mmzone.h
68847 +++ b/include/linux/mmzone.h
68848 @@ -412,7 +412,7 @@ struct zone {
68849 unsigned long flags; /* zone flags, see below */
68850
68851 /* Zone statistics */
68852 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
68853 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
68854
68855 /*
68856 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
68857 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
68858 index fed3def..c933f99 100644
68859 --- a/include/linux/mod_devicetable.h
68860 +++ b/include/linux/mod_devicetable.h
68861 @@ -12,7 +12,7 @@
68862 typedef unsigned long kernel_ulong_t;
68863 #endif
68864
68865 -#define PCI_ANY_ID (~0)
68866 +#define PCI_ANY_ID ((__u16)~0)
68867
68868 struct pci_device_id {
68869 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
68870 @@ -139,7 +139,7 @@ struct usb_device_id {
68871 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
68872 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
68873
68874 -#define HID_ANY_ID (~0)
68875 +#define HID_ANY_ID (~0U)
68876 #define HID_BUS_ANY 0xffff
68877 #define HID_GROUP_ANY 0x0000
68878
68879 @@ -498,7 +498,7 @@ struct dmi_system_id {
68880 const char *ident;
68881 struct dmi_strmatch matches[4];
68882 void *driver_data;
68883 -};
68884 +} __do_const;
68885 /*
68886 * struct dmi_device_id appears during expansion of
68887 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
68888 diff --git a/include/linux/module.h b/include/linux/module.h
68889 index 1375ee3..ced8177 100644
68890 --- a/include/linux/module.h
68891 +++ b/include/linux/module.h
68892 @@ -17,9 +17,11 @@
68893 #include <linux/moduleparam.h>
68894 #include <linux/tracepoint.h>
68895 #include <linux/export.h>
68896 +#include <linux/fs.h>
68897
68898 #include <linux/percpu.h>
68899 #include <asm/module.h>
68900 +#include <asm/pgtable.h>
68901
68902 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
68903 #define MODULE_SIG_STRING "~Module signature appended~\n"
68904 @@ -54,12 +56,13 @@ struct module_attribute {
68905 int (*test)(struct module *);
68906 void (*free)(struct module *);
68907 };
68908 +typedef struct module_attribute __no_const module_attribute_no_const;
68909
68910 struct module_version_attribute {
68911 struct module_attribute mattr;
68912 const char *module_name;
68913 const char *version;
68914 -} __attribute__ ((__aligned__(sizeof(void *))));
68915 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
68916
68917 extern ssize_t __modver_version_show(struct module_attribute *,
68918 struct module_kobject *, char *);
68919 @@ -232,7 +235,7 @@ struct module
68920
68921 /* Sysfs stuff. */
68922 struct module_kobject mkobj;
68923 - struct module_attribute *modinfo_attrs;
68924 + module_attribute_no_const *modinfo_attrs;
68925 const char *version;
68926 const char *srcversion;
68927 struct kobject *holders_dir;
68928 @@ -281,19 +284,16 @@ struct module
68929 int (*init)(void);
68930
68931 /* If this is non-NULL, vfree after init() returns */
68932 - void *module_init;
68933 + void *module_init_rx, *module_init_rw;
68934
68935 /* Here is the actual code + data, vfree'd on unload. */
68936 - void *module_core;
68937 + void *module_core_rx, *module_core_rw;
68938
68939 /* Here are the sizes of the init and core sections */
68940 - unsigned int init_size, core_size;
68941 + unsigned int init_size_rw, core_size_rw;
68942
68943 /* The size of the executable code in each section. */
68944 - unsigned int init_text_size, core_text_size;
68945 -
68946 - /* Size of RO sections of the module (text+rodata) */
68947 - unsigned int init_ro_size, core_ro_size;
68948 + unsigned int init_size_rx, core_size_rx;
68949
68950 /* Arch-specific module values */
68951 struct mod_arch_specific arch;
68952 @@ -349,6 +349,10 @@ struct module
68953 #ifdef CONFIG_EVENT_TRACING
68954 struct ftrace_event_call **trace_events;
68955 unsigned int num_trace_events;
68956 + struct file_operations trace_id;
68957 + struct file_operations trace_enable;
68958 + struct file_operations trace_format;
68959 + struct file_operations trace_filter;
68960 #endif
68961 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
68962 unsigned int num_ftrace_callsites;
68963 @@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
68964 bool is_module_percpu_address(unsigned long addr);
68965 bool is_module_text_address(unsigned long addr);
68966
68967 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
68968 +{
68969 +
68970 +#ifdef CONFIG_PAX_KERNEXEC
68971 + if (ktla_ktva(addr) >= (unsigned long)start &&
68972 + ktla_ktva(addr) < (unsigned long)start + size)
68973 + return 1;
68974 +#endif
68975 +
68976 + return ((void *)addr >= start && (void *)addr < start + size);
68977 +}
68978 +
68979 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
68980 +{
68981 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
68982 +}
68983 +
68984 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
68985 +{
68986 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
68987 +}
68988 +
68989 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
68990 +{
68991 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
68992 +}
68993 +
68994 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
68995 +{
68996 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
68997 +}
68998 +
68999 static inline int within_module_core(unsigned long addr, struct module *mod)
69000 {
69001 - return (unsigned long)mod->module_core <= addr &&
69002 - addr < (unsigned long)mod->module_core + mod->core_size;
69003 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
69004 }
69005
69006 static inline int within_module_init(unsigned long addr, struct module *mod)
69007 {
69008 - return (unsigned long)mod->module_init <= addr &&
69009 - addr < (unsigned long)mod->module_init + mod->init_size;
69010 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
69011 }
69012
69013 /* Search for module by name: must hold module_mutex. */
69014 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
69015 index 560ca53..5ee8d73 100644
69016 --- a/include/linux/moduleloader.h
69017 +++ b/include/linux/moduleloader.h
69018 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
69019
69020 /* Allocator used for allocating struct module, core sections and init
69021 sections. Returns NULL on failure. */
69022 -void *module_alloc(unsigned long size);
69023 +void *module_alloc(unsigned long size) __size_overflow(1);
69024 +
69025 +#ifdef CONFIG_PAX_KERNEXEC
69026 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
69027 +#else
69028 +#define module_alloc_exec(x) module_alloc(x)
69029 +#endif
69030
69031 /* Free memory returned from module_alloc. */
69032 void module_free(struct module *mod, void *module_region);
69033
69034 +#ifdef CONFIG_PAX_KERNEXEC
69035 +void module_free_exec(struct module *mod, void *module_region);
69036 +#else
69037 +#define module_free_exec(x, y) module_free((x), (y))
69038 +#endif
69039 +
69040 /*
69041 * Apply the given relocation to the (simplified) ELF. Return -error
69042 * or 0.
69043 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
69044 unsigned int relsec,
69045 struct module *me)
69046 {
69047 +#ifdef CONFIG_MODULES
69048 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69049 +#endif
69050 return -ENOEXEC;
69051 }
69052 #endif
69053 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
69054 unsigned int relsec,
69055 struct module *me)
69056 {
69057 +#ifdef CONFIG_MODULES
69058 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69059 +#endif
69060 return -ENOEXEC;
69061 }
69062 #endif
69063 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
69064 index 137b419..fe663ec 100644
69065 --- a/include/linux/moduleparam.h
69066 +++ b/include/linux/moduleparam.h
69067 @@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
69068 * @len is usually just sizeof(string).
69069 */
69070 #define module_param_string(name, string, len, perm) \
69071 - static const struct kparam_string __param_string_##name \
69072 + static const struct kparam_string __param_string_##name __used \
69073 = { len, string }; \
69074 __module_param_call(MODULE_PARAM_PREFIX, name, \
69075 &param_ops_string, \
69076 @@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
69077 */
69078 #define module_param_array_named(name, array, type, nump, perm) \
69079 param_check_##type(name, &(array)[0]); \
69080 - static const struct kparam_array __param_arr_##name \
69081 + static const struct kparam_array __param_arr_##name __used \
69082 = { .max = ARRAY_SIZE(array), .num = nump, \
69083 .ops = &param_ops_##type, \
69084 .elemsize = sizeof(array[0]), .elem = array }; \
69085 diff --git a/include/linux/namei.h b/include/linux/namei.h
69086 index 5a5ff57..5ae5070 100644
69087 --- a/include/linux/namei.h
69088 +++ b/include/linux/namei.h
69089 @@ -19,7 +19,7 @@ struct nameidata {
69090 unsigned seq;
69091 int last_type;
69092 unsigned depth;
69093 - char *saved_names[MAX_NESTED_LINKS + 1];
69094 + const char *saved_names[MAX_NESTED_LINKS + 1];
69095 };
69096
69097 /*
69098 @@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
69099
69100 extern void nd_jump_link(struct nameidata *nd, struct path *path);
69101
69102 -static inline void nd_set_link(struct nameidata *nd, char *path)
69103 +static inline void nd_set_link(struct nameidata *nd, const char *path)
69104 {
69105 nd->saved_names[nd->depth] = path;
69106 }
69107
69108 -static inline char *nd_get_link(struct nameidata *nd)
69109 +static inline const char *nd_get_link(const struct nameidata *nd)
69110 {
69111 return nd->saved_names[nd->depth];
69112 }
69113 diff --git a/include/linux/net.h b/include/linux/net.h
69114 index aa16731..514b875 100644
69115 --- a/include/linux/net.h
69116 +++ b/include/linux/net.h
69117 @@ -183,7 +183,7 @@ struct net_proto_family {
69118 int (*create)(struct net *net, struct socket *sock,
69119 int protocol, int kern);
69120 struct module *owner;
69121 -};
69122 +} __do_const;
69123
69124 struct iovec;
69125 struct kvec;
69126 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
69127 index 9ef07d0..130a5d9 100644
69128 --- a/include/linux/netdevice.h
69129 +++ b/include/linux/netdevice.h
69130 @@ -1012,6 +1012,7 @@ struct net_device_ops {
69131 u32 pid, u32 seq,
69132 struct net_device *dev);
69133 };
69134 +typedef struct net_device_ops __no_const net_device_ops_no_const;
69135
69136 /*
69137 * The DEVICE structure.
69138 @@ -1078,7 +1079,7 @@ struct net_device {
69139 int iflink;
69140
69141 struct net_device_stats stats;
69142 - atomic_long_t rx_dropped; /* dropped packets by core network
69143 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
69144 * Do not use this in drivers.
69145 */
69146
69147 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
69148 index ee14284..bc65d63 100644
69149 --- a/include/linux/netfilter.h
69150 +++ b/include/linux/netfilter.h
69151 @@ -82,7 +82,7 @@ struct nf_sockopt_ops {
69152 #endif
69153 /* Use the module struct to lock set/get code in place */
69154 struct module *owner;
69155 -};
69156 +} __do_const;
69157
69158 /* Function to register/unregister hook points. */
69159 int nf_register_hook(struct nf_hook_ops *reg);
69160 diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
69161 index 7958e84..ed74d7a 100644
69162 --- a/include/linux/netfilter/ipset/ip_set.h
69163 +++ b/include/linux/netfilter/ipset/ip_set.h
69164 @@ -98,7 +98,7 @@ struct ip_set_type_variant {
69165 /* Return true if "b" set is the same as "a"
69166 * according to the create set parameters */
69167 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
69168 -};
69169 +} __do_const;
69170
69171 /* The core set type structure */
69172 struct ip_set_type {
69173 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
69174 index 4966dde..7d8ce06 100644
69175 --- a/include/linux/netfilter/nfnetlink.h
69176 +++ b/include/linux/netfilter/nfnetlink.h
69177 @@ -16,7 +16,7 @@ struct nfnl_callback {
69178 const struct nlattr * const cda[]);
69179 const struct nla_policy *policy; /* netlink attribute policy */
69180 const u_int16_t attr_count; /* number of nlattr's */
69181 -};
69182 +} __do_const;
69183
69184 struct nfnetlink_subsystem {
69185 const char *name;
69186 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
69187 new file mode 100644
69188 index 0000000..33f4af8
69189 --- /dev/null
69190 +++ b/include/linux/netfilter/xt_gradm.h
69191 @@ -0,0 +1,9 @@
69192 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
69193 +#define _LINUX_NETFILTER_XT_GRADM_H 1
69194 +
69195 +struct xt_gradm_mtinfo {
69196 + __u16 flags;
69197 + __u16 invflags;
69198 +};
69199 +
69200 +#endif
69201 diff --git a/include/linux/nls.h b/include/linux/nls.h
69202 index 5dc635f..35f5e11 100644
69203 --- a/include/linux/nls.h
69204 +++ b/include/linux/nls.h
69205 @@ -31,7 +31,7 @@ struct nls_table {
69206 const unsigned char *charset2upper;
69207 struct module *owner;
69208 struct nls_table *next;
69209 -};
69210 +} __do_const;
69211
69212 /* this value hold the maximum octet of charset */
69213 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
69214 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
69215 index d65746e..62e72c2 100644
69216 --- a/include/linux/notifier.h
69217 +++ b/include/linux/notifier.h
69218 @@ -51,7 +51,8 @@ struct notifier_block {
69219 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
69220 struct notifier_block __rcu *next;
69221 int priority;
69222 -};
69223 +} __do_const;
69224 +typedef struct notifier_block __no_const notifier_block_no_const;
69225
69226 struct atomic_notifier_head {
69227 spinlock_t lock;
69228 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
69229 index a4c5624..79d6d88 100644
69230 --- a/include/linux/oprofile.h
69231 +++ b/include/linux/oprofile.h
69232 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
69233 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
69234 char const * name, ulong * val);
69235
69236 -/** Create a file for read-only access to an atomic_t. */
69237 +/** Create a file for read-only access to an atomic_unchecked_t. */
69238 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
69239 - char const * name, atomic_t * val);
69240 + char const * name, atomic_unchecked_t * val);
69241
69242 /** create a directory */
69243 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
69244 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
69245 index 45fc162..01a4068 100644
69246 --- a/include/linux/pci_hotplug.h
69247 +++ b/include/linux/pci_hotplug.h
69248 @@ -80,7 +80,8 @@ struct hotplug_slot_ops {
69249 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
69250 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
69251 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
69252 -};
69253 +} __do_const;
69254 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
69255
69256 /**
69257 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
69258 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
69259 index 6bfb2faa..e5bc5e5 100644
69260 --- a/include/linux/perf_event.h
69261 +++ b/include/linux/perf_event.h
69262 @@ -328,8 +328,8 @@ struct perf_event {
69263
69264 enum perf_event_active_state state;
69265 unsigned int attach_state;
69266 - local64_t count;
69267 - atomic64_t child_count;
69268 + local64_t count; /* PaX: fix it one day */
69269 + atomic64_unchecked_t child_count;
69270
69271 /*
69272 * These are the total time in nanoseconds that the event
69273 @@ -380,8 +380,8 @@ struct perf_event {
69274 * These accumulate total time (in nanoseconds) that children
69275 * events have been enabled and running, respectively.
69276 */
69277 - atomic64_t child_total_time_enabled;
69278 - atomic64_t child_total_time_running;
69279 + atomic64_unchecked_t child_total_time_enabled;
69280 + atomic64_unchecked_t child_total_time_running;
69281
69282 /*
69283 * Protect attach/detach and child_list:
69284 @@ -801,7 +801,7 @@ static inline void perf_event_task_tick(void) { }
69285 */
69286 #define perf_cpu_notifier(fn) \
69287 do { \
69288 - static struct notifier_block fn##_nb __cpuinitdata = \
69289 + static struct notifier_block fn##_nb = \
69290 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
69291 unsigned long cpu = smp_processor_id(); \
69292 unsigned long flags; \
69293 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
69294 index ad1a427..6419649 100644
69295 --- a/include/linux/pipe_fs_i.h
69296 +++ b/include/linux/pipe_fs_i.h
69297 @@ -45,9 +45,9 @@ struct pipe_buffer {
69298 struct pipe_inode_info {
69299 wait_queue_head_t wait;
69300 unsigned int nrbufs, curbuf, buffers;
69301 - unsigned int readers;
69302 - unsigned int writers;
69303 - unsigned int waiting_writers;
69304 + atomic_t readers;
69305 + atomic_t writers;
69306 + atomic_t waiting_writers;
69307 unsigned int r_counter;
69308 unsigned int w_counter;
69309 struct page *tmp_page;
69310 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
69311 index 5f28cae..3d23723 100644
69312 --- a/include/linux/platform_data/usb-ehci-s5p.h
69313 +++ b/include/linux/platform_data/usb-ehci-s5p.h
69314 @@ -14,7 +14,7 @@
69315 struct s5p_ehci_platdata {
69316 int (*phy_init)(struct platform_device *pdev, int type);
69317 int (*phy_exit)(struct platform_device *pdev, int type);
69318 -};
69319 +} __no_const;
69320
69321 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
69322
69323 diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
69324 index c256c59..8ea94c7 100644
69325 --- a/include/linux/platform_data/usb-exynos.h
69326 +++ b/include/linux/platform_data/usb-exynos.h
69327 @@ -14,7 +14,7 @@
69328 struct exynos4_ohci_platdata {
69329 int (*phy_init)(struct platform_device *pdev, int type);
69330 int (*phy_exit)(struct platform_device *pdev, int type);
69331 -};
69332 +} __no_const;
69333
69334 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
69335
69336 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
69337 index 7c1d252..c5c773e 100644
69338 --- a/include/linux/pm_domain.h
69339 +++ b/include/linux/pm_domain.h
69340 @@ -48,7 +48,7 @@ struct gpd_dev_ops {
69341
69342 struct gpd_cpu_data {
69343 unsigned int saved_exit_latency;
69344 - struct cpuidle_state *idle_state;
69345 + cpuidle_state_no_const *idle_state;
69346 };
69347
69348 struct generic_pm_domain {
69349 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
69350 index f271860..6b3bec5 100644
69351 --- a/include/linux/pm_runtime.h
69352 +++ b/include/linux/pm_runtime.h
69353 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
69354
69355 static inline void pm_runtime_mark_last_busy(struct device *dev)
69356 {
69357 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
69358 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
69359 }
69360
69361 #else /* !CONFIG_PM_RUNTIME */
69362 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
69363 index 195aafc..49a7bc2 100644
69364 --- a/include/linux/pnp.h
69365 +++ b/include/linux/pnp.h
69366 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
69367 struct pnp_fixup {
69368 char id[7];
69369 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
69370 -};
69371 +} __do_const;
69372
69373 /* config parameters */
69374 #define PNP_CONFIG_NORMAL 0x0001
69375 diff --git a/include/linux/poison.h b/include/linux/poison.h
69376 index 2110a81..13a11bb 100644
69377 --- a/include/linux/poison.h
69378 +++ b/include/linux/poison.h
69379 @@ -19,8 +19,8 @@
69380 * under normal circumstances, used to verify that nobody uses
69381 * non-initialized list entries.
69382 */
69383 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
69384 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
69385 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
69386 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
69387
69388 /********** include/linux/timer.h **********/
69389 /*
69390 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
69391 index c0f44c2..1572583 100644
69392 --- a/include/linux/power/smartreflex.h
69393 +++ b/include/linux/power/smartreflex.h
69394 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
69395 int (*notify)(struct omap_sr *sr, u32 status);
69396 u8 notify_flags;
69397 u8 class_type;
69398 -};
69399 +} __do_const;
69400
69401 /**
69402 * struct omap_sr_nvalue_table - Smartreflex n-target value info
69403 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
69404 index 4ea1d37..80f4b33 100644
69405 --- a/include/linux/ppp-comp.h
69406 +++ b/include/linux/ppp-comp.h
69407 @@ -84,7 +84,7 @@ struct compressor {
69408 struct module *owner;
69409 /* Extra skb space needed by the compressor algorithm */
69410 unsigned int comp_extra;
69411 -};
69412 +} __do_const;
69413
69414 /*
69415 * The return value from decompress routine is the length of the
69416 diff --git a/include/linux/printk.h b/include/linux/printk.h
69417 index 9afc01e..92c32e8 100644
69418 --- a/include/linux/printk.h
69419 +++ b/include/linux/printk.h
69420 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
69421 extern int printk_needs_cpu(int cpu);
69422 extern void printk_tick(void);
69423
69424 +extern int kptr_restrict;
69425 +
69426 #ifdef CONFIG_PRINTK
69427 asmlinkage __printf(5, 0)
69428 int vprintk_emit(int facility, int level,
69429 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
69430
69431 extern int printk_delay_msec;
69432 extern int dmesg_restrict;
69433 -extern int kptr_restrict;
69434
69435 void log_buf_kexec_setup(void);
69436 void __init setup_log_buf(int early);
69437 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
69438 index 32676b3..8f7a182 100644
69439 --- a/include/linux/proc_fs.h
69440 +++ b/include/linux/proc_fs.h
69441 @@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
69442 return proc_create_data(name, mode, parent, proc_fops, NULL);
69443 }
69444
69445 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
69446 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
69447 +{
69448 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69449 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
69450 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69451 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
69452 +#else
69453 + return proc_create_data(name, mode, parent, proc_fops, NULL);
69454 +#endif
69455 +}
69456 +
69457 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
69458 umode_t mode, struct proc_dir_entry *base,
69459 read_proc_t *read_proc, void * data)
69460 diff --git a/include/linux/random.h b/include/linux/random.h
69461 index d984608..d6f0042 100644
69462 --- a/include/linux/random.h
69463 +++ b/include/linux/random.h
69464 @@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
69465 u32 prandom_u32_state(struct rnd_state *);
69466 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
69467
69468 +static inline unsigned long pax_get_random_long(void)
69469 +{
69470 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
69471 +}
69472 +
69473 /*
69474 * Handle minimum values for seeds
69475 */
69476 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
69477 index c92dd28..08f4eab 100644
69478 --- a/include/linux/rculist.h
69479 +++ b/include/linux/rculist.h
69480 @@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
69481 struct list_head *prev, struct list_head *next);
69482 #endif
69483
69484 +extern void __pax_list_add_rcu(struct list_head *new,
69485 + struct list_head *prev, struct list_head *next);
69486 +
69487 /**
69488 * list_add_rcu - add a new entry to rcu-protected list
69489 * @new: new entry to be added
69490 @@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
69491 __list_add_rcu(new, head, head->next);
69492 }
69493
69494 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
69495 +{
69496 + __pax_list_add_rcu(new, head, head->next);
69497 +}
69498 +
69499 /**
69500 * list_add_tail_rcu - add a new entry to rcu-protected list
69501 * @new: new entry to be added
69502 @@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
69503 __list_add_rcu(new, head->prev, head);
69504 }
69505
69506 +static inline void pax_list_add_tail_rcu(struct list_head *new,
69507 + struct list_head *head)
69508 +{
69509 + __pax_list_add_rcu(new, head->prev, head);
69510 +}
69511 +
69512 /**
69513 * list_del_rcu - deletes entry from list without re-initialization
69514 * @entry: the element to delete from the list.
69515 @@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
69516 entry->prev = LIST_POISON2;
69517 }
69518
69519 +extern void pax_list_del_rcu(struct list_head *entry);
69520 +
69521 /**
69522 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
69523 * @n: the element to delete from the hash list.
69524 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
69525 index 23b3630..e1bc12b 100644
69526 --- a/include/linux/reboot.h
69527 +++ b/include/linux/reboot.h
69528 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
69529 * Architecture-specific implementations of sys_reboot commands.
69530 */
69531
69532 -extern void machine_restart(char *cmd);
69533 -extern void machine_halt(void);
69534 -extern void machine_power_off(void);
69535 +extern void machine_restart(char *cmd) __noreturn;
69536 +extern void machine_halt(void) __noreturn;
69537 +extern void machine_power_off(void) __noreturn;
69538
69539 extern void machine_shutdown(void);
69540 struct pt_regs;
69541 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
69542 */
69543
69544 extern void kernel_restart_prepare(char *cmd);
69545 -extern void kernel_restart(char *cmd);
69546 -extern void kernel_halt(void);
69547 -extern void kernel_power_off(void);
69548 +extern void kernel_restart(char *cmd) __noreturn;
69549 +extern void kernel_halt(void) __noreturn;
69550 +extern void kernel_power_off(void) __noreturn;
69551
69552 extern int C_A_D; /* for sysctl */
69553 void ctrl_alt_del(void);
69554 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
69555 * Emergency restart, callable from an interrupt handler.
69556 */
69557
69558 -extern void emergency_restart(void);
69559 +extern void emergency_restart(void) __noreturn;
69560 #include <asm/emergency-restart.h>
69561
69562 #endif /* _LINUX_REBOOT_H */
69563 diff --git a/include/linux/regset.h b/include/linux/regset.h
69564 index 8e0c9fe..ac4d221 100644
69565 --- a/include/linux/regset.h
69566 +++ b/include/linux/regset.h
69567 @@ -161,7 +161,8 @@ struct user_regset {
69568 unsigned int align;
69569 unsigned int bias;
69570 unsigned int core_note_type;
69571 -};
69572 +} __do_const;
69573 +typedef struct user_regset __no_const user_regset_no_const;
69574
69575 /**
69576 * struct user_regset_view - available regsets
69577 diff --git a/include/linux/relay.h b/include/linux/relay.h
69578 index 91cacc3..b55ff74 100644
69579 --- a/include/linux/relay.h
69580 +++ b/include/linux/relay.h
69581 @@ -160,7 +160,7 @@ struct rchan_callbacks
69582 * The callback should return 0 if successful, negative if not.
69583 */
69584 int (*remove_buf_file)(struct dentry *dentry);
69585 -};
69586 +} __no_const;
69587
69588 /*
69589 * CONFIG_RELAY kernel API, kernel/relay.c
69590 diff --git a/include/linux/rio.h b/include/linux/rio.h
69591 index a3e7842..d973ca6 100644
69592 --- a/include/linux/rio.h
69593 +++ b/include/linux/rio.h
69594 @@ -339,7 +339,7 @@ struct rio_ops {
69595 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
69596 u64 rstart, u32 size, u32 flags);
69597 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
69598 -};
69599 +} __no_const;
69600
69601 #define RIO_RESOURCE_MEM 0x00000100
69602 #define RIO_RESOURCE_DOORBELL 0x00000200
69603 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
69604 index c20635c..2f5def4 100644
69605 --- a/include/linux/rmap.h
69606 +++ b/include/linux/rmap.h
69607 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
69608 void anon_vma_init(void); /* create anon_vma_cachep */
69609 int anon_vma_prepare(struct vm_area_struct *);
69610 void unlink_anon_vmas(struct vm_area_struct *);
69611 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
69612 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
69613 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
69614 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
69615
69616 static inline void anon_vma_merge(struct vm_area_struct *vma,
69617 struct vm_area_struct *next)
69618 diff --git a/include/linux/sched.h b/include/linux/sched.h
69619 index d211247..a5cbf38b 100644
69620 --- a/include/linux/sched.h
69621 +++ b/include/linux/sched.h
69622 @@ -61,6 +61,7 @@ struct bio_list;
69623 struct fs_struct;
69624 struct perf_event_context;
69625 struct blk_plug;
69626 +struct linux_binprm;
69627
69628 /*
69629 * List of flags we want to share for kernel threads,
69630 @@ -354,10 +355,23 @@ struct user_namespace;
69631 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
69632
69633 extern int sysctl_max_map_count;
69634 +extern unsigned long sysctl_heap_stack_gap;
69635
69636 #include <linux/aio.h>
69637
69638 #ifdef CONFIG_MMU
69639 +
69640 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
69641 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
69642 +#else
69643 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
69644 +{
69645 + return 0;
69646 +}
69647 +#endif
69648 +
69649 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
69650 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
69651 extern void arch_pick_mmap_layout(struct mm_struct *mm);
69652 extern unsigned long
69653 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
69654 @@ -639,6 +653,17 @@ struct signal_struct {
69655 #ifdef CONFIG_TASKSTATS
69656 struct taskstats *stats;
69657 #endif
69658 +
69659 +#ifdef CONFIG_GRKERNSEC
69660 + u32 curr_ip;
69661 + u32 saved_ip;
69662 + u32 gr_saddr;
69663 + u32 gr_daddr;
69664 + u16 gr_sport;
69665 + u16 gr_dport;
69666 + u8 used_accept:1;
69667 +#endif
69668 +
69669 #ifdef CONFIG_AUDIT
69670 unsigned audit_tty;
69671 struct tty_audit_buf *tty_audit_buf;
69672 @@ -717,6 +742,11 @@ struct user_struct {
69673 struct key *session_keyring; /* UID's default session keyring */
69674 #endif
69675
69676 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
69677 + unsigned int banned;
69678 + unsigned long ban_expires;
69679 +#endif
69680 +
69681 /* Hash table maintenance information */
69682 struct hlist_node uidhash_node;
69683 kuid_t uid;
69684 @@ -1116,7 +1146,7 @@ struct sched_class {
69685 #ifdef CONFIG_FAIR_GROUP_SCHED
69686 void (*task_move_group) (struct task_struct *p, int on_rq);
69687 #endif
69688 -};
69689 +} __do_const;
69690
69691 struct load_weight {
69692 unsigned long weight, inv_weight;
69693 @@ -1360,8 +1390,8 @@ struct task_struct {
69694 struct list_head thread_group;
69695
69696 struct completion *vfork_done; /* for vfork() */
69697 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
69698 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
69699 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
69700 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
69701
69702 cputime_t utime, stime, utimescaled, stimescaled;
69703 cputime_t gtime;
69704 @@ -1377,11 +1407,6 @@ struct task_struct {
69705 struct task_cputime cputime_expires;
69706 struct list_head cpu_timers[3];
69707
69708 -/* process credentials */
69709 - const struct cred __rcu *real_cred; /* objective and real subjective task
69710 - * credentials (COW) */
69711 - const struct cred __rcu *cred; /* effective (overridable) subjective task
69712 - * credentials (COW) */
69713 char comm[TASK_COMM_LEN]; /* executable name excluding path
69714 - access with [gs]et_task_comm (which lock
69715 it with task_lock())
69716 @@ -1398,6 +1423,10 @@ struct task_struct {
69717 #endif
69718 /* CPU-specific state of this task */
69719 struct thread_struct thread;
69720 +/* thread_info moved to task_struct */
69721 +#ifdef CONFIG_X86
69722 + struct thread_info tinfo;
69723 +#endif
69724 /* filesystem information */
69725 struct fs_struct *fs;
69726 /* open file information */
69727 @@ -1471,6 +1500,10 @@ struct task_struct {
69728 gfp_t lockdep_reclaim_gfp;
69729 #endif
69730
69731 +/* process credentials */
69732 + const struct cred __rcu *real_cred; /* objective and real subjective task
69733 + * credentials (COW) */
69734 +
69735 /* journalling filesystem info */
69736 void *journal_info;
69737
69738 @@ -1509,6 +1542,10 @@ struct task_struct {
69739 /* cg_list protected by css_set_lock and tsk->alloc_lock */
69740 struct list_head cg_list;
69741 #endif
69742 +
69743 + const struct cred __rcu *cred; /* effective (overridable) subjective task
69744 + * credentials (COW) */
69745 +
69746 #ifdef CONFIG_FUTEX
69747 struct robust_list_head __user *robust_list;
69748 #ifdef CONFIG_COMPAT
69749 @@ -1605,8 +1642,74 @@ struct task_struct {
69750 #ifdef CONFIG_UPROBES
69751 struct uprobe_task *utask;
69752 #endif
69753 +
69754 +#ifdef CONFIG_GRKERNSEC
69755 + /* grsecurity */
69756 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
69757 + u64 exec_id;
69758 +#endif
69759 +#ifdef CONFIG_GRKERNSEC_SETXID
69760 + const struct cred *delayed_cred;
69761 +#endif
69762 + struct dentry *gr_chroot_dentry;
69763 + struct acl_subject_label *acl;
69764 + struct acl_role_label *role;
69765 + struct file *exec_file;
69766 + unsigned long brute_expires;
69767 + u16 acl_role_id;
69768 + /* is this the task that authenticated to the special role */
69769 + u8 acl_sp_role;
69770 + u8 is_writable;
69771 + u8 brute;
69772 + u8 gr_is_chrooted;
69773 +#endif
69774 +
69775 };
69776
69777 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
69778 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
69779 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
69780 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
69781 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
69782 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
69783 +
69784 +#ifdef CONFIG_PAX_SOFTMODE
69785 +extern int pax_softmode;
69786 +#endif
69787 +
69788 +extern int pax_check_flags(unsigned long *);
69789 +
69790 +/* if tsk != current then task_lock must be held on it */
69791 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
69792 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
69793 +{
69794 + if (likely(tsk->mm))
69795 + return tsk->mm->pax_flags;
69796 + else
69797 + return 0UL;
69798 +}
69799 +
69800 +/* if tsk != current then task_lock must be held on it */
69801 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
69802 +{
69803 + if (likely(tsk->mm)) {
69804 + tsk->mm->pax_flags = flags;
69805 + return 0;
69806 + }
69807 + return -EINVAL;
69808 +}
69809 +#endif
69810 +
69811 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
69812 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
69813 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
69814 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
69815 +#endif
69816 +
69817 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
69818 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
69819 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
69820 +
69821 /* Future-safe accessor for struct task_struct's cpus_allowed. */
69822 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
69823
69824 @@ -1696,7 +1799,7 @@ struct pid_namespace;
69825 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
69826 struct pid_namespace *ns);
69827
69828 -static inline pid_t task_pid_nr(struct task_struct *tsk)
69829 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
69830 {
69831 return tsk->pid;
69832 }
69833 @@ -2155,7 +2258,9 @@ void yield(void);
69834 extern struct exec_domain default_exec_domain;
69835
69836 union thread_union {
69837 +#ifndef CONFIG_X86
69838 struct thread_info thread_info;
69839 +#endif
69840 unsigned long stack[THREAD_SIZE/sizeof(long)];
69841 };
69842
69843 @@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
69844 */
69845
69846 extern struct task_struct *find_task_by_vpid(pid_t nr);
69847 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
69848 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
69849 struct pid_namespace *ns);
69850
69851 @@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
69852 extern void exit_itimers(struct signal_struct *);
69853 extern void flush_itimer_signals(void);
69854
69855 -extern void do_group_exit(int);
69856 +extern __noreturn void do_group_exit(int);
69857
69858 extern int allow_signal(int);
69859 extern int disallow_signal(int);
69860 @@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
69861
69862 #endif
69863
69864 -static inline int object_is_on_stack(void *obj)
69865 +static inline int object_starts_on_stack(void *obj)
69866 {
69867 - void *stack = task_stack_page(current);
69868 + const void *stack = task_stack_page(current);
69869
69870 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
69871 }
69872 diff --git a/include/linux/security.h b/include/linux/security.h
69873 index eee7478..290f7ba 100644
69874 --- a/include/linux/security.h
69875 +++ b/include/linux/security.h
69876 @@ -26,6 +26,7 @@
69877 #include <linux/capability.h>
69878 #include <linux/slab.h>
69879 #include <linux/err.h>
69880 +#include <linux/grsecurity.h>
69881
69882 struct linux_binprm;
69883 struct cred;
69884 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
69885 index 68a04a3..866e6a1 100644
69886 --- a/include/linux/seq_file.h
69887 +++ b/include/linux/seq_file.h
69888 @@ -26,6 +26,9 @@ struct seq_file {
69889 struct mutex lock;
69890 const struct seq_operations *op;
69891 int poll_event;
69892 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
69893 + u64 exec_id;
69894 +#endif
69895 #ifdef CONFIG_USER_NS
69896 struct user_namespace *user_ns;
69897 #endif
69898 @@ -38,6 +41,7 @@ struct seq_operations {
69899 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
69900 int (*show) (struct seq_file *m, void *v);
69901 };
69902 +typedef struct seq_operations __no_const seq_operations_no_const;
69903
69904 #define SEQ_SKIP 1
69905
69906 diff --git a/include/linux/shm.h b/include/linux/shm.h
69907 index 429c199..4d42e38 100644
69908 --- a/include/linux/shm.h
69909 +++ b/include/linux/shm.h
69910 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
69911
69912 /* The task created the shm object. NULL if the task is dead. */
69913 struct task_struct *shm_creator;
69914 +#ifdef CONFIG_GRKERNSEC
69915 + time_t shm_createtime;
69916 + pid_t shm_lapid;
69917 +#endif
69918 };
69919
69920 /* shm_mode upper byte flags */
69921 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
69922 index 320e976..fd52553 100644
69923 --- a/include/linux/skbuff.h
69924 +++ b/include/linux/skbuff.h
69925 @@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
69926 extern struct sk_buff *__alloc_skb(unsigned int size,
69927 gfp_t priority, int flags, int node);
69928 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
69929 -static inline struct sk_buff *alloc_skb(unsigned int size,
69930 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
69931 gfp_t priority)
69932 {
69933 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
69934 @@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
69935 */
69936 static inline int skb_queue_empty(const struct sk_buff_head *list)
69937 {
69938 - return list->next == (struct sk_buff *)list;
69939 + return list->next == (const struct sk_buff *)list;
69940 }
69941
69942 /**
69943 @@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
69944 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
69945 const struct sk_buff *skb)
69946 {
69947 - return skb->next == (struct sk_buff *)list;
69948 + return skb->next == (const struct sk_buff *)list;
69949 }
69950
69951 /**
69952 @@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
69953 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
69954 const struct sk_buff *skb)
69955 {
69956 - return skb->prev == (struct sk_buff *)list;
69957 + return skb->prev == (const struct sk_buff *)list;
69958 }
69959
69960 /**
69961 @@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
69962 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
69963 */
69964 #ifndef NET_SKB_PAD
69965 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
69966 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
69967 #endif
69968
69969 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
69970 @@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
69971 int noblock, int *err);
69972 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
69973 struct poll_table_struct *wait);
69974 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
69975 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
69976 int offset, struct iovec *to,
69977 int size);
69978 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
69979 diff --git a/include/linux/slab.h b/include/linux/slab.h
69980 index 5d168d7..720bff3 100644
69981 --- a/include/linux/slab.h
69982 +++ b/include/linux/slab.h
69983 @@ -12,13 +12,20 @@
69984 #include <linux/gfp.h>
69985 #include <linux/types.h>
69986 #include <linux/workqueue.h>
69987 -
69988 +#include <linux/err.h>
69989
69990 /*
69991 * Flags to pass to kmem_cache_create().
69992 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
69993 */
69994 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
69995 +
69996 +#ifdef CONFIG_PAX_USERCOPY_SLABS
69997 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
69998 +#else
69999 +#define SLAB_USERCOPY 0x00000000UL
70000 +#endif
70001 +
70002 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
70003 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
70004 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
70005 @@ -89,10 +96,13 @@
70006 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
70007 * Both make kfree a no-op.
70008 */
70009 -#define ZERO_SIZE_PTR ((void *)16)
70010 +#define ZERO_SIZE_PTR \
70011 +({ \
70012 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
70013 + (void *)(-MAX_ERRNO-1L); \
70014 +})
70015
70016 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
70017 - (unsigned long)ZERO_SIZE_PTR)
70018 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
70019
70020 /*
70021 * Common fields provided in kmem_cache by all slab allocators
70022 @@ -112,7 +122,7 @@ struct kmem_cache {
70023 unsigned int align; /* Alignment as calculated */
70024 unsigned long flags; /* Active flags on the slab */
70025 const char *name; /* Slab name for sysfs */
70026 - int refcount; /* Use counter */
70027 + atomic_t refcount; /* Use counter */
70028 void (*ctor)(void *); /* Called on object slot creation */
70029 struct list_head list; /* List of all slab caches on the system */
70030 };
70031 @@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
70032 void kfree(const void *);
70033 void kzfree(const void *);
70034 size_t ksize(const void *);
70035 +const char *check_heap_object(const void *ptr, unsigned long n);
70036 +bool is_usercopy_object(const void *ptr);
70037
70038 /*
70039 * Allocator specific definitions. These are mainly used to establish optimized
70040 @@ -311,6 +323,7 @@ size_t ksize(const void *);
70041 * for general use, and so are not documented here. For a full list of
70042 * potential flags, always refer to linux/gfp.h.
70043 */
70044 +
70045 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
70046 {
70047 if (size != 0 && n > SIZE_MAX / size)
70048 @@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
70049 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70050 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70051 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70052 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70053 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
70054 #define kmalloc_track_caller(size, flags) \
70055 __kmalloc_track_caller(size, flags, _RET_IP_)
70056 #else
70057 @@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70058 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70059 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70060 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70061 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
70062 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
70063 #define kmalloc_node_track_caller(size, flags, node) \
70064 __kmalloc_node_track_caller(size, flags, node, \
70065 _RET_IP_)
70066 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
70067 index 8bb6e0e..8eb0dbe 100644
70068 --- a/include/linux/slab_def.h
70069 +++ b/include/linux/slab_def.h
70070 @@ -52,7 +52,7 @@ struct kmem_cache {
70071 /* 4) cache creation/removal */
70072 const char *name;
70073 struct list_head list;
70074 - int refcount;
70075 + atomic_t refcount;
70076 int object_size;
70077 int align;
70078
70079 @@ -68,10 +68,10 @@ struct kmem_cache {
70080 unsigned long node_allocs;
70081 unsigned long node_frees;
70082 unsigned long node_overflow;
70083 - atomic_t allochit;
70084 - atomic_t allocmiss;
70085 - atomic_t freehit;
70086 - atomic_t freemiss;
70087 + atomic_unchecked_t allochit;
70088 + atomic_unchecked_t allocmiss;
70089 + atomic_unchecked_t freehit;
70090 + atomic_unchecked_t freemiss;
70091
70092 /*
70093 * If debugging is enabled, then the allocator can add additional
70094 @@ -111,11 +111,16 @@ struct cache_sizes {
70095 #ifdef CONFIG_ZONE_DMA
70096 struct kmem_cache *cs_dmacachep;
70097 #endif
70098 +
70099 +#ifdef CONFIG_PAX_USERCOPY_SLABS
70100 + struct kmem_cache *cs_usercopycachep;
70101 +#endif
70102 +
70103 };
70104 extern struct cache_sizes malloc_sizes[];
70105
70106 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70107 -void *__kmalloc(size_t size, gfp_t flags);
70108 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
70109
70110 #ifdef CONFIG_TRACING
70111 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
70112 @@ -152,6 +157,13 @@ found:
70113 cachep = malloc_sizes[i].cs_dmacachep;
70114 else
70115 #endif
70116 +
70117 +#ifdef CONFIG_PAX_USERCOPY_SLABS
70118 + if (flags & GFP_USERCOPY)
70119 + cachep = malloc_sizes[i].cs_usercopycachep;
70120 + else
70121 +#endif
70122 +
70123 cachep = malloc_sizes[i].cs_cachep;
70124
70125 ret = kmem_cache_alloc_trace(cachep, flags, size);
70126 @@ -162,7 +174,7 @@ found:
70127 }
70128
70129 #ifdef CONFIG_NUMA
70130 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
70131 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70132 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70133
70134 #ifdef CONFIG_TRACING
70135 @@ -205,6 +217,13 @@ found:
70136 cachep = malloc_sizes[i].cs_dmacachep;
70137 else
70138 #endif
70139 +
70140 +#ifdef CONFIG_PAX_USERCOPY_SLABS
70141 + if (flags & GFP_USERCOPY)
70142 + cachep = malloc_sizes[i].cs_usercopycachep;
70143 + else
70144 +#endif
70145 +
70146 cachep = malloc_sizes[i].cs_cachep;
70147
70148 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
70149 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
70150 index f28e14a..7831211 100644
70151 --- a/include/linux/slob_def.h
70152 +++ b/include/linux/slob_def.h
70153 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
70154 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
70155 }
70156
70157 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
70158 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70159
70160 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
70161 {
70162 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70163 return __kmalloc_node(size, flags, NUMA_NO_NODE);
70164 }
70165
70166 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
70167 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
70168 {
70169 return kmalloc(size, flags);
70170 }
70171 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
70172 index 9db4825..ed42fb5 100644
70173 --- a/include/linux/slub_def.h
70174 +++ b/include/linux/slub_def.h
70175 @@ -91,7 +91,7 @@ struct kmem_cache {
70176 struct kmem_cache_order_objects max;
70177 struct kmem_cache_order_objects min;
70178 gfp_t allocflags; /* gfp flags to use on each alloc */
70179 - int refcount; /* Refcount for slab cache destroy */
70180 + atomic_t refcount; /* Refcount for slab cache destroy */
70181 void (*ctor)(void *);
70182 int inuse; /* Offset to metadata */
70183 int align; /* Alignment */
70184 @@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
70185 * Sorry that the following has to be that ugly but some versions of GCC
70186 * have trouble with constant propagation and loops.
70187 */
70188 -static __always_inline int kmalloc_index(size_t size)
70189 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
70190 {
70191 if (!size)
70192 return 0;
70193 @@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
70194 }
70195
70196 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70197 -void *__kmalloc(size_t size, gfp_t flags);
70198 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
70199
70200 static __always_inline void *
70201 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
70202 @@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
70203 }
70204 #endif
70205
70206 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
70207 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
70208 {
70209 unsigned int order = get_order(size);
70210 return kmalloc_order_trace(size, flags, order);
70211 @@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70212 }
70213
70214 #ifdef CONFIG_NUMA
70215 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
70216 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70217 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70218
70219 #ifdef CONFIG_TRACING
70220 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
70221 index e8d702e..0a56eb4 100644
70222 --- a/include/linux/sock_diag.h
70223 +++ b/include/linux/sock_diag.h
70224 @@ -10,7 +10,7 @@ struct sock;
70225 struct sock_diag_handler {
70226 __u8 family;
70227 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
70228 -};
70229 +} __do_const;
70230
70231 int sock_diag_register(const struct sock_diag_handler *h);
70232 void sock_diag_unregister(const struct sock_diag_handler *h);
70233 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
70234 index 680f9a3..f13aeb0 100644
70235 --- a/include/linux/sonet.h
70236 +++ b/include/linux/sonet.h
70237 @@ -7,7 +7,7 @@
70238 #include <uapi/linux/sonet.h>
70239
70240 struct k_sonet_stats {
70241 -#define __HANDLE_ITEM(i) atomic_t i
70242 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
70243 __SONET_ITEMS
70244 #undef __HANDLE_ITEM
70245 };
70246 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
70247 index 34206b8..3db7f1c 100644
70248 --- a/include/linux/sunrpc/clnt.h
70249 +++ b/include/linux/sunrpc/clnt.h
70250 @@ -96,7 +96,7 @@ struct rpc_procinfo {
70251 unsigned int p_timer; /* Which RTT timer to use */
70252 u32 p_statidx; /* Which procedure to account */
70253 const char * p_name; /* name of procedure */
70254 -};
70255 +} __do_const;
70256
70257 #ifdef __KERNEL__
70258
70259 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
70260 {
70261 switch (sap->sa_family) {
70262 case AF_INET:
70263 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
70264 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
70265 case AF_INET6:
70266 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
70267 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
70268 }
70269 return 0;
70270 }
70271 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
70272 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
70273 const struct sockaddr *src)
70274 {
70275 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
70276 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
70277 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
70278
70279 dsin->sin_family = ssin->sin_family;
70280 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
70281 if (sa->sa_family != AF_INET6)
70282 return 0;
70283
70284 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
70285 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
70286 }
70287
70288 #endif /* __KERNEL__ */
70289 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
70290 index 676ddf5..4c519a1 100644
70291 --- a/include/linux/sunrpc/svc.h
70292 +++ b/include/linux/sunrpc/svc.h
70293 @@ -410,7 +410,7 @@ struct svc_procedure {
70294 unsigned int pc_count; /* call count */
70295 unsigned int pc_cachetype; /* cache info (NFS) */
70296 unsigned int pc_xdrressize; /* maximum size of XDR reply */
70297 -};
70298 +} __do_const;
70299
70300 /*
70301 * Function prototypes.
70302 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
70303 index 0b8e3e6..33e0a01 100644
70304 --- a/include/linux/sunrpc/svc_rdma.h
70305 +++ b/include/linux/sunrpc/svc_rdma.h
70306 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
70307 extern unsigned int svcrdma_max_requests;
70308 extern unsigned int svcrdma_max_req_size;
70309
70310 -extern atomic_t rdma_stat_recv;
70311 -extern atomic_t rdma_stat_read;
70312 -extern atomic_t rdma_stat_write;
70313 -extern atomic_t rdma_stat_sq_starve;
70314 -extern atomic_t rdma_stat_rq_starve;
70315 -extern atomic_t rdma_stat_rq_poll;
70316 -extern atomic_t rdma_stat_rq_prod;
70317 -extern atomic_t rdma_stat_sq_poll;
70318 -extern atomic_t rdma_stat_sq_prod;
70319 +extern atomic_unchecked_t rdma_stat_recv;
70320 +extern atomic_unchecked_t rdma_stat_read;
70321 +extern atomic_unchecked_t rdma_stat_write;
70322 +extern atomic_unchecked_t rdma_stat_sq_starve;
70323 +extern atomic_unchecked_t rdma_stat_rq_starve;
70324 +extern atomic_unchecked_t rdma_stat_rq_poll;
70325 +extern atomic_unchecked_t rdma_stat_rq_prod;
70326 +extern atomic_unchecked_t rdma_stat_sq_poll;
70327 +extern atomic_unchecked_t rdma_stat_sq_prod;
70328
70329 #define RPCRDMA_VERSION 1
70330
70331 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
70332 index dd74084a..7f509d5 100644
70333 --- a/include/linux/sunrpc/svcauth.h
70334 +++ b/include/linux/sunrpc/svcauth.h
70335 @@ -109,7 +109,7 @@ struct auth_ops {
70336 int (*release)(struct svc_rqst *rq);
70337 void (*domain_release)(struct auth_domain *);
70338 int (*set_client)(struct svc_rqst *rq);
70339 -};
70340 +} __do_const;
70341
70342 #define SVC_GARBAGE 1
70343 #define SVC_SYSERR 2
70344 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
70345 index 071d62c..4ccc7ac 100644
70346 --- a/include/linux/swiotlb.h
70347 +++ b/include/linux/swiotlb.h
70348 @@ -59,7 +59,8 @@ extern void
70349
70350 extern void
70351 swiotlb_free_coherent(struct device *hwdev, size_t size,
70352 - void *vaddr, dma_addr_t dma_handle);
70353 + void *vaddr, dma_addr_t dma_handle,
70354 + struct dma_attrs *attrs);
70355
70356 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
70357 unsigned long offset, size_t size,
70358 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
70359 index 27b3b0b..e093dd9 100644
70360 --- a/include/linux/syscore_ops.h
70361 +++ b/include/linux/syscore_ops.h
70362 @@ -16,7 +16,7 @@ struct syscore_ops {
70363 int (*suspend)(void);
70364 void (*resume)(void);
70365 void (*shutdown)(void);
70366 -};
70367 +} __do_const;
70368
70369 extern void register_syscore_ops(struct syscore_ops *ops);
70370 extern void unregister_syscore_ops(struct syscore_ops *ops);
70371 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
70372 index 14a8ff2..af52bad 100644
70373 --- a/include/linux/sysctl.h
70374 +++ b/include/linux/sysctl.h
70375 @@ -34,13 +34,13 @@ struct ctl_table_root;
70376 struct ctl_table_header;
70377 struct ctl_dir;
70378
70379 -typedef struct ctl_table ctl_table;
70380 -
70381 typedef int proc_handler (struct ctl_table *ctl, int write,
70382 void __user *buffer, size_t *lenp, loff_t *ppos);
70383
70384 extern int proc_dostring(struct ctl_table *, int,
70385 void __user *, size_t *, loff_t *);
70386 +extern int proc_dostring_modpriv(struct ctl_table *, int,
70387 + void __user *, size_t *, loff_t *);
70388 extern int proc_dointvec(struct ctl_table *, int,
70389 void __user *, size_t *, loff_t *);
70390 extern int proc_dointvec_minmax(struct ctl_table *, int,
70391 @@ -115,7 +115,9 @@ struct ctl_table
70392 struct ctl_table_poll *poll;
70393 void *extra1;
70394 void *extra2;
70395 -};
70396 +} __do_const;
70397 +typedef struct ctl_table __no_const ctl_table_no_const;
70398 +typedef struct ctl_table ctl_table;
70399
70400 struct ctl_node {
70401 struct rb_node node;
70402 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
70403 index 381f06d..dc16cc7 100644
70404 --- a/include/linux/sysfs.h
70405 +++ b/include/linux/sysfs.h
70406 @@ -31,7 +31,8 @@ struct attribute {
70407 struct lock_class_key *key;
70408 struct lock_class_key skey;
70409 #endif
70410 -};
70411 +} __do_const;
70412 +typedef struct attribute __no_const attribute_no_const;
70413
70414 /**
70415 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
70416 @@ -59,8 +60,8 @@ struct attribute_group {
70417 umode_t (*is_visible)(struct kobject *,
70418 struct attribute *, int);
70419 struct attribute **attrs;
70420 -};
70421 -
70422 +} __do_const;
70423 +typedef struct attribute_group __no_const attribute_group_no_const;
70424
70425
70426 /**
70427 @@ -107,7 +108,8 @@ struct bin_attribute {
70428 char *, loff_t, size_t);
70429 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
70430 struct vm_area_struct *vma);
70431 -};
70432 +} __do_const;
70433 +typedef struct bin_attribute __no_const bin_attribute_no_const;
70434
70435 /**
70436 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
70437 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
70438 index 7faf933..4657127 100644
70439 --- a/include/linux/sysrq.h
70440 +++ b/include/linux/sysrq.h
70441 @@ -15,7 +15,9 @@
70442 #define _LINUX_SYSRQ_H
70443
70444 #include <linux/errno.h>
70445 +#include <linux/compiler.h>
70446 #include <linux/types.h>
70447 +#include <linux/compiler.h>
70448
70449 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
70450 #define SYSRQ_DEFAULT_ENABLE 1
70451 @@ -36,7 +38,7 @@ struct sysrq_key_op {
70452 char *help_msg;
70453 char *action_msg;
70454 int enable_mask;
70455 -};
70456 +} __do_const;
70457
70458 #ifdef CONFIG_MAGIC_SYSRQ
70459
70460 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
70461 index e7e0473..39b7b52 100644
70462 --- a/include/linux/thread_info.h
70463 +++ b/include/linux/thread_info.h
70464 @@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
70465 #error "no set_restore_sigmask() provided and default one won't work"
70466 #endif
70467
70468 +extern void __check_object_size(const void *ptr, unsigned long n, bool to);
70469 +static inline void check_object_size(const void *ptr, unsigned long n, bool to)
70470 +{
70471 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
70472 + if (!__builtin_constant_p(n))
70473 +#endif
70474 + __check_object_size(ptr, n, to);
70475 +}
70476 +
70477 #endif /* __KERNEL__ */
70478
70479 #endif /* _LINUX_THREAD_INFO_H */
70480 diff --git a/include/linux/tty.h b/include/linux/tty.h
70481 index 8db1b56..c16a040 100644
70482 --- a/include/linux/tty.h
70483 +++ b/include/linux/tty.h
70484 @@ -194,7 +194,7 @@ struct tty_port {
70485 const struct tty_port_operations *ops; /* Port operations */
70486 spinlock_t lock; /* Lock protecting tty field */
70487 int blocked_open; /* Waiting to open */
70488 - int count; /* Usage count */
70489 + atomic_t count; /* Usage count */
70490 wait_queue_head_t open_wait; /* Open waiters */
70491 wait_queue_head_t close_wait; /* Close waiters */
70492 wait_queue_head_t delta_msr_wait; /* Modem status change */
70493 @@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
70494 struct tty_struct *tty, struct file *filp);
70495 static inline int tty_port_users(struct tty_port *port)
70496 {
70497 - return port->count + port->blocked_open;
70498 + return atomic_read(&port->count) + port->blocked_open;
70499 }
70500
70501 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
70502 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
70503 index dd976cf..e272742 100644
70504 --- a/include/linux/tty_driver.h
70505 +++ b/include/linux/tty_driver.h
70506 @@ -284,7 +284,7 @@ struct tty_operations {
70507 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
70508 #endif
70509 const struct file_operations *proc_fops;
70510 -};
70511 +} __do_const;
70512
70513 struct tty_driver {
70514 int magic; /* magic number for this structure */
70515 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
70516 index fb79dd8d..07d4773 100644
70517 --- a/include/linux/tty_ldisc.h
70518 +++ b/include/linux/tty_ldisc.h
70519 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
70520
70521 struct module *owner;
70522
70523 - int refcount;
70524 + atomic_t refcount;
70525 };
70526
70527 struct tty_ldisc {
70528 diff --git a/include/linux/types.h b/include/linux/types.h
70529 index 4d118ba..c3ee9bf 100644
70530 --- a/include/linux/types.h
70531 +++ b/include/linux/types.h
70532 @@ -176,10 +176,26 @@ typedef struct {
70533 int counter;
70534 } atomic_t;
70535
70536 +#ifdef CONFIG_PAX_REFCOUNT
70537 +typedef struct {
70538 + int counter;
70539 +} atomic_unchecked_t;
70540 +#else
70541 +typedef atomic_t atomic_unchecked_t;
70542 +#endif
70543 +
70544 #ifdef CONFIG_64BIT
70545 typedef struct {
70546 long counter;
70547 } atomic64_t;
70548 +
70549 +#ifdef CONFIG_PAX_REFCOUNT
70550 +typedef struct {
70551 + long counter;
70552 +} atomic64_unchecked_t;
70553 +#else
70554 +typedef atomic64_t atomic64_unchecked_t;
70555 +#endif
70556 #endif
70557
70558 struct list_head {
70559 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
70560 index 5ca0951..ab496a5 100644
70561 --- a/include/linux/uaccess.h
70562 +++ b/include/linux/uaccess.h
70563 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
70564 long ret; \
70565 mm_segment_t old_fs = get_fs(); \
70566 \
70567 - set_fs(KERNEL_DS); \
70568 pagefault_disable(); \
70569 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
70570 - pagefault_enable(); \
70571 + set_fs(KERNEL_DS); \
70572 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
70573 set_fs(old_fs); \
70574 + pagefault_enable(); \
70575 ret; \
70576 })
70577
70578 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
70579 index 8e522cbc..aa8572d 100644
70580 --- a/include/linux/uidgid.h
70581 +++ b/include/linux/uidgid.h
70582 @@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
70583
70584 #endif /* CONFIG_USER_NS */
70585
70586 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
70587 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
70588 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
70589 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
70590 +
70591 #endif /* _LINUX_UIDGID_H */
70592 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
70593 index 99c1b4d..bb94261 100644
70594 --- a/include/linux/unaligned/access_ok.h
70595 +++ b/include/linux/unaligned/access_ok.h
70596 @@ -6,32 +6,32 @@
70597
70598 static inline u16 get_unaligned_le16(const void *p)
70599 {
70600 - return le16_to_cpup((__le16 *)p);
70601 + return le16_to_cpup((const __le16 *)p);
70602 }
70603
70604 static inline u32 get_unaligned_le32(const void *p)
70605 {
70606 - return le32_to_cpup((__le32 *)p);
70607 + return le32_to_cpup((const __le32 *)p);
70608 }
70609
70610 static inline u64 get_unaligned_le64(const void *p)
70611 {
70612 - return le64_to_cpup((__le64 *)p);
70613 + return le64_to_cpup((const __le64 *)p);
70614 }
70615
70616 static inline u16 get_unaligned_be16(const void *p)
70617 {
70618 - return be16_to_cpup((__be16 *)p);
70619 + return be16_to_cpup((const __be16 *)p);
70620 }
70621
70622 static inline u32 get_unaligned_be32(const void *p)
70623 {
70624 - return be32_to_cpup((__be32 *)p);
70625 + return be32_to_cpup((const __be32 *)p);
70626 }
70627
70628 static inline u64 get_unaligned_be64(const void *p)
70629 {
70630 - return be64_to_cpup((__be64 *)p);
70631 + return be64_to_cpup((const __be64 *)p);
70632 }
70633
70634 static inline void put_unaligned_le16(u16 val, void *p)
70635 diff --git a/include/linux/usb.h b/include/linux/usb.h
70636 index 4d22d0f..ac43c2f 100644
70637 --- a/include/linux/usb.h
70638 +++ b/include/linux/usb.h
70639 @@ -554,7 +554,7 @@ struct usb_device {
70640 int maxchild;
70641
70642 u32 quirks;
70643 - atomic_t urbnum;
70644 + atomic_unchecked_t urbnum;
70645
70646 unsigned long active_duration;
70647
70648 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
70649 index c5d36c6..108f4f9 100644
70650 --- a/include/linux/usb/renesas_usbhs.h
70651 +++ b/include/linux/usb/renesas_usbhs.h
70652 @@ -39,7 +39,7 @@ enum {
70653 */
70654 struct renesas_usbhs_driver_callback {
70655 int (*notify_hotplug)(struct platform_device *pdev);
70656 -};
70657 +} __no_const;
70658
70659 /*
70660 * callback functions for platform
70661 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
70662 index b9bd2e6..4ce0093 100644
70663 --- a/include/linux/user_namespace.h
70664 +++ b/include/linux/user_namespace.h
70665 @@ -21,7 +21,7 @@ struct user_namespace {
70666 struct uid_gid_map uid_map;
70667 struct uid_gid_map gid_map;
70668 struct uid_gid_map projid_map;
70669 - struct kref kref;
70670 + atomic_t count;
70671 struct user_namespace *parent;
70672 kuid_t owner;
70673 kgid_t group;
70674 @@ -35,18 +35,18 @@ extern struct user_namespace init_user_ns;
70675 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
70676 {
70677 if (ns)
70678 - kref_get(&ns->kref);
70679 + atomic_inc(&ns->count);
70680 return ns;
70681 }
70682
70683 extern int create_user_ns(struct cred *new);
70684 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
70685 -extern void free_user_ns(struct kref *kref);
70686 +extern void free_user_ns(struct user_namespace *ns);
70687
70688 static inline void put_user_ns(struct user_namespace *ns)
70689 {
70690 - if (ns)
70691 - kref_put(&ns->kref, free_user_ns);
70692 + if (ns && atomic_dec_and_test(&ns->count))
70693 + free_user_ns(ns);
70694 }
70695
70696 struct seq_operations;
70697 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
70698 index 6f8fbcf..8259001 100644
70699 --- a/include/linux/vermagic.h
70700 +++ b/include/linux/vermagic.h
70701 @@ -25,9 +25,35 @@
70702 #define MODULE_ARCH_VERMAGIC ""
70703 #endif
70704
70705 +#ifdef CONFIG_PAX_REFCOUNT
70706 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
70707 +#else
70708 +#define MODULE_PAX_REFCOUNT ""
70709 +#endif
70710 +
70711 +#ifdef CONSTIFY_PLUGIN
70712 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
70713 +#else
70714 +#define MODULE_CONSTIFY_PLUGIN ""
70715 +#endif
70716 +
70717 +#ifdef STACKLEAK_PLUGIN
70718 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
70719 +#else
70720 +#define MODULE_STACKLEAK_PLUGIN ""
70721 +#endif
70722 +
70723 +#ifdef CONFIG_GRKERNSEC
70724 +#define MODULE_GRSEC "GRSEC "
70725 +#else
70726 +#define MODULE_GRSEC ""
70727 +#endif
70728 +
70729 #define VERMAGIC_STRING \
70730 UTS_RELEASE " " \
70731 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
70732 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
70733 - MODULE_ARCH_VERMAGIC
70734 + MODULE_ARCH_VERMAGIC \
70735 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
70736 + MODULE_GRSEC
70737
70738 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
70739 index 6071e91..ca6a489 100644
70740 --- a/include/linux/vmalloc.h
70741 +++ b/include/linux/vmalloc.h
70742 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
70743 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
70744 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
70745 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
70746 +
70747 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
70748 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
70749 +#endif
70750 +
70751 /* bits [20..32] reserved for arch specific ioremap internals */
70752
70753 /*
70754 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
70755 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
70756 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
70757 unsigned long start, unsigned long end, gfp_t gfp_mask,
70758 - pgprot_t prot, int node, const void *caller);
70759 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
70760 extern void vfree(const void *addr);
70761
70762 extern void *vmap(struct page **pages, unsigned int count,
70763 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
70764 extern void free_vm_area(struct vm_struct *area);
70765
70766 /* for /dev/kmem */
70767 -extern long vread(char *buf, char *addr, unsigned long count);
70768 -extern long vwrite(char *buf, char *addr, unsigned long count);
70769 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
70770 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
70771
70772 /*
70773 * Internals. Dont't use..
70774 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
70775 index a13291f..af51fa3 100644
70776 --- a/include/linux/vmstat.h
70777 +++ b/include/linux/vmstat.h
70778 @@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
70779 /*
70780 * Zone based page accounting with per cpu differentials.
70781 */
70782 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70783 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70784
70785 static inline void zone_page_state_add(long x, struct zone *zone,
70786 enum zone_stat_item item)
70787 {
70788 - atomic_long_add(x, &zone->vm_stat[item]);
70789 - atomic_long_add(x, &vm_stat[item]);
70790 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
70791 + atomic_long_add_unchecked(x, &vm_stat[item]);
70792 }
70793
70794 static inline unsigned long global_page_state(enum zone_stat_item item)
70795 {
70796 - long x = atomic_long_read(&vm_stat[item]);
70797 + long x = atomic_long_read_unchecked(&vm_stat[item]);
70798 #ifdef CONFIG_SMP
70799 if (x < 0)
70800 x = 0;
70801 @@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
70802 static inline unsigned long zone_page_state(struct zone *zone,
70803 enum zone_stat_item item)
70804 {
70805 - long x = atomic_long_read(&zone->vm_stat[item]);
70806 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
70807 #ifdef CONFIG_SMP
70808 if (x < 0)
70809 x = 0;
70810 @@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
70811 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
70812 enum zone_stat_item item)
70813 {
70814 - long x = atomic_long_read(&zone->vm_stat[item]);
70815 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
70816
70817 #ifdef CONFIG_SMP
70818 int cpu;
70819 @@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
70820
70821 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
70822 {
70823 - atomic_long_inc(&zone->vm_stat[item]);
70824 - atomic_long_inc(&vm_stat[item]);
70825 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
70826 + atomic_long_inc_unchecked(&vm_stat[item]);
70827 }
70828
70829 static inline void __inc_zone_page_state(struct page *page,
70830 @@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
70831
70832 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
70833 {
70834 - atomic_long_dec(&zone->vm_stat[item]);
70835 - atomic_long_dec(&vm_stat[item]);
70836 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
70837 + atomic_long_dec_unchecked(&vm_stat[item]);
70838 }
70839
70840 static inline void __dec_zone_page_state(struct page *page,
70841 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
70842 index fdbafc6..b7ffd47 100644
70843 --- a/include/linux/xattr.h
70844 +++ b/include/linux/xattr.h
70845 @@ -28,7 +28,7 @@ struct xattr_handler {
70846 size_t size, int handler_flags);
70847 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
70848 size_t size, int flags, int handler_flags);
70849 -};
70850 +} __do_const;
70851
70852 struct xattr {
70853 char *name;
70854 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
70855 index 95d1c91..6798cca 100644
70856 --- a/include/media/v4l2-dev.h
70857 +++ b/include/media/v4l2-dev.h
70858 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
70859 int (*mmap) (struct file *, struct vm_area_struct *);
70860 int (*open) (struct file *);
70861 int (*release) (struct file *);
70862 -};
70863 +} __do_const;
70864
70865 /*
70866 * Newer version of video_device, handled by videodev2.c
70867 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
70868 index 4118ad1..cb7e25f 100644
70869 --- a/include/media/v4l2-ioctl.h
70870 +++ b/include/media/v4l2-ioctl.h
70871 @@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
70872 bool valid_prio, int cmd, void *arg);
70873 };
70874
70875 -
70876 /* v4l debugging and diagnostics */
70877
70878 /* Debug bitmask flags to be used on V4L2 */
70879 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
70880 index adcbb20..62c2559 100644
70881 --- a/include/net/9p/transport.h
70882 +++ b/include/net/9p/transport.h
70883 @@ -57,7 +57,7 @@ struct p9_trans_module {
70884 int (*cancel) (struct p9_client *, struct p9_req_t *req);
70885 int (*zc_request)(struct p9_client *, struct p9_req_t *,
70886 char *, char *, int , int, int, int);
70887 -};
70888 +} __do_const;
70889
70890 void v9fs_register_trans(struct p9_trans_module *m);
70891 void v9fs_unregister_trans(struct p9_trans_module *m);
70892 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
70893 index 7588ef4..e62d35f 100644
70894 --- a/include/net/bluetooth/l2cap.h
70895 +++ b/include/net/bluetooth/l2cap.h
70896 @@ -552,7 +552,7 @@ struct l2cap_ops {
70897 void (*defer) (struct l2cap_chan *chan);
70898 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
70899 unsigned long len, int nb);
70900 -};
70901 +} __do_const;
70902
70903 struct l2cap_conn {
70904 struct hci_conn *hcon;
70905 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
70906 index 9e5425b..8136ffc 100644
70907 --- a/include/net/caif/cfctrl.h
70908 +++ b/include/net/caif/cfctrl.h
70909 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
70910 void (*radioset_rsp)(void);
70911 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
70912 struct cflayer *client_layer);
70913 -};
70914 +} __no_const;
70915
70916 /* Link Setup Parameters for CAIF-Links. */
70917 struct cfctrl_link_param {
70918 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
70919 struct cfctrl {
70920 struct cfsrvl serv;
70921 struct cfctrl_rsp res;
70922 - atomic_t req_seq_no;
70923 - atomic_t rsp_seq_no;
70924 + atomic_unchecked_t req_seq_no;
70925 + atomic_unchecked_t rsp_seq_no;
70926 struct list_head list;
70927 /* Protects from simultaneous access to first_req list */
70928 spinlock_t info_list_lock;
70929 diff --git a/include/net/flow.h b/include/net/flow.h
70930 index 628e11b..4c475df 100644
70931 --- a/include/net/flow.h
70932 +++ b/include/net/flow.h
70933 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
70934
70935 extern void flow_cache_flush(void);
70936 extern void flow_cache_flush_deferred(void);
70937 -extern atomic_t flow_cache_genid;
70938 +extern atomic_unchecked_t flow_cache_genid;
70939
70940 #endif
70941 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
70942 index bdfbe68..4402ebe 100644
70943 --- a/include/net/genetlink.h
70944 +++ b/include/net/genetlink.h
70945 @@ -118,7 +118,7 @@ struct genl_ops {
70946 struct netlink_callback *cb);
70947 int (*done)(struct netlink_callback *cb);
70948 struct list_head ops_list;
70949 -};
70950 +} __do_const;
70951
70952 extern int genl_register_family(struct genl_family *family);
70953 extern int genl_register_family_with_ops(struct genl_family *family,
70954 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
70955 index e5062c9..48a9a4b 100644
70956 --- a/include/net/gro_cells.h
70957 +++ b/include/net/gro_cells.h
70958 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
70959 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
70960
70961 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
70962 - atomic_long_inc(&dev->rx_dropped);
70963 + atomic_long_inc_unchecked(&dev->rx_dropped);
70964 kfree_skb(skb);
70965 return;
70966 }
70967 @@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
70968 int i;
70969
70970 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
70971 - gcells->cells = kcalloc(sizeof(struct gro_cell),
70972 - gcells->gro_cells_mask + 1,
70973 + gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
70974 + sizeof(struct gro_cell),
70975 GFP_KERNEL);
70976 if (!gcells->cells)
70977 return -ENOMEM;
70978 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
70979 index 1832927..ce39aea 100644
70980 --- a/include/net/inet_connection_sock.h
70981 +++ b/include/net/inet_connection_sock.h
70982 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
70983 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
70984 int (*bind_conflict)(const struct sock *sk,
70985 const struct inet_bind_bucket *tb, bool relax);
70986 -};
70987 +} __do_const;
70988
70989 /** inet_connection_sock - INET connection oriented sock
70990 *
70991 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
70992 index 53f464d..ba76aaa 100644
70993 --- a/include/net/inetpeer.h
70994 +++ b/include/net/inetpeer.h
70995 @@ -47,8 +47,8 @@ struct inet_peer {
70996 */
70997 union {
70998 struct {
70999 - atomic_t rid; /* Frag reception counter */
71000 - atomic_t ip_id_count; /* IP ID for the next packet */
71001 + atomic_unchecked_t rid; /* Frag reception counter */
71002 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
71003 };
71004 struct rcu_head rcu;
71005 struct inet_peer *gc_next;
71006 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
71007 more++;
71008 inet_peer_refcheck(p);
71009 do {
71010 - old = atomic_read(&p->ip_id_count);
71011 + old = atomic_read_unchecked(&p->ip_id_count);
71012 new = old + more;
71013 if (!new)
71014 new = 1;
71015 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
71016 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
71017 return new;
71018 }
71019
71020 diff --git a/include/net/ip.h b/include/net/ip.h
71021 index a68f838..74518ab 100644
71022 --- a/include/net/ip.h
71023 +++ b/include/net/ip.h
71024 @@ -202,7 +202,7 @@ extern struct local_ports {
71025 } sysctl_local_ports;
71026 extern void inet_get_local_port_range(int *low, int *high);
71027
71028 -extern unsigned long *sysctl_local_reserved_ports;
71029 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
71030 static inline int inet_is_reserved_local_port(int port)
71031 {
71032 return test_bit(port, sysctl_local_reserved_ports);
71033 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
71034 index 9497be1..5a4fafe 100644
71035 --- a/include/net/ip_fib.h
71036 +++ b/include/net/ip_fib.h
71037 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
71038
71039 #define FIB_RES_SADDR(net, res) \
71040 ((FIB_RES_NH(res).nh_saddr_genid == \
71041 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
71042 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
71043 FIB_RES_NH(res).nh_saddr : \
71044 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
71045 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
71046 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
71047 index 68c69d5..bdab192 100644
71048 --- a/include/net/ip_vs.h
71049 +++ b/include/net/ip_vs.h
71050 @@ -599,7 +599,7 @@ struct ip_vs_conn {
71051 struct ip_vs_conn *control; /* Master control connection */
71052 atomic_t n_control; /* Number of controlled ones */
71053 struct ip_vs_dest *dest; /* real server */
71054 - atomic_t in_pkts; /* incoming packet counter */
71055 + atomic_unchecked_t in_pkts; /* incoming packet counter */
71056
71057 /* packet transmitter for different forwarding methods. If it
71058 mangles the packet, it must return NF_DROP or better NF_STOLEN,
71059 @@ -737,7 +737,7 @@ struct ip_vs_dest {
71060 __be16 port; /* port number of the server */
71061 union nf_inet_addr addr; /* IP address of the server */
71062 volatile unsigned int flags; /* dest status flags */
71063 - atomic_t conn_flags; /* flags to copy to conn */
71064 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
71065 atomic_t weight; /* server weight */
71066
71067 atomic_t refcnt; /* reference counter */
71068 @@ -980,11 +980,11 @@ struct netns_ipvs {
71069 /* ip_vs_lblc */
71070 int sysctl_lblc_expiration;
71071 struct ctl_table_header *lblc_ctl_header;
71072 - struct ctl_table *lblc_ctl_table;
71073 + ctl_table_no_const *lblc_ctl_table;
71074 /* ip_vs_lblcr */
71075 int sysctl_lblcr_expiration;
71076 struct ctl_table_header *lblcr_ctl_header;
71077 - struct ctl_table *lblcr_ctl_table;
71078 + ctl_table_no_const *lblcr_ctl_table;
71079 /* ip_vs_est */
71080 struct list_head est_list; /* estimator list */
71081 spinlock_t est_lock;
71082 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
71083 index 80ffde3..968b0f4 100644
71084 --- a/include/net/irda/ircomm_tty.h
71085 +++ b/include/net/irda/ircomm_tty.h
71086 @@ -35,6 +35,7 @@
71087 #include <linux/termios.h>
71088 #include <linux/timer.h>
71089 #include <linux/tty.h> /* struct tty_struct */
71090 +#include <asm/local.h>
71091
71092 #include <net/irda/irias_object.h>
71093 #include <net/irda/ircomm_core.h>
71094 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
71095 index cc7c197..9f2da2a 100644
71096 --- a/include/net/iucv/af_iucv.h
71097 +++ b/include/net/iucv/af_iucv.h
71098 @@ -141,7 +141,7 @@ struct iucv_sock {
71099 struct iucv_sock_list {
71100 struct hlist_head head;
71101 rwlock_t lock;
71102 - atomic_t autobind_name;
71103 + atomic_unchecked_t autobind_name;
71104 };
71105
71106 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
71107 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
71108 index df83f69..9b640b8 100644
71109 --- a/include/net/llc_c_ac.h
71110 +++ b/include/net/llc_c_ac.h
71111 @@ -87,7 +87,7 @@
71112 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
71113 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
71114
71115 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71116 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71117
71118 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
71119 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
71120 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
71121 index 6ca3113..f8026dd 100644
71122 --- a/include/net/llc_c_ev.h
71123 +++ b/include/net/llc_c_ev.h
71124 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
71125 return (struct llc_conn_state_ev *)skb->cb;
71126 }
71127
71128 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71129 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71130 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71131 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71132
71133 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
71134 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
71135 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
71136 index 0e79cfb..f46db31 100644
71137 --- a/include/net/llc_c_st.h
71138 +++ b/include/net/llc_c_st.h
71139 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
71140 u8 next_state;
71141 llc_conn_ev_qfyr_t *ev_qualifiers;
71142 llc_conn_action_t *ev_actions;
71143 -};
71144 +} __do_const;
71145
71146 struct llc_conn_state {
71147 u8 current_state;
71148 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
71149 index 37a3bbd..55a4241 100644
71150 --- a/include/net/llc_s_ac.h
71151 +++ b/include/net/llc_s_ac.h
71152 @@ -23,7 +23,7 @@
71153 #define SAP_ACT_TEST_IND 9
71154
71155 /* All action functions must look like this */
71156 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71157 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71158
71159 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
71160 struct sk_buff *skb);
71161 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
71162 index 567c681..cd73ac0 100644
71163 --- a/include/net/llc_s_st.h
71164 +++ b/include/net/llc_s_st.h
71165 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
71166 llc_sap_ev_t ev;
71167 u8 next_state;
71168 llc_sap_action_t *ev_actions;
71169 -};
71170 +} __do_const;
71171
71172 struct llc_sap_state {
71173 u8 curr_state;
71174 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
71175 index ee50c5e..1bc3b1a 100644
71176 --- a/include/net/mac80211.h
71177 +++ b/include/net/mac80211.h
71178 @@ -3996,7 +3996,7 @@ struct rate_control_ops {
71179 void (*add_sta_debugfs)(void *priv, void *priv_sta,
71180 struct dentry *dir);
71181 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
71182 -};
71183 +} __do_const;
71184
71185 static inline int rate_supported(struct ieee80211_sta *sta,
71186 enum ieee80211_band band,
71187 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
71188 index 0dab173..1b76af0 100644
71189 --- a/include/net/neighbour.h
71190 +++ b/include/net/neighbour.h
71191 @@ -123,7 +123,7 @@ struct neigh_ops {
71192 void (*error_report)(struct neighbour *, struct sk_buff *);
71193 int (*output)(struct neighbour *, struct sk_buff *);
71194 int (*connected_output)(struct neighbour *, struct sk_buff *);
71195 -};
71196 +} __do_const;
71197
71198 struct pneigh_entry {
71199 struct pneigh_entry *next;
71200 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
71201 index de644bc..351fd4e 100644
71202 --- a/include/net/net_namespace.h
71203 +++ b/include/net/net_namespace.h
71204 @@ -115,7 +115,7 @@ struct net {
71205 #endif
71206 struct netns_ipvs *ipvs;
71207 struct sock *diag_nlsk;
71208 - atomic_t rt_genid;
71209 + atomic_unchecked_t rt_genid;
71210 };
71211
71212 /*
71213 @@ -282,7 +282,7 @@ struct pernet_operations {
71214 void (*exit_batch)(struct list_head *net_exit_list);
71215 int *id;
71216 size_t size;
71217 -};
71218 +} __do_const;
71219
71220 /*
71221 * Use these carefully. If you implement a network device and it
71222 @@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
71223
71224 static inline int rt_genid(struct net *net)
71225 {
71226 - return atomic_read(&net->rt_genid);
71227 + return atomic_read_unchecked(&net->rt_genid);
71228 }
71229
71230 static inline void rt_genid_bump(struct net *net)
71231 {
71232 - atomic_inc(&net->rt_genid);
71233 + atomic_inc_unchecked(&net->rt_genid);
71234 }
71235
71236 #endif /* __NET_NET_NAMESPACE_H */
71237 diff --git a/include/net/netdma.h b/include/net/netdma.h
71238 index 8ba8ce2..99b7fff 100644
71239 --- a/include/net/netdma.h
71240 +++ b/include/net/netdma.h
71241 @@ -24,7 +24,7 @@
71242 #include <linux/dmaengine.h>
71243 #include <linux/skbuff.h>
71244
71245 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71246 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71247 struct sk_buff *skb, int offset, struct iovec *to,
71248 size_t len, struct dma_pinned_list *pinned_list);
71249
71250 diff --git a/include/net/netlink.h b/include/net/netlink.h
71251 index 9690b0f..87aded7 100644
71252 --- a/include/net/netlink.h
71253 +++ b/include/net/netlink.h
71254 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
71255 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
71256 {
71257 if (mark)
71258 - skb_trim(skb, (unsigned char *) mark - skb->data);
71259 + skb_trim(skb, (const unsigned char *) mark - skb->data);
71260 }
71261
71262 /**
71263 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
71264 index 923cb20..deae816 100644
71265 --- a/include/net/netns/conntrack.h
71266 +++ b/include/net/netns/conntrack.h
71267 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
71268 struct nf_proto_net {
71269 #ifdef CONFIG_SYSCTL
71270 struct ctl_table_header *ctl_table_header;
71271 - struct ctl_table *ctl_table;
71272 + ctl_table_no_const *ctl_table;
71273 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
71274 struct ctl_table_header *ctl_compat_header;
71275 - struct ctl_table *ctl_compat_table;
71276 + ctl_table_no_const *ctl_compat_table;
71277 #endif
71278 #endif
71279 unsigned int users;
71280 @@ -58,7 +58,7 @@ struct nf_ip_net {
71281 struct nf_icmp_net icmpv6;
71282 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
71283 struct ctl_table_header *ctl_table_header;
71284 - struct ctl_table *ctl_table;
71285 + ctl_table_no_const *ctl_table;
71286 #endif
71287 };
71288
71289 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
71290 index 2ae2b83..dbdc85e 100644
71291 --- a/include/net/netns/ipv4.h
71292 +++ b/include/net/netns/ipv4.h
71293 @@ -64,7 +64,7 @@ struct netns_ipv4 {
71294 kgid_t sysctl_ping_group_range[2];
71295 long sysctl_tcp_mem[3];
71296
71297 - atomic_t dev_addr_genid;
71298 + atomic_unchecked_t dev_addr_genid;
71299
71300 #ifdef CONFIG_IP_MROUTE
71301 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
71302 diff --git a/include/net/protocol.h b/include/net/protocol.h
71303 index 047c047..b9dad15 100644
71304 --- a/include/net/protocol.h
71305 +++ b/include/net/protocol.h
71306 @@ -44,7 +44,7 @@ struct net_protocol {
71307 void (*err_handler)(struct sk_buff *skb, u32 info);
71308 unsigned int no_policy:1,
71309 netns_ok:1;
71310 -};
71311 +} __do_const;
71312
71313 #if IS_ENABLED(CONFIG_IPV6)
71314 struct inet6_protocol {
71315 @@ -57,7 +57,7 @@ struct inet6_protocol {
71316 u8 type, u8 code, int offset,
71317 __be32 info);
71318 unsigned int flags; /* INET6_PROTO_xxx */
71319 -};
71320 +} __do_const;
71321
71322 #define INET6_PROTO_NOPOLICY 0x1
71323 #define INET6_PROTO_FINAL 0x2
71324 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
71325 index 5a15fab..d799ea7 100644
71326 --- a/include/net/rtnetlink.h
71327 +++ b/include/net/rtnetlink.h
71328 @@ -81,7 +81,7 @@ struct rtnl_link_ops {
71329 const struct net_device *dev);
71330 unsigned int (*get_num_tx_queues)(void);
71331 unsigned int (*get_num_rx_queues)(void);
71332 -};
71333 +} __do_const;
71334
71335 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
71336 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
71337 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
71338 index 7fdf298..197e9f7 100644
71339 --- a/include/net/sctp/sctp.h
71340 +++ b/include/net/sctp/sctp.h
71341 @@ -330,9 +330,9 @@ do { \
71342
71343 #else /* SCTP_DEBUG */
71344
71345 -#define SCTP_DEBUG_PRINTK(whatever...)
71346 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
71347 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
71348 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
71349 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
71350 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
71351 #define SCTP_ENABLE_DEBUG
71352 #define SCTP_DISABLE_DEBUG
71353 #define SCTP_ASSERT(expr, str, func)
71354 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
71355 index 2a82d13..62a31c2 100644
71356 --- a/include/net/sctp/sm.h
71357 +++ b/include/net/sctp/sm.h
71358 @@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
71359 typedef struct {
71360 sctp_state_fn_t *fn;
71361 const char *name;
71362 -} sctp_sm_table_entry_t;
71363 +} __do_const sctp_sm_table_entry_t;
71364
71365 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
71366 * currently in use.
71367 @@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
71368 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
71369
71370 /* Extern declarations for major data structures. */
71371 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
71372 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
71373
71374
71375 /* Get the size of a DATA chunk payload. */
71376 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
71377 index fdeb85a..1329d95 100644
71378 --- a/include/net/sctp/structs.h
71379 +++ b/include/net/sctp/structs.h
71380 @@ -517,7 +517,7 @@ struct sctp_pf {
71381 struct sctp_association *asoc);
71382 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
71383 struct sctp_af *af;
71384 -};
71385 +} __do_const;
71386
71387
71388 /* Structure to track chunk fragments that have been acked, but peer
71389 diff --git a/include/net/sock.h b/include/net/sock.h
71390 index 25afaa0..8bb0070 100644
71391 --- a/include/net/sock.h
71392 +++ b/include/net/sock.h
71393 @@ -322,7 +322,7 @@ struct sock {
71394 #ifdef CONFIG_RPS
71395 __u32 sk_rxhash;
71396 #endif
71397 - atomic_t sk_drops;
71398 + atomic_unchecked_t sk_drops;
71399 int sk_rcvbuf;
71400
71401 struct sk_filter __rcu *sk_filter;
71402 @@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
71403 }
71404
71405 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
71406 - char __user *from, char *to,
71407 + char __user *from, unsigned char *to,
71408 int copy, int offset)
71409 {
71410 if (skb->ip_summed == CHECKSUM_NONE) {
71411 @@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
71412 }
71413 }
71414
71415 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
71416 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
71417
71418 /**
71419 * sk_page_frag - return an appropriate page_frag
71420 diff --git a/include/net/tcp.h b/include/net/tcp.h
71421 index aed42c7..43890c6 100644
71422 --- a/include/net/tcp.h
71423 +++ b/include/net/tcp.h
71424 @@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
71425 extern void tcp_xmit_retransmit_queue(struct sock *);
71426 extern void tcp_simple_retransmit(struct sock *);
71427 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
71428 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
71429 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
71430
71431 extern void tcp_send_probe0(struct sock *);
71432 extern void tcp_send_partial(struct sock *);
71433 @@ -701,8 +701,8 @@ struct tcp_skb_cb {
71434 struct inet6_skb_parm h6;
71435 #endif
71436 } header; /* For incoming frames */
71437 - __u32 seq; /* Starting sequence number */
71438 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
71439 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
71440 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
71441 __u32 when; /* used to compute rtt's */
71442 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
71443
71444 @@ -716,7 +716,7 @@ struct tcp_skb_cb {
71445
71446 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
71447 /* 1 byte hole */
71448 - __u32 ack_seq; /* Sequence number ACK'd */
71449 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
71450 };
71451
71452 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
71453 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
71454 index 63445ed..d6fc34f 100644
71455 --- a/include/net/xfrm.h
71456 +++ b/include/net/xfrm.h
71457 @@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
71458 struct net_device *dev,
71459 const struct flowi *fl);
71460 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
71461 -};
71462 +} __do_const;
71463
71464 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
71465 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
71466 @@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
71467 struct sk_buff *skb);
71468 int (*transport_finish)(struct sk_buff *skb,
71469 int async);
71470 -};
71471 +} __do_const;
71472
71473 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
71474 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
71475 @@ -423,7 +423,7 @@ struct xfrm_mode {
71476 struct module *owner;
71477 unsigned int encap;
71478 int flags;
71479 -};
71480 +} __do_const;
71481
71482 /* Flags for xfrm_mode. */
71483 enum {
71484 @@ -514,7 +514,7 @@ struct xfrm_policy {
71485 struct timer_list timer;
71486
71487 struct flow_cache_object flo;
71488 - atomic_t genid;
71489 + atomic_unchecked_t genid;
71490 u32 priority;
71491 u32 index;
71492 struct xfrm_mark mark;
71493 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
71494 index 1a046b1..ee0bef0 100644
71495 --- a/include/rdma/iw_cm.h
71496 +++ b/include/rdma/iw_cm.h
71497 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
71498 int backlog);
71499
71500 int (*destroy_listen)(struct iw_cm_id *cm_id);
71501 -};
71502 +} __no_const;
71503
71504 /**
71505 * iw_create_cm_id - Create an IW CM identifier.
71506 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
71507 index 399162b..b337f1a 100644
71508 --- a/include/scsi/libfc.h
71509 +++ b/include/scsi/libfc.h
71510 @@ -762,6 +762,7 @@ struct libfc_function_template {
71511 */
71512 void (*disc_stop_final) (struct fc_lport *);
71513 };
71514 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
71515
71516 /**
71517 * struct fc_disc - Discovery context
71518 @@ -866,7 +867,7 @@ struct fc_lport {
71519 struct fc_vport *vport;
71520
71521 /* Operational Information */
71522 - struct libfc_function_template tt;
71523 + libfc_function_template_no_const tt;
71524 u8 link_up;
71525 u8 qfull;
71526 enum fc_lport_state state;
71527 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
71528 index e65c62e..aa2e5a2 100644
71529 --- a/include/scsi/scsi_device.h
71530 +++ b/include/scsi/scsi_device.h
71531 @@ -170,9 +170,9 @@ struct scsi_device {
71532 unsigned int max_device_blocked; /* what device_blocked counts down from */
71533 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
71534
71535 - atomic_t iorequest_cnt;
71536 - atomic_t iodone_cnt;
71537 - atomic_t ioerr_cnt;
71538 + atomic_unchecked_t iorequest_cnt;
71539 + atomic_unchecked_t iodone_cnt;
71540 + atomic_unchecked_t ioerr_cnt;
71541
71542 struct device sdev_gendev,
71543 sdev_dev;
71544 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
71545 index b797e8f..8e2c3aa 100644
71546 --- a/include/scsi/scsi_transport_fc.h
71547 +++ b/include/scsi/scsi_transport_fc.h
71548 @@ -751,7 +751,8 @@ struct fc_function_template {
71549 unsigned long show_host_system_hostname:1;
71550
71551 unsigned long disable_target_scan:1;
71552 -};
71553 +} __do_const;
71554 +typedef struct fc_function_template __no_const fc_function_template_no_const;
71555
71556
71557 /**
71558 diff --git a/include/sound/soc.h b/include/sound/soc.h
71559 index bc56738..a4be132 100644
71560 --- a/include/sound/soc.h
71561 +++ b/include/sound/soc.h
71562 @@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
71563 /* probe ordering - for components with runtime dependencies */
71564 int probe_order;
71565 int remove_order;
71566 -};
71567 +} __do_const;
71568
71569 /* SoC platform interface */
71570 struct snd_soc_platform_driver {
71571 @@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
71572 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
71573 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
71574 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
71575 -};
71576 +} __do_const;
71577
71578 struct snd_soc_platform {
71579 const char *name;
71580 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
71581 index 663e34a..91b306a 100644
71582 --- a/include/target/target_core_base.h
71583 +++ b/include/target/target_core_base.h
71584 @@ -654,7 +654,7 @@ struct se_device {
71585 spinlock_t stats_lock;
71586 /* Active commands on this virtual SE device */
71587 atomic_t simple_cmds;
71588 - atomic_t dev_ordered_id;
71589 + atomic_unchecked_t dev_ordered_id;
71590 atomic_t dev_ordered_sync;
71591 atomic_t dev_qf_count;
71592 int export_count;
71593 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
71594 new file mode 100644
71595 index 0000000..fb634b7
71596 --- /dev/null
71597 +++ b/include/trace/events/fs.h
71598 @@ -0,0 +1,53 @@
71599 +#undef TRACE_SYSTEM
71600 +#define TRACE_SYSTEM fs
71601 +
71602 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
71603 +#define _TRACE_FS_H
71604 +
71605 +#include <linux/fs.h>
71606 +#include <linux/tracepoint.h>
71607 +
71608 +TRACE_EVENT(do_sys_open,
71609 +
71610 + TP_PROTO(const char *filename, int flags, int mode),
71611 +
71612 + TP_ARGS(filename, flags, mode),
71613 +
71614 + TP_STRUCT__entry(
71615 + __string( filename, filename )
71616 + __field( int, flags )
71617 + __field( int, mode )
71618 + ),
71619 +
71620 + TP_fast_assign(
71621 + __assign_str(filename, filename);
71622 + __entry->flags = flags;
71623 + __entry->mode = mode;
71624 + ),
71625 +
71626 + TP_printk("\"%s\" %x %o",
71627 + __get_str(filename), __entry->flags, __entry->mode)
71628 +);
71629 +
71630 +TRACE_EVENT(open_exec,
71631 +
71632 + TP_PROTO(const char *filename),
71633 +
71634 + TP_ARGS(filename),
71635 +
71636 + TP_STRUCT__entry(
71637 + __string( filename, filename )
71638 + ),
71639 +
71640 + TP_fast_assign(
71641 + __assign_str(filename, filename);
71642 + ),
71643 +
71644 + TP_printk("\"%s\"",
71645 + __get_str(filename))
71646 +);
71647 +
71648 +#endif /* _TRACE_FS_H */
71649 +
71650 +/* This part must be outside protection */
71651 +#include <trace/define_trace.h>
71652 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
71653 index 1c09820..7f5ec79 100644
71654 --- a/include/trace/events/irq.h
71655 +++ b/include/trace/events/irq.h
71656 @@ -36,7 +36,7 @@ struct softirq_action;
71657 */
71658 TRACE_EVENT(irq_handler_entry,
71659
71660 - TP_PROTO(int irq, struct irqaction *action),
71661 + TP_PROTO(int irq, const struct irqaction *action),
71662
71663 TP_ARGS(irq, action),
71664
71665 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
71666 */
71667 TRACE_EVENT(irq_handler_exit,
71668
71669 - TP_PROTO(int irq, struct irqaction *action, int ret),
71670 + TP_PROTO(int irq, const struct irqaction *action, int ret),
71671
71672 TP_ARGS(irq, action, ret),
71673
71674 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
71675 index 7caf44c..23c6f27 100644
71676 --- a/include/uapi/linux/a.out.h
71677 +++ b/include/uapi/linux/a.out.h
71678 @@ -39,6 +39,14 @@ enum machine_type {
71679 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
71680 };
71681
71682 +/* Constants for the N_FLAGS field */
71683 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
71684 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
71685 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
71686 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
71687 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
71688 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
71689 +
71690 #if !defined (N_MAGIC)
71691 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
71692 #endif
71693 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
71694 index d876736..b36014e 100644
71695 --- a/include/uapi/linux/byteorder/little_endian.h
71696 +++ b/include/uapi/linux/byteorder/little_endian.h
71697 @@ -42,51 +42,51 @@
71698
71699 static inline __le64 __cpu_to_le64p(const __u64 *p)
71700 {
71701 - return (__force __le64)*p;
71702 + return (__force const __le64)*p;
71703 }
71704 static inline __u64 __le64_to_cpup(const __le64 *p)
71705 {
71706 - return (__force __u64)*p;
71707 + return (__force const __u64)*p;
71708 }
71709 static inline __le32 __cpu_to_le32p(const __u32 *p)
71710 {
71711 - return (__force __le32)*p;
71712 + return (__force const __le32)*p;
71713 }
71714 static inline __u32 __le32_to_cpup(const __le32 *p)
71715 {
71716 - return (__force __u32)*p;
71717 + return (__force const __u32)*p;
71718 }
71719 static inline __le16 __cpu_to_le16p(const __u16 *p)
71720 {
71721 - return (__force __le16)*p;
71722 + return (__force const __le16)*p;
71723 }
71724 static inline __u16 __le16_to_cpup(const __le16 *p)
71725 {
71726 - return (__force __u16)*p;
71727 + return (__force const __u16)*p;
71728 }
71729 static inline __be64 __cpu_to_be64p(const __u64 *p)
71730 {
71731 - return (__force __be64)__swab64p(p);
71732 + return (__force const __be64)__swab64p(p);
71733 }
71734 static inline __u64 __be64_to_cpup(const __be64 *p)
71735 {
71736 - return __swab64p((__u64 *)p);
71737 + return __swab64p((const __u64 *)p);
71738 }
71739 static inline __be32 __cpu_to_be32p(const __u32 *p)
71740 {
71741 - return (__force __be32)__swab32p(p);
71742 + return (__force const __be32)__swab32p(p);
71743 }
71744 static inline __u32 __be32_to_cpup(const __be32 *p)
71745 {
71746 - return __swab32p((__u32 *)p);
71747 + return __swab32p((const __u32 *)p);
71748 }
71749 static inline __be16 __cpu_to_be16p(const __u16 *p)
71750 {
71751 - return (__force __be16)__swab16p(p);
71752 + return (__force const __be16)__swab16p(p);
71753 }
71754 static inline __u16 __be16_to_cpup(const __be16 *p)
71755 {
71756 - return __swab16p((__u16 *)p);
71757 + return __swab16p((const __u16 *)p);
71758 }
71759 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
71760 #define __le64_to_cpus(x) do { (void)(x); } while (0)
71761 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
71762 index 126a817..d522bd1 100644
71763 --- a/include/uapi/linux/elf.h
71764 +++ b/include/uapi/linux/elf.h
71765 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
71766 #define PT_GNU_EH_FRAME 0x6474e550
71767
71768 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
71769 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
71770 +
71771 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
71772 +
71773 +/* Constants for the e_flags field */
71774 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
71775 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
71776 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
71777 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
71778 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
71779 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
71780
71781 /*
71782 * Extended Numbering
71783 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
71784 #define DT_DEBUG 21
71785 #define DT_TEXTREL 22
71786 #define DT_JMPREL 23
71787 +#define DT_FLAGS 30
71788 + #define DF_TEXTREL 0x00000004
71789 #define DT_ENCODING 32
71790 #define OLD_DT_LOOS 0x60000000
71791 #define DT_LOOS 0x6000000d
71792 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
71793 #define PF_W 0x2
71794 #define PF_X 0x1
71795
71796 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
71797 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
71798 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
71799 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
71800 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
71801 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
71802 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
71803 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
71804 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
71805 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
71806 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
71807 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
71808 +
71809 typedef struct elf32_phdr{
71810 Elf32_Word p_type;
71811 Elf32_Off p_offset;
71812 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
71813 #define EI_OSABI 7
71814 #define EI_PAD 8
71815
71816 +#define EI_PAX 14
71817 +
71818 #define ELFMAG0 0x7f /* EI_MAG */
71819 #define ELFMAG1 'E'
71820 #define ELFMAG2 'L'
71821 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
71822 index aa169c4..6a2771d 100644
71823 --- a/include/uapi/linux/personality.h
71824 +++ b/include/uapi/linux/personality.h
71825 @@ -30,6 +30,7 @@ enum {
71826 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
71827 ADDR_NO_RANDOMIZE | \
71828 ADDR_COMPAT_LAYOUT | \
71829 + ADDR_LIMIT_3GB | \
71830 MMAP_PAGE_ZERO)
71831
71832 /*
71833 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
71834 index 7530e74..e714828 100644
71835 --- a/include/uapi/linux/screen_info.h
71836 +++ b/include/uapi/linux/screen_info.h
71837 @@ -43,7 +43,8 @@ struct screen_info {
71838 __u16 pages; /* 0x32 */
71839 __u16 vesa_attributes; /* 0x34 */
71840 __u32 capabilities; /* 0x36 */
71841 - __u8 _reserved[6]; /* 0x3a */
71842 + __u16 vesapm_size; /* 0x3a */
71843 + __u8 _reserved[4]; /* 0x3c */
71844 } __attribute__((packed));
71845
71846 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
71847 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
71848 index 6d67213..8dab561 100644
71849 --- a/include/uapi/linux/sysctl.h
71850 +++ b/include/uapi/linux/sysctl.h
71851 @@ -155,7 +155,11 @@ enum
71852 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
71853 };
71854
71855 -
71856 +#ifdef CONFIG_PAX_SOFTMODE
71857 +enum {
71858 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
71859 +};
71860 +#endif
71861
71862 /* CTL_VM names: */
71863 enum
71864 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
71865 index 26607bd..588b65f 100644
71866 --- a/include/uapi/linux/xattr.h
71867 +++ b/include/uapi/linux/xattr.h
71868 @@ -60,5 +60,9 @@
71869 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
71870 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
71871
71872 +/* User namespace */
71873 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
71874 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
71875 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
71876
71877 #endif /* _UAPI_LINUX_XATTR_H */
71878 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
71879 index f9466fa..f4e2b81 100644
71880 --- a/include/video/udlfb.h
71881 +++ b/include/video/udlfb.h
71882 @@ -53,10 +53,10 @@ struct dlfb_data {
71883 u32 pseudo_palette[256];
71884 int blank_mode; /*one of FB_BLANK_ */
71885 /* blit-only rendering path metrics, exposed through sysfs */
71886 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
71887 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
71888 - atomic_t bytes_sent; /* to usb, after compression including overhead */
71889 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
71890 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
71891 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
71892 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
71893 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
71894 };
71895
71896 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
71897 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
71898 index 0993a22..32ba2fe 100644
71899 --- a/include/video/uvesafb.h
71900 +++ b/include/video/uvesafb.h
71901 @@ -177,6 +177,7 @@ struct uvesafb_par {
71902 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
71903 u8 pmi_setpal; /* PMI for palette changes */
71904 u16 *pmi_base; /* protected mode interface location */
71905 + u8 *pmi_code; /* protected mode code location */
71906 void *pmi_start;
71907 void *pmi_pal;
71908 u8 *vbe_state_orig; /*
71909 diff --git a/init/Kconfig b/init/Kconfig
71910 index be8b7f5..1eeca9b 100644
71911 --- a/init/Kconfig
71912 +++ b/init/Kconfig
71913 @@ -990,6 +990,7 @@ endif # CGROUPS
71914
71915 config CHECKPOINT_RESTORE
71916 bool "Checkpoint/restore support" if EXPERT
71917 + depends on !GRKERNSEC
71918 default n
71919 help
71920 Enables additional kernel features in a sake of checkpoint/restore.
71921 @@ -1468,7 +1469,7 @@ config SLUB_DEBUG
71922
71923 config COMPAT_BRK
71924 bool "Disable heap randomization"
71925 - default y
71926 + default n
71927 help
71928 Randomizing heap placement makes heap exploits harder, but it
71929 also breaks ancient binaries (including anything libc5 based).
71930 @@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
71931 config STOP_MACHINE
71932 bool
71933 default y
71934 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
71935 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
71936 help
71937 Need stop_machine() primitive.
71938
71939 diff --git a/init/Makefile b/init/Makefile
71940 index 7bc47ee..6da2dc7 100644
71941 --- a/init/Makefile
71942 +++ b/init/Makefile
71943 @@ -2,6 +2,9 @@
71944 # Makefile for the linux kernel.
71945 #
71946
71947 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
71948 +asflags-y := $(GCC_PLUGINS_AFLAGS)
71949 +
71950 obj-y := main.o version.o mounts.o
71951 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
71952 obj-y += noinitramfs.o
71953 diff --git a/init/do_mounts.c b/init/do_mounts.c
71954 index 1d1b634..a1c810f 100644
71955 --- a/init/do_mounts.c
71956 +++ b/init/do_mounts.c
71957 @@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
71958 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
71959 {
71960 struct super_block *s;
71961 - int err = sys_mount(name, "/root", fs, flags, data);
71962 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
71963 if (err)
71964 return err;
71965
71966 - sys_chdir("/root");
71967 + sys_chdir((const char __force_user *)"/root");
71968 s = current->fs->pwd.dentry->d_sb;
71969 ROOT_DEV = s->s_dev;
71970 printk(KERN_INFO
71971 @@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
71972 va_start(args, fmt);
71973 vsprintf(buf, fmt, args);
71974 va_end(args);
71975 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
71976 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
71977 if (fd >= 0) {
71978 sys_ioctl(fd, FDEJECT, 0);
71979 sys_close(fd);
71980 }
71981 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
71982 - fd = sys_open("/dev/console", O_RDWR, 0);
71983 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
71984 if (fd >= 0) {
71985 sys_ioctl(fd, TCGETS, (long)&termios);
71986 termios.c_lflag &= ~ICANON;
71987 sys_ioctl(fd, TCSETSF, (long)&termios);
71988 - sys_read(fd, &c, 1);
71989 + sys_read(fd, (char __user *)&c, 1);
71990 termios.c_lflag |= ICANON;
71991 sys_ioctl(fd, TCSETSF, (long)&termios);
71992 sys_close(fd);
71993 @@ -585,6 +585,6 @@ void __init prepare_namespace(void)
71994 mount_root();
71995 out:
71996 devtmpfs_mount("dev");
71997 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
71998 - sys_chroot(".");
71999 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
72000 + sys_chroot((const char __force_user *)".");
72001 }
72002 diff --git a/init/do_mounts.h b/init/do_mounts.h
72003 index f5b978a..69dbfe8 100644
72004 --- a/init/do_mounts.h
72005 +++ b/init/do_mounts.h
72006 @@ -15,15 +15,15 @@ extern int root_mountflags;
72007
72008 static inline int create_dev(char *name, dev_t dev)
72009 {
72010 - sys_unlink(name);
72011 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
72012 + sys_unlink((char __force_user *)name);
72013 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
72014 }
72015
72016 #if BITS_PER_LONG == 32
72017 static inline u32 bstat(char *name)
72018 {
72019 struct stat64 stat;
72020 - if (sys_stat64(name, &stat) != 0)
72021 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
72022 return 0;
72023 if (!S_ISBLK(stat.st_mode))
72024 return 0;
72025 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
72026 static inline u32 bstat(char *name)
72027 {
72028 struct stat stat;
72029 - if (sys_newstat(name, &stat) != 0)
72030 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
72031 return 0;
72032 if (!S_ISBLK(stat.st_mode))
72033 return 0;
72034 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
72035 index f9acf71..1e19144 100644
72036 --- a/init/do_mounts_initrd.c
72037 +++ b/init/do_mounts_initrd.c
72038 @@ -58,8 +58,8 @@ static void __init handle_initrd(void)
72039 create_dev("/dev/root.old", Root_RAM0);
72040 /* mount initrd on rootfs' /root */
72041 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
72042 - sys_mkdir("/old", 0700);
72043 - sys_chdir("/old");
72044 + sys_mkdir((const char __force_user *)"/old", 0700);
72045 + sys_chdir((const char __force_user *)"/old");
72046
72047 /*
72048 * In case that a resume from disk is carried out by linuxrc or one of
72049 @@ -73,31 +73,31 @@ static void __init handle_initrd(void)
72050 current->flags &= ~PF_FREEZER_SKIP;
72051
72052 /* move initrd to rootfs' /old */
72053 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
72054 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
72055 /* switch root and cwd back to / of rootfs */
72056 - sys_chroot("..");
72057 + sys_chroot((const char __force_user *)"..");
72058
72059 if (new_decode_dev(real_root_dev) == Root_RAM0) {
72060 - sys_chdir("/old");
72061 + sys_chdir((const char __force_user *)"/old");
72062 return;
72063 }
72064
72065 - sys_chdir("/");
72066 + sys_chdir((const char __force_user *)"/");
72067 ROOT_DEV = new_decode_dev(real_root_dev);
72068 mount_root();
72069
72070 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
72071 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
72072 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
72073 if (!error)
72074 printk("okay\n");
72075 else {
72076 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
72077 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
72078 if (error == -ENOENT)
72079 printk("/initrd does not exist. Ignored.\n");
72080 else
72081 printk("failed\n");
72082 printk(KERN_NOTICE "Unmounting old root\n");
72083 - sys_umount("/old", MNT_DETACH);
72084 + sys_umount((char __force_user *)"/old", MNT_DETACH);
72085 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
72086 if (fd < 0) {
72087 error = fd;
72088 @@ -120,11 +120,11 @@ int __init initrd_load(void)
72089 * mounted in the normal path.
72090 */
72091 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
72092 - sys_unlink("/initrd.image");
72093 + sys_unlink((const char __force_user *)"/initrd.image");
72094 handle_initrd();
72095 return 1;
72096 }
72097 }
72098 - sys_unlink("/initrd.image");
72099 + sys_unlink((const char __force_user *)"/initrd.image");
72100 return 0;
72101 }
72102 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
72103 index 8cb6db5..d729f50 100644
72104 --- a/init/do_mounts_md.c
72105 +++ b/init/do_mounts_md.c
72106 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
72107 partitioned ? "_d" : "", minor,
72108 md_setup_args[ent].device_names);
72109
72110 - fd = sys_open(name, 0, 0);
72111 + fd = sys_open((char __force_user *)name, 0, 0);
72112 if (fd < 0) {
72113 printk(KERN_ERR "md: open failed - cannot start "
72114 "array %s\n", name);
72115 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
72116 * array without it
72117 */
72118 sys_close(fd);
72119 - fd = sys_open(name, 0, 0);
72120 + fd = sys_open((char __force_user *)name, 0, 0);
72121 sys_ioctl(fd, BLKRRPART, 0);
72122 }
72123 sys_close(fd);
72124 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
72125
72126 wait_for_device_probe();
72127
72128 - fd = sys_open("/dev/md0", 0, 0);
72129 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
72130 if (fd >= 0) {
72131 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
72132 sys_close(fd);
72133 diff --git a/init/init_task.c b/init/init_task.c
72134 index 8b2f399..f0797c9 100644
72135 --- a/init/init_task.c
72136 +++ b/init/init_task.c
72137 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
72138 * Initial thread structure. Alignment of this is handled by a special
72139 * linker map entry.
72140 */
72141 +#ifdef CONFIG_X86
72142 +union thread_union init_thread_union __init_task_data;
72143 +#else
72144 union thread_union init_thread_union __init_task_data =
72145 { INIT_THREAD_INFO(init_task) };
72146 +#endif
72147 diff --git a/init/initramfs.c b/init/initramfs.c
72148 index 84c6bf1..8899338 100644
72149 --- a/init/initramfs.c
72150 +++ b/init/initramfs.c
72151 @@ -84,7 +84,7 @@ static void __init free_hash(void)
72152 }
72153 }
72154
72155 -static long __init do_utime(char *filename, time_t mtime)
72156 +static long __init do_utime(char __force_user *filename, time_t mtime)
72157 {
72158 struct timespec t[2];
72159
72160 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
72161 struct dir_entry *de, *tmp;
72162 list_for_each_entry_safe(de, tmp, &dir_list, list) {
72163 list_del(&de->list);
72164 - do_utime(de->name, de->mtime);
72165 + do_utime((char __force_user *)de->name, de->mtime);
72166 kfree(de->name);
72167 kfree(de);
72168 }
72169 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
72170 if (nlink >= 2) {
72171 char *old = find_link(major, minor, ino, mode, collected);
72172 if (old)
72173 - return (sys_link(old, collected) < 0) ? -1 : 1;
72174 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
72175 }
72176 return 0;
72177 }
72178 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
72179 {
72180 struct stat st;
72181
72182 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
72183 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
72184 if (S_ISDIR(st.st_mode))
72185 - sys_rmdir(path);
72186 + sys_rmdir((char __force_user *)path);
72187 else
72188 - sys_unlink(path);
72189 + sys_unlink((char __force_user *)path);
72190 }
72191 }
72192
72193 @@ -315,7 +315,7 @@ static int __init do_name(void)
72194 int openflags = O_WRONLY|O_CREAT;
72195 if (ml != 1)
72196 openflags |= O_TRUNC;
72197 - wfd = sys_open(collected, openflags, mode);
72198 + wfd = sys_open((char __force_user *)collected, openflags, mode);
72199
72200 if (wfd >= 0) {
72201 sys_fchown(wfd, uid, gid);
72202 @@ -327,17 +327,17 @@ static int __init do_name(void)
72203 }
72204 }
72205 } else if (S_ISDIR(mode)) {
72206 - sys_mkdir(collected, mode);
72207 - sys_chown(collected, uid, gid);
72208 - sys_chmod(collected, mode);
72209 + sys_mkdir((char __force_user *)collected, mode);
72210 + sys_chown((char __force_user *)collected, uid, gid);
72211 + sys_chmod((char __force_user *)collected, mode);
72212 dir_add(collected, mtime);
72213 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
72214 S_ISFIFO(mode) || S_ISSOCK(mode)) {
72215 if (maybe_link() == 0) {
72216 - sys_mknod(collected, mode, rdev);
72217 - sys_chown(collected, uid, gid);
72218 - sys_chmod(collected, mode);
72219 - do_utime(collected, mtime);
72220 + sys_mknod((char __force_user *)collected, mode, rdev);
72221 + sys_chown((char __force_user *)collected, uid, gid);
72222 + sys_chmod((char __force_user *)collected, mode);
72223 + do_utime((char __force_user *)collected, mtime);
72224 }
72225 }
72226 return 0;
72227 @@ -346,15 +346,15 @@ static int __init do_name(void)
72228 static int __init do_copy(void)
72229 {
72230 if (count >= body_len) {
72231 - sys_write(wfd, victim, body_len);
72232 + sys_write(wfd, (char __force_user *)victim, body_len);
72233 sys_close(wfd);
72234 - do_utime(vcollected, mtime);
72235 + do_utime((char __force_user *)vcollected, mtime);
72236 kfree(vcollected);
72237 eat(body_len);
72238 state = SkipIt;
72239 return 0;
72240 } else {
72241 - sys_write(wfd, victim, count);
72242 + sys_write(wfd, (char __force_user *)victim, count);
72243 body_len -= count;
72244 eat(count);
72245 return 1;
72246 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
72247 {
72248 collected[N_ALIGN(name_len) + body_len] = '\0';
72249 clean_path(collected, 0);
72250 - sys_symlink(collected + N_ALIGN(name_len), collected);
72251 - sys_lchown(collected, uid, gid);
72252 - do_utime(collected, mtime);
72253 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
72254 + sys_lchown((char __force_user *)collected, uid, gid);
72255 + do_utime((char __force_user *)collected, mtime);
72256 state = SkipIt;
72257 next_state = Reset;
72258 return 0;
72259 diff --git a/init/main.c b/init/main.c
72260 index cee4b5c..6a3402b 100644
72261 --- a/init/main.c
72262 +++ b/init/main.c
72263 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
72264 extern void tc_init(void);
72265 #endif
72266
72267 +extern void grsecurity_init(void);
72268 +
72269 /*
72270 * Debug helper: via this flag we know that we are in 'early bootup code'
72271 * where only the boot processor is running with IRQ disabled. This means
72272 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
72273
72274 __setup("reset_devices", set_reset_devices);
72275
72276 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
72277 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
72278 +static int __init setup_grsec_proc_gid(char *str)
72279 +{
72280 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
72281 + return 1;
72282 +}
72283 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
72284 +#endif
72285 +
72286 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
72287 +extern char pax_enter_kernel_user[];
72288 +extern char pax_exit_kernel_user[];
72289 +extern pgdval_t clone_pgd_mask;
72290 +#endif
72291 +
72292 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
72293 +static int __init setup_pax_nouderef(char *str)
72294 +{
72295 +#ifdef CONFIG_X86_32
72296 + unsigned int cpu;
72297 + struct desc_struct *gdt;
72298 +
72299 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
72300 + gdt = get_cpu_gdt_table(cpu);
72301 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
72302 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
72303 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
72304 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
72305 + }
72306 + loadsegment(ds, __KERNEL_DS);
72307 + loadsegment(es, __KERNEL_DS);
72308 + loadsegment(ss, __KERNEL_DS);
72309 +#else
72310 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
72311 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
72312 + clone_pgd_mask = ~(pgdval_t)0UL;
72313 +#endif
72314 +
72315 + return 0;
72316 +}
72317 +early_param("pax_nouderef", setup_pax_nouderef);
72318 +#endif
72319 +
72320 +#ifdef CONFIG_PAX_SOFTMODE
72321 +int pax_softmode;
72322 +
72323 +static int __init setup_pax_softmode(char *str)
72324 +{
72325 + get_option(&str, &pax_softmode);
72326 + return 1;
72327 +}
72328 +__setup("pax_softmode=", setup_pax_softmode);
72329 +#endif
72330 +
72331 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
72332 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
72333 static const char *panic_later, *panic_param;
72334 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
72335 {
72336 int count = preempt_count();
72337 int ret;
72338 + const char *msg1 = "", *msg2 = "";
72339
72340 if (initcall_debug)
72341 ret = do_one_initcall_debug(fn);
72342 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
72343 sprintf(msgbuf, "error code %d ", ret);
72344
72345 if (preempt_count() != count) {
72346 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
72347 + msg1 = " preemption imbalance";
72348 preempt_count() = count;
72349 }
72350 if (irqs_disabled()) {
72351 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
72352 + msg2 = " disabled interrupts";
72353 local_irq_enable();
72354 }
72355 - if (msgbuf[0]) {
72356 - printk("initcall %pF returned with %s\n", fn, msgbuf);
72357 + if (msgbuf[0] || *msg1 || *msg2) {
72358 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
72359 }
72360
72361 return ret;
72362 @@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
72363 level, level,
72364 &repair_env_string);
72365
72366 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
72367 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
72368 do_one_initcall(*fn);
72369 +
72370 +#ifdef CONFIG_PAX_LATENT_ENTROPY
72371 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
72372 +#endif
72373 +
72374 + }
72375 }
72376
72377 static void __init do_initcalls(void)
72378 @@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
72379 {
72380 initcall_t *fn;
72381
72382 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
72383 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
72384 do_one_initcall(*fn);
72385 +
72386 +#ifdef CONFIG_PAX_LATENT_ENTROPY
72387 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
72388 +#endif
72389 +
72390 + }
72391 }
72392
72393 static int run_init_process(const char *init_filename)
72394 @@ -877,7 +947,7 @@ static noinline void __init kernel_init_freeable(void)
72395 do_basic_setup();
72396
72397 /* Open the /dev/console on the rootfs, this should never fail */
72398 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
72399 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
72400 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
72401
72402 (void) sys_dup(0);
72403 @@ -890,11 +960,13 @@ static noinline void __init kernel_init_freeable(void)
72404 if (!ramdisk_execute_command)
72405 ramdisk_execute_command = "/init";
72406
72407 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
72408 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
72409 ramdisk_execute_command = NULL;
72410 prepare_namespace();
72411 }
72412
72413 + grsecurity_init();
72414 +
72415 /*
72416 * Ok, we have completed the initial bootup, and
72417 * we're essentially up and running. Get rid of the
72418 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
72419 index 130dfec..cc88451 100644
72420 --- a/ipc/ipc_sysctl.c
72421 +++ b/ipc/ipc_sysctl.c
72422 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
72423 static int proc_ipc_dointvec(ctl_table *table, int write,
72424 void __user *buffer, size_t *lenp, loff_t *ppos)
72425 {
72426 - struct ctl_table ipc_table;
72427 + ctl_table_no_const ipc_table;
72428
72429 memcpy(&ipc_table, table, sizeof(ipc_table));
72430 ipc_table.data = get_ipc(table);
72431 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
72432 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
72433 void __user *buffer, size_t *lenp, loff_t *ppos)
72434 {
72435 - struct ctl_table ipc_table;
72436 + ctl_table_no_const ipc_table;
72437
72438 memcpy(&ipc_table, table, sizeof(ipc_table));
72439 ipc_table.data = get_ipc(table);
72440 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
72441 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
72442 void __user *buffer, size_t *lenp, loff_t *ppos)
72443 {
72444 - struct ctl_table ipc_table;
72445 + ctl_table_no_const ipc_table;
72446 size_t lenp_bef = *lenp;
72447 int rc;
72448
72449 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
72450 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
72451 void __user *buffer, size_t *lenp, loff_t *ppos)
72452 {
72453 - struct ctl_table ipc_table;
72454 + ctl_table_no_const ipc_table;
72455 memcpy(&ipc_table, table, sizeof(ipc_table));
72456 ipc_table.data = get_ipc(table);
72457
72458 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
72459 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
72460 void __user *buffer, size_t *lenp, loff_t *ppos)
72461 {
72462 - struct ctl_table ipc_table;
72463 + ctl_table_no_const ipc_table;
72464 size_t lenp_bef = *lenp;
72465 int oldval;
72466 int rc;
72467 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
72468 index 383d638..943fdbb 100644
72469 --- a/ipc/mq_sysctl.c
72470 +++ b/ipc/mq_sysctl.c
72471 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
72472 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
72473 void __user *buffer, size_t *lenp, loff_t *ppos)
72474 {
72475 - struct ctl_table mq_table;
72476 + ctl_table_no_const mq_table;
72477 memcpy(&mq_table, table, sizeof(mq_table));
72478 mq_table.data = get_mq(table);
72479
72480 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
72481 index 71a3ca1..cc330ee 100644
72482 --- a/ipc/mqueue.c
72483 +++ b/ipc/mqueue.c
72484 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
72485 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
72486 info->attr.mq_msgsize);
72487
72488 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
72489 spin_lock(&mq_lock);
72490 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
72491 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
72492 diff --git a/ipc/msg.c b/ipc/msg.c
72493 index 31cd1bf..362ea07 100644
72494 --- a/ipc/msg.c
72495 +++ b/ipc/msg.c
72496 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
72497 return security_msg_queue_associate(msq, msgflg);
72498 }
72499
72500 +static struct ipc_ops msg_ops = {
72501 + .getnew = newque,
72502 + .associate = msg_security,
72503 + .more_checks = NULL
72504 +};
72505 +
72506 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
72507 {
72508 struct ipc_namespace *ns;
72509 - struct ipc_ops msg_ops;
72510 struct ipc_params msg_params;
72511
72512 ns = current->nsproxy->ipc_ns;
72513
72514 - msg_ops.getnew = newque;
72515 - msg_ops.associate = msg_security;
72516 - msg_ops.more_checks = NULL;
72517 -
72518 msg_params.key = key;
72519 msg_params.flg = msgflg;
72520
72521 diff --git a/ipc/sem.c b/ipc/sem.c
72522 index 58d31f1..cce7a55 100644
72523 --- a/ipc/sem.c
72524 +++ b/ipc/sem.c
72525 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
72526 return 0;
72527 }
72528
72529 +static struct ipc_ops sem_ops = {
72530 + .getnew = newary,
72531 + .associate = sem_security,
72532 + .more_checks = sem_more_checks
72533 +};
72534 +
72535 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
72536 {
72537 struct ipc_namespace *ns;
72538 - struct ipc_ops sem_ops;
72539 struct ipc_params sem_params;
72540
72541 ns = current->nsproxy->ipc_ns;
72542 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
72543 if (nsems < 0 || nsems > ns->sc_semmsl)
72544 return -EINVAL;
72545
72546 - sem_ops.getnew = newary;
72547 - sem_ops.associate = sem_security;
72548 - sem_ops.more_checks = sem_more_checks;
72549 -
72550 sem_params.key = key;
72551 sem_params.flg = semflg;
72552 sem_params.u.nsems = nsems;
72553 diff --git a/ipc/shm.c b/ipc/shm.c
72554 index 4fa6d8f..55cff14 100644
72555 --- a/ipc/shm.c
72556 +++ b/ipc/shm.c
72557 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
72558 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
72559 #endif
72560
72561 +#ifdef CONFIG_GRKERNSEC
72562 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72563 + const time_t shm_createtime, const kuid_t cuid,
72564 + const int shmid);
72565 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72566 + const time_t shm_createtime);
72567 +#endif
72568 +
72569 void shm_init_ns(struct ipc_namespace *ns)
72570 {
72571 ns->shm_ctlmax = SHMMAX;
72572 @@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
72573 shp->shm_lprid = 0;
72574 shp->shm_atim = shp->shm_dtim = 0;
72575 shp->shm_ctim = get_seconds();
72576 +#ifdef CONFIG_GRKERNSEC
72577 + {
72578 + struct timespec timeval;
72579 + do_posix_clock_monotonic_gettime(&timeval);
72580 +
72581 + shp->shm_createtime = timeval.tv_sec;
72582 + }
72583 +#endif
72584 shp->shm_segsz = size;
72585 shp->shm_nattch = 0;
72586 shp->shm_file = file;
72587 @@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
72588 return 0;
72589 }
72590
72591 +static struct ipc_ops shm_ops = {
72592 + .getnew = newseg,
72593 + .associate = shm_security,
72594 + .more_checks = shm_more_checks
72595 +};
72596 +
72597 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
72598 {
72599 struct ipc_namespace *ns;
72600 - struct ipc_ops shm_ops;
72601 struct ipc_params shm_params;
72602
72603 ns = current->nsproxy->ipc_ns;
72604
72605 - shm_ops.getnew = newseg;
72606 - shm_ops.associate = shm_security;
72607 - shm_ops.more_checks = shm_more_checks;
72608 -
72609 shm_params.key = key;
72610 shm_params.flg = shmflg;
72611 shm_params.u.size = size;
72612 @@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
72613 f_mode = FMODE_READ | FMODE_WRITE;
72614 }
72615 if (shmflg & SHM_EXEC) {
72616 +
72617 +#ifdef CONFIG_PAX_MPROTECT
72618 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
72619 + goto out;
72620 +#endif
72621 +
72622 prot |= PROT_EXEC;
72623 acc_mode |= S_IXUGO;
72624 }
72625 @@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
72626 if (err)
72627 goto out_unlock;
72628
72629 +#ifdef CONFIG_GRKERNSEC
72630 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
72631 + shp->shm_perm.cuid, shmid) ||
72632 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
72633 + err = -EACCES;
72634 + goto out_unlock;
72635 + }
72636 +#endif
72637 +
72638 path = shp->shm_file->f_path;
72639 path_get(&path);
72640 shp->shm_nattch++;
72641 +#ifdef CONFIG_GRKERNSEC
72642 + shp->shm_lapid = current->pid;
72643 +#endif
72644 size = i_size_read(path.dentry->d_inode);
72645 shm_unlock(shp);
72646
72647 diff --git a/kernel/acct.c b/kernel/acct.c
72648 index 051e071..15e0920 100644
72649 --- a/kernel/acct.c
72650 +++ b/kernel/acct.c
72651 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
72652 */
72653 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
72654 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
72655 - file->f_op->write(file, (char *)&ac,
72656 + file->f_op->write(file, (char __force_user *)&ac,
72657 sizeof(acct_t), &file->f_pos);
72658 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
72659 set_fs(fs);
72660 diff --git a/kernel/audit.c b/kernel/audit.c
72661 index d596e53..dbef3c3 100644
72662 --- a/kernel/audit.c
72663 +++ b/kernel/audit.c
72664 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
72665 3) suppressed due to audit_rate_limit
72666 4) suppressed due to audit_backlog_limit
72667 */
72668 -static atomic_t audit_lost = ATOMIC_INIT(0);
72669 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
72670
72671 /* The netlink socket. */
72672 static struct sock *audit_sock;
72673 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
72674 unsigned long now;
72675 int print;
72676
72677 - atomic_inc(&audit_lost);
72678 + atomic_inc_unchecked(&audit_lost);
72679
72680 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
72681
72682 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
72683 printk(KERN_WARNING
72684 "audit: audit_lost=%d audit_rate_limit=%d "
72685 "audit_backlog_limit=%d\n",
72686 - atomic_read(&audit_lost),
72687 + atomic_read_unchecked(&audit_lost),
72688 audit_rate_limit,
72689 audit_backlog_limit);
72690 audit_panic(message);
72691 @@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
72692 status_set.pid = audit_pid;
72693 status_set.rate_limit = audit_rate_limit;
72694 status_set.backlog_limit = audit_backlog_limit;
72695 - status_set.lost = atomic_read(&audit_lost);
72696 + status_set.lost = atomic_read_unchecked(&audit_lost);
72697 status_set.backlog = skb_queue_len(&audit_skb_queue);
72698 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
72699 &status_set, sizeof(status_set));
72700 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
72701 index a371f85..da826c1 100644
72702 --- a/kernel/auditsc.c
72703 +++ b/kernel/auditsc.c
72704 @@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
72705 }
72706
72707 /* global counter which is incremented every time something logs in */
72708 -static atomic_t session_id = ATOMIC_INIT(0);
72709 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
72710
72711 /**
72712 * audit_set_loginuid - set current task's audit_context loginuid
72713 @@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
72714 return -EPERM;
72715 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
72716
72717 - sessionid = atomic_inc_return(&session_id);
72718 + sessionid = atomic_inc_return_unchecked(&session_id);
72719 if (context && context->in_syscall) {
72720 struct audit_buffer *ab;
72721
72722 diff --git a/kernel/capability.c b/kernel/capability.c
72723 index 493d972..f87dfbd 100644
72724 --- a/kernel/capability.c
72725 +++ b/kernel/capability.c
72726 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
72727 * before modification is attempted and the application
72728 * fails.
72729 */
72730 + if (tocopy > ARRAY_SIZE(kdata))
72731 + return -EFAULT;
72732 +
72733 if (copy_to_user(dataptr, kdata, tocopy
72734 * sizeof(struct __user_cap_data_struct))) {
72735 return -EFAULT;
72736 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
72737 int ret;
72738
72739 rcu_read_lock();
72740 - ret = security_capable(__task_cred(t), ns, cap);
72741 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
72742 + gr_task_is_capable(t, __task_cred(t), cap);
72743 rcu_read_unlock();
72744
72745 - return (ret == 0);
72746 + return ret;
72747 }
72748
72749 /**
72750 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
72751 int ret;
72752
72753 rcu_read_lock();
72754 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
72755 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
72756 rcu_read_unlock();
72757
72758 - return (ret == 0);
72759 + return ret;
72760 }
72761
72762 /**
72763 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
72764 BUG();
72765 }
72766
72767 - if (security_capable(current_cred(), ns, cap) == 0) {
72768 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
72769 current->flags |= PF_SUPERPRIV;
72770 return true;
72771 }
72772 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
72773 }
72774 EXPORT_SYMBOL(ns_capable);
72775
72776 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
72777 +{
72778 + if (unlikely(!cap_valid(cap))) {
72779 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
72780 + BUG();
72781 + }
72782 +
72783 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
72784 + current->flags |= PF_SUPERPRIV;
72785 + return true;
72786 + }
72787 + return false;
72788 +}
72789 +EXPORT_SYMBOL(ns_capable_nolog);
72790 +
72791 /**
72792 * capable - Determine if the current task has a superior capability in effect
72793 * @cap: The capability to be tested for
72794 @@ -408,6 +427,12 @@ bool capable(int cap)
72795 }
72796 EXPORT_SYMBOL(capable);
72797
72798 +bool capable_nolog(int cap)
72799 +{
72800 + return ns_capable_nolog(&init_user_ns, cap);
72801 +}
72802 +EXPORT_SYMBOL(capable_nolog);
72803 +
72804 /**
72805 * nsown_capable - Check superior capability to one's own user_ns
72806 * @cap: The capability in question
72807 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
72808
72809 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
72810 }
72811 +
72812 +bool inode_capable_nolog(const struct inode *inode, int cap)
72813 +{
72814 + struct user_namespace *ns = current_user_ns();
72815 +
72816 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
72817 +}
72818 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
72819 index 1e23664..570a83d 100644
72820 --- a/kernel/cgroup.c
72821 +++ b/kernel/cgroup.c
72822 @@ -5543,7 +5543,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
72823 struct css_set *cg = link->cg;
72824 struct task_struct *task;
72825 int count = 0;
72826 - seq_printf(seq, "css_set %p\n", cg);
72827 + seq_printf(seq, "css_set %pK\n", cg);
72828 list_for_each_entry(task, &cg->tasks, cg_list) {
72829 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
72830 seq_puts(seq, " ...\n");
72831 diff --git a/kernel/compat.c b/kernel/compat.c
72832 index 36700e9..73d770c 100644
72833 --- a/kernel/compat.c
72834 +++ b/kernel/compat.c
72835 @@ -13,6 +13,7 @@
72836
72837 #include <linux/linkage.h>
72838 #include <linux/compat.h>
72839 +#include <linux/module.h>
72840 #include <linux/errno.h>
72841 #include <linux/time.h>
72842 #include <linux/signal.h>
72843 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
72844 mm_segment_t oldfs;
72845 long ret;
72846
72847 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
72848 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
72849 oldfs = get_fs();
72850 set_fs(KERNEL_DS);
72851 ret = hrtimer_nanosleep_restart(restart);
72852 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
72853 oldfs = get_fs();
72854 set_fs(KERNEL_DS);
72855 ret = hrtimer_nanosleep(&tu,
72856 - rmtp ? (struct timespec __user *)&rmt : NULL,
72857 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
72858 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
72859 set_fs(oldfs);
72860
72861 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
72862 mm_segment_t old_fs = get_fs();
72863
72864 set_fs(KERNEL_DS);
72865 - ret = sys_sigpending((old_sigset_t __user *) &s);
72866 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
72867 set_fs(old_fs);
72868 if (ret == 0)
72869 ret = put_user(s, set);
72870 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
72871 mm_segment_t old_fs = get_fs();
72872
72873 set_fs(KERNEL_DS);
72874 - ret = sys_old_getrlimit(resource, &r);
72875 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
72876 set_fs(old_fs);
72877
72878 if (!ret) {
72879 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
72880 mm_segment_t old_fs = get_fs();
72881
72882 set_fs(KERNEL_DS);
72883 - ret = sys_getrusage(who, (struct rusage __user *) &r);
72884 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
72885 set_fs(old_fs);
72886
72887 if (ret)
72888 @@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
72889 set_fs (KERNEL_DS);
72890 ret = sys_wait4(pid,
72891 (stat_addr ?
72892 - (unsigned int __user *) &status : NULL),
72893 - options, (struct rusage __user *) &r);
72894 + (unsigned int __force_user *) &status : NULL),
72895 + options, (struct rusage __force_user *) &r);
72896 set_fs (old_fs);
72897
72898 if (ret > 0) {
72899 @@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
72900 memset(&info, 0, sizeof(info));
72901
72902 set_fs(KERNEL_DS);
72903 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
72904 - uru ? (struct rusage __user *)&ru : NULL);
72905 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
72906 + uru ? (struct rusage __force_user *)&ru : NULL);
72907 set_fs(old_fs);
72908
72909 if ((ret < 0) || (info.si_signo == 0))
72910 @@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
72911 oldfs = get_fs();
72912 set_fs(KERNEL_DS);
72913 err = sys_timer_settime(timer_id, flags,
72914 - (struct itimerspec __user *) &newts,
72915 - (struct itimerspec __user *) &oldts);
72916 + (struct itimerspec __force_user *) &newts,
72917 + (struct itimerspec __force_user *) &oldts);
72918 set_fs(oldfs);
72919 if (!err && old && put_compat_itimerspec(old, &oldts))
72920 return -EFAULT;
72921 @@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
72922 oldfs = get_fs();
72923 set_fs(KERNEL_DS);
72924 err = sys_timer_gettime(timer_id,
72925 - (struct itimerspec __user *) &ts);
72926 + (struct itimerspec __force_user *) &ts);
72927 set_fs(oldfs);
72928 if (!err && put_compat_itimerspec(setting, &ts))
72929 return -EFAULT;
72930 @@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
72931 oldfs = get_fs();
72932 set_fs(KERNEL_DS);
72933 err = sys_clock_settime(which_clock,
72934 - (struct timespec __user *) &ts);
72935 + (struct timespec __force_user *) &ts);
72936 set_fs(oldfs);
72937 return err;
72938 }
72939 @@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
72940 oldfs = get_fs();
72941 set_fs(KERNEL_DS);
72942 err = sys_clock_gettime(which_clock,
72943 - (struct timespec __user *) &ts);
72944 + (struct timespec __force_user *) &ts);
72945 set_fs(oldfs);
72946 if (!err && put_compat_timespec(&ts, tp))
72947 return -EFAULT;
72948 @@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
72949
72950 oldfs = get_fs();
72951 set_fs(KERNEL_DS);
72952 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
72953 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
72954 set_fs(oldfs);
72955
72956 err = compat_put_timex(utp, &txc);
72957 @@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
72958 oldfs = get_fs();
72959 set_fs(KERNEL_DS);
72960 err = sys_clock_getres(which_clock,
72961 - (struct timespec __user *) &ts);
72962 + (struct timespec __force_user *) &ts);
72963 set_fs(oldfs);
72964 if (!err && tp && put_compat_timespec(&ts, tp))
72965 return -EFAULT;
72966 @@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
72967 long err;
72968 mm_segment_t oldfs;
72969 struct timespec tu;
72970 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
72971 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
72972
72973 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
72974 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
72975 oldfs = get_fs();
72976 set_fs(KERNEL_DS);
72977 err = clock_nanosleep_restart(restart);
72978 @@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
72979 oldfs = get_fs();
72980 set_fs(KERNEL_DS);
72981 err = sys_clock_nanosleep(which_clock, flags,
72982 - (struct timespec __user *) &in,
72983 - (struct timespec __user *) &out);
72984 + (struct timespec __force_user *) &in,
72985 + (struct timespec __force_user *) &out);
72986 set_fs(oldfs);
72987
72988 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
72989 diff --git a/kernel/configs.c b/kernel/configs.c
72990 index 42e8fa0..9e7406b 100644
72991 --- a/kernel/configs.c
72992 +++ b/kernel/configs.c
72993 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
72994 struct proc_dir_entry *entry;
72995
72996 /* create the current config file */
72997 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
72998 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
72999 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
73000 + &ikconfig_file_ops);
73001 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73002 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
73003 + &ikconfig_file_ops);
73004 +#endif
73005 +#else
73006 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
73007 &ikconfig_file_ops);
73008 +#endif
73009 +
73010 if (!entry)
73011 return -ENOMEM;
73012
73013 diff --git a/kernel/cred.c b/kernel/cred.c
73014 index e0573a4..3874e41 100644
73015 --- a/kernel/cred.c
73016 +++ b/kernel/cred.c
73017 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
73018 validate_creds(cred);
73019 alter_cred_subscribers(cred, -1);
73020 put_cred(cred);
73021 +
73022 +#ifdef CONFIG_GRKERNSEC_SETXID
73023 + cred = (struct cred *) tsk->delayed_cred;
73024 + if (cred != NULL) {
73025 + tsk->delayed_cred = NULL;
73026 + validate_creds(cred);
73027 + alter_cred_subscribers(cred, -1);
73028 + put_cred(cred);
73029 + }
73030 +#endif
73031 }
73032
73033 /**
73034 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
73035 * Always returns 0 thus allowing this function to be tail-called at the end
73036 * of, say, sys_setgid().
73037 */
73038 -int commit_creds(struct cred *new)
73039 +static int __commit_creds(struct cred *new)
73040 {
73041 struct task_struct *task = current;
73042 const struct cred *old = task->real_cred;
73043 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
73044
73045 get_cred(new); /* we will require a ref for the subj creds too */
73046
73047 + gr_set_role_label(task, new->uid, new->gid);
73048 +
73049 /* dumpability changes */
73050 if (!uid_eq(old->euid, new->euid) ||
73051 !gid_eq(old->egid, new->egid) ||
73052 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
73053 put_cred(old);
73054 return 0;
73055 }
73056 +#ifdef CONFIG_GRKERNSEC_SETXID
73057 +extern int set_user(struct cred *new);
73058 +
73059 +void gr_delayed_cred_worker(void)
73060 +{
73061 + const struct cred *new = current->delayed_cred;
73062 + struct cred *ncred;
73063 +
73064 + current->delayed_cred = NULL;
73065 +
73066 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
73067 + // from doing get_cred on it when queueing this
73068 + put_cred(new);
73069 + return;
73070 + } else if (new == NULL)
73071 + return;
73072 +
73073 + ncred = prepare_creds();
73074 + if (!ncred)
73075 + goto die;
73076 + // uids
73077 + ncred->uid = new->uid;
73078 + ncred->euid = new->euid;
73079 + ncred->suid = new->suid;
73080 + ncred->fsuid = new->fsuid;
73081 + // gids
73082 + ncred->gid = new->gid;
73083 + ncred->egid = new->egid;
73084 + ncred->sgid = new->sgid;
73085 + ncred->fsgid = new->fsgid;
73086 + // groups
73087 + if (set_groups(ncred, new->group_info) < 0) {
73088 + abort_creds(ncred);
73089 + goto die;
73090 + }
73091 + // caps
73092 + ncred->securebits = new->securebits;
73093 + ncred->cap_inheritable = new->cap_inheritable;
73094 + ncred->cap_permitted = new->cap_permitted;
73095 + ncred->cap_effective = new->cap_effective;
73096 + ncred->cap_bset = new->cap_bset;
73097 +
73098 + if (set_user(ncred)) {
73099 + abort_creds(ncred);
73100 + goto die;
73101 + }
73102 +
73103 + // from doing get_cred on it when queueing this
73104 + put_cred(new);
73105 +
73106 + __commit_creds(ncred);
73107 + return;
73108 +die:
73109 + // from doing get_cred on it when queueing this
73110 + put_cred(new);
73111 + do_group_exit(SIGKILL);
73112 +}
73113 +#endif
73114 +
73115 +int commit_creds(struct cred *new)
73116 +{
73117 +#ifdef CONFIG_GRKERNSEC_SETXID
73118 + int ret;
73119 + int schedule_it = 0;
73120 + struct task_struct *t;
73121 +
73122 + /* we won't get called with tasklist_lock held for writing
73123 + and interrupts disabled as the cred struct in that case is
73124 + init_cred
73125 + */
73126 + if (grsec_enable_setxid && !current_is_single_threaded() &&
73127 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
73128 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
73129 + schedule_it = 1;
73130 + }
73131 + ret = __commit_creds(new);
73132 + if (schedule_it) {
73133 + rcu_read_lock();
73134 + read_lock(&tasklist_lock);
73135 + for (t = next_thread(current); t != current;
73136 + t = next_thread(t)) {
73137 + if (t->delayed_cred == NULL) {
73138 + t->delayed_cred = get_cred(new);
73139 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
73140 + set_tsk_need_resched(t);
73141 + }
73142 + }
73143 + read_unlock(&tasklist_lock);
73144 + rcu_read_unlock();
73145 + }
73146 + return ret;
73147 +#else
73148 + return __commit_creds(new);
73149 +#endif
73150 +}
73151 +
73152 EXPORT_SYMBOL(commit_creds);
73153
73154 /**
73155 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
73156 index 9a61738..c5c8f3a 100644
73157 --- a/kernel/debug/debug_core.c
73158 +++ b/kernel/debug/debug_core.c
73159 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
73160 */
73161 static atomic_t masters_in_kgdb;
73162 static atomic_t slaves_in_kgdb;
73163 -static atomic_t kgdb_break_tasklet_var;
73164 +static atomic_unchecked_t kgdb_break_tasklet_var;
73165 atomic_t kgdb_setting_breakpoint;
73166
73167 struct task_struct *kgdb_usethread;
73168 @@ -132,7 +132,7 @@ int kgdb_single_step;
73169 static pid_t kgdb_sstep_pid;
73170
73171 /* to keep track of the CPU which is doing the single stepping*/
73172 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73173 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73174
73175 /*
73176 * If you are debugging a problem where roundup (the collection of
73177 @@ -540,7 +540,7 @@ return_normal:
73178 * kernel will only try for the value of sstep_tries before
73179 * giving up and continuing on.
73180 */
73181 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
73182 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
73183 (kgdb_info[cpu].task &&
73184 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
73185 atomic_set(&kgdb_active, -1);
73186 @@ -634,8 +634,8 @@ cpu_master_loop:
73187 }
73188
73189 kgdb_restore:
73190 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
73191 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
73192 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
73193 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
73194 if (kgdb_info[sstep_cpu].task)
73195 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
73196 else
73197 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
73198 static void kgdb_tasklet_bpt(unsigned long ing)
73199 {
73200 kgdb_breakpoint();
73201 - atomic_set(&kgdb_break_tasklet_var, 0);
73202 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
73203 }
73204
73205 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
73206
73207 void kgdb_schedule_breakpoint(void)
73208 {
73209 - if (atomic_read(&kgdb_break_tasklet_var) ||
73210 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
73211 atomic_read(&kgdb_active) != -1 ||
73212 atomic_read(&kgdb_setting_breakpoint))
73213 return;
73214 - atomic_inc(&kgdb_break_tasklet_var);
73215 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
73216 tasklet_schedule(&kgdb_tasklet_breakpoint);
73217 }
73218 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
73219 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
73220 index 8875254..7cf4928 100644
73221 --- a/kernel/debug/kdb/kdb_main.c
73222 +++ b/kernel/debug/kdb/kdb_main.c
73223 @@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
73224 continue;
73225
73226 kdb_printf("%-20s%8u 0x%p ", mod->name,
73227 - mod->core_size, (void *)mod);
73228 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
73229 #ifdef CONFIG_MODULE_UNLOAD
73230 kdb_printf("%4ld ", module_refcount(mod));
73231 #endif
73232 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
73233 kdb_printf(" (Loading)");
73234 else
73235 kdb_printf(" (Live)");
73236 - kdb_printf(" 0x%p", mod->module_core);
73237 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
73238
73239 #ifdef CONFIG_MODULE_UNLOAD
73240 {
73241 diff --git a/kernel/events/core.c b/kernel/events/core.c
73242 index 7b6646a..3cb1135 100644
73243 --- a/kernel/events/core.c
73244 +++ b/kernel/events/core.c
73245 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
73246 return 0;
73247 }
73248
73249 -static atomic64_t perf_event_id;
73250 +static atomic64_unchecked_t perf_event_id;
73251
73252 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
73253 enum event_type_t event_type);
73254 @@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
73255
73256 static inline u64 perf_event_count(struct perf_event *event)
73257 {
73258 - return local64_read(&event->count) + atomic64_read(&event->child_count);
73259 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
73260 }
73261
73262 static u64 perf_event_read(struct perf_event *event)
73263 @@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
73264 mutex_lock(&event->child_mutex);
73265 total += perf_event_read(event);
73266 *enabled += event->total_time_enabled +
73267 - atomic64_read(&event->child_total_time_enabled);
73268 + atomic64_read_unchecked(&event->child_total_time_enabled);
73269 *running += event->total_time_running +
73270 - atomic64_read(&event->child_total_time_running);
73271 + atomic64_read_unchecked(&event->child_total_time_running);
73272
73273 list_for_each_entry(child, &event->child_list, child_list) {
73274 total += perf_event_read(child);
73275 @@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
73276 userpg->offset -= local64_read(&event->hw.prev_count);
73277
73278 userpg->time_enabled = enabled +
73279 - atomic64_read(&event->child_total_time_enabled);
73280 + atomic64_read_unchecked(&event->child_total_time_enabled);
73281
73282 userpg->time_running = running +
73283 - atomic64_read(&event->child_total_time_running);
73284 + atomic64_read_unchecked(&event->child_total_time_running);
73285
73286 arch_perf_update_userpage(userpg, now);
73287
73288 @@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
73289 values[n++] = perf_event_count(event);
73290 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
73291 values[n++] = enabled +
73292 - atomic64_read(&event->child_total_time_enabled);
73293 + atomic64_read_unchecked(&event->child_total_time_enabled);
73294 }
73295 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
73296 values[n++] = running +
73297 - atomic64_read(&event->child_total_time_running);
73298 + atomic64_read_unchecked(&event->child_total_time_running);
73299 }
73300 if (read_format & PERF_FORMAT_ID)
73301 values[n++] = primary_event_id(event);
73302 @@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
73303 * need to add enough zero bytes after the string to handle
73304 * the 64bit alignment we do later.
73305 */
73306 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
73307 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
73308 if (!buf) {
73309 name = strncpy(tmp, "//enomem", sizeof(tmp));
73310 goto got_name;
73311 }
73312 - name = d_path(&file->f_path, buf, PATH_MAX);
73313 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
73314 if (IS_ERR(name)) {
73315 name = strncpy(tmp, "//toolong", sizeof(tmp));
73316 goto got_name;
73317 @@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
73318 event->parent = parent_event;
73319
73320 event->ns = get_pid_ns(task_active_pid_ns(current));
73321 - event->id = atomic64_inc_return(&perf_event_id);
73322 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
73323
73324 event->state = PERF_EVENT_STATE_INACTIVE;
73325
73326 @@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
73327 /*
73328 * Add back the child's count to the parent's count:
73329 */
73330 - atomic64_add(child_val, &parent_event->child_count);
73331 - atomic64_add(child_event->total_time_enabled,
73332 + atomic64_add_unchecked(child_val, &parent_event->child_count);
73333 + atomic64_add_unchecked(child_event->total_time_enabled,
73334 &parent_event->child_total_time_enabled);
73335 - atomic64_add(child_event->total_time_running,
73336 + atomic64_add_unchecked(child_event->total_time_running,
73337 &parent_event->child_total_time_running);
73338
73339 /*
73340 diff --git a/kernel/exit.c b/kernel/exit.c
73341 index b4df219..f13c02d 100644
73342 --- a/kernel/exit.c
73343 +++ b/kernel/exit.c
73344 @@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
73345 struct task_struct *leader;
73346 int zap_leader;
73347 repeat:
73348 +#ifdef CONFIG_NET
73349 + gr_del_task_from_ip_table(p);
73350 +#endif
73351 +
73352 /* don't need to get the RCU readlock here - the process is dead and
73353 * can't be modifying its own credentials. But shut RCU-lockdep up */
73354 rcu_read_lock();
73355 @@ -338,7 +342,7 @@ int allow_signal(int sig)
73356 * know it'll be handled, so that they don't get converted to
73357 * SIGKILL or just silently dropped.
73358 */
73359 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
73360 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
73361 recalc_sigpending();
73362 spin_unlock_irq(&current->sighand->siglock);
73363 return 0;
73364 @@ -708,6 +712,8 @@ void do_exit(long code)
73365 struct task_struct *tsk = current;
73366 int group_dead;
73367
73368 + set_fs(USER_DS);
73369 +
73370 profile_task_exit(tsk);
73371
73372 WARN_ON(blk_needs_flush_plug(tsk));
73373 @@ -724,7 +730,6 @@ void do_exit(long code)
73374 * mm_release()->clear_child_tid() from writing to a user-controlled
73375 * kernel address.
73376 */
73377 - set_fs(USER_DS);
73378
73379 ptrace_event(PTRACE_EVENT_EXIT, code);
73380
73381 @@ -783,6 +788,9 @@ void do_exit(long code)
73382 tsk->exit_code = code;
73383 taskstats_exit(tsk, group_dead);
73384
73385 + gr_acl_handle_psacct(tsk, code);
73386 + gr_acl_handle_exit();
73387 +
73388 exit_mm(tsk);
73389
73390 if (group_dead)
73391 @@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
73392 * Take down every thread in the group. This is called by fatal signals
73393 * as well as by sys_exit_group (below).
73394 */
73395 -void
73396 +__noreturn void
73397 do_group_exit(int exit_code)
73398 {
73399 struct signal_struct *sig = current->signal;
73400 diff --git a/kernel/fork.c b/kernel/fork.c
73401 index 5630e52..0cee608 100644
73402 --- a/kernel/fork.c
73403 +++ b/kernel/fork.c
73404 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
73405 *stackend = STACK_END_MAGIC; /* for overflow detection */
73406
73407 #ifdef CONFIG_CC_STACKPROTECTOR
73408 - tsk->stack_canary = get_random_int();
73409 + tsk->stack_canary = pax_get_random_long();
73410 #endif
73411
73412 /*
73413 @@ -344,13 +344,81 @@ free_tsk:
73414 }
73415
73416 #ifdef CONFIG_MMU
73417 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
73418 +{
73419 + struct vm_area_struct *tmp;
73420 + unsigned long charge;
73421 + struct mempolicy *pol;
73422 + struct file *file;
73423 +
73424 + charge = 0;
73425 + if (mpnt->vm_flags & VM_ACCOUNT) {
73426 + unsigned long len = vma_pages(mpnt);
73427 +
73428 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
73429 + goto fail_nomem;
73430 + charge = len;
73431 + }
73432 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73433 + if (!tmp)
73434 + goto fail_nomem;
73435 + *tmp = *mpnt;
73436 + tmp->vm_mm = mm;
73437 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
73438 + pol = mpol_dup(vma_policy(mpnt));
73439 + if (IS_ERR(pol))
73440 + goto fail_nomem_policy;
73441 + vma_set_policy(tmp, pol);
73442 + if (anon_vma_fork(tmp, mpnt))
73443 + goto fail_nomem_anon_vma_fork;
73444 + tmp->vm_flags &= ~VM_LOCKED;
73445 + tmp->vm_next = tmp->vm_prev = NULL;
73446 + tmp->vm_mirror = NULL;
73447 + file = tmp->vm_file;
73448 + if (file) {
73449 + struct inode *inode = file->f_path.dentry->d_inode;
73450 + struct address_space *mapping = file->f_mapping;
73451 +
73452 + get_file(file);
73453 + if (tmp->vm_flags & VM_DENYWRITE)
73454 + atomic_dec(&inode->i_writecount);
73455 + mutex_lock(&mapping->i_mmap_mutex);
73456 + if (tmp->vm_flags & VM_SHARED)
73457 + mapping->i_mmap_writable++;
73458 + flush_dcache_mmap_lock(mapping);
73459 + /* insert tmp into the share list, just after mpnt */
73460 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
73461 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
73462 + else
73463 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
73464 + flush_dcache_mmap_unlock(mapping);
73465 + mutex_unlock(&mapping->i_mmap_mutex);
73466 + }
73467 +
73468 + /*
73469 + * Clear hugetlb-related page reserves for children. This only
73470 + * affects MAP_PRIVATE mappings. Faults generated by the child
73471 + * are not guaranteed to succeed, even if read-only
73472 + */
73473 + if (is_vm_hugetlb_page(tmp))
73474 + reset_vma_resv_huge_pages(tmp);
73475 +
73476 + return tmp;
73477 +
73478 +fail_nomem_anon_vma_fork:
73479 + mpol_put(pol);
73480 +fail_nomem_policy:
73481 + kmem_cache_free(vm_area_cachep, tmp);
73482 +fail_nomem:
73483 + vm_unacct_memory(charge);
73484 + return NULL;
73485 +}
73486 +
73487 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73488 {
73489 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
73490 struct rb_node **rb_link, *rb_parent;
73491 int retval;
73492 - unsigned long charge;
73493 - struct mempolicy *pol;
73494
73495 uprobe_start_dup_mmap();
73496 down_write(&oldmm->mmap_sem);
73497 @@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73498 mm->locked_vm = 0;
73499 mm->mmap = NULL;
73500 mm->mmap_cache = NULL;
73501 - mm->free_area_cache = oldmm->mmap_base;
73502 - mm->cached_hole_size = ~0UL;
73503 + mm->free_area_cache = oldmm->free_area_cache;
73504 + mm->cached_hole_size = oldmm->cached_hole_size;
73505 mm->map_count = 0;
73506 cpumask_clear(mm_cpumask(mm));
73507 mm->mm_rb = RB_ROOT;
73508 @@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73509
73510 prev = NULL;
73511 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
73512 - struct file *file;
73513 -
73514 if (mpnt->vm_flags & VM_DONTCOPY) {
73515 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
73516 -vma_pages(mpnt));
73517 continue;
73518 }
73519 - charge = 0;
73520 - if (mpnt->vm_flags & VM_ACCOUNT) {
73521 - unsigned long len = vma_pages(mpnt);
73522 -
73523 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
73524 - goto fail_nomem;
73525 - charge = len;
73526 - }
73527 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73528 - if (!tmp)
73529 - goto fail_nomem;
73530 - *tmp = *mpnt;
73531 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
73532 - pol = mpol_dup(vma_policy(mpnt));
73533 - retval = PTR_ERR(pol);
73534 - if (IS_ERR(pol))
73535 - goto fail_nomem_policy;
73536 - vma_set_policy(tmp, pol);
73537 - tmp->vm_mm = mm;
73538 - if (anon_vma_fork(tmp, mpnt))
73539 - goto fail_nomem_anon_vma_fork;
73540 - tmp->vm_flags &= ~VM_LOCKED;
73541 - tmp->vm_next = tmp->vm_prev = NULL;
73542 - file = tmp->vm_file;
73543 - if (file) {
73544 - struct inode *inode = file->f_path.dentry->d_inode;
73545 - struct address_space *mapping = file->f_mapping;
73546 -
73547 - get_file(file);
73548 - if (tmp->vm_flags & VM_DENYWRITE)
73549 - atomic_dec(&inode->i_writecount);
73550 - mutex_lock(&mapping->i_mmap_mutex);
73551 - if (tmp->vm_flags & VM_SHARED)
73552 - mapping->i_mmap_writable++;
73553 - flush_dcache_mmap_lock(mapping);
73554 - /* insert tmp into the share list, just after mpnt */
73555 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
73556 - vma_nonlinear_insert(tmp,
73557 - &mapping->i_mmap_nonlinear);
73558 - else
73559 - vma_interval_tree_insert_after(tmp, mpnt,
73560 - &mapping->i_mmap);
73561 - flush_dcache_mmap_unlock(mapping);
73562 - mutex_unlock(&mapping->i_mmap_mutex);
73563 + tmp = dup_vma(mm, oldmm, mpnt);
73564 + if (!tmp) {
73565 + retval = -ENOMEM;
73566 + goto out;
73567 }
73568
73569 /*
73570 @@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73571 if (retval)
73572 goto out;
73573 }
73574 +
73575 +#ifdef CONFIG_PAX_SEGMEXEC
73576 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
73577 + struct vm_area_struct *mpnt_m;
73578 +
73579 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
73580 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
73581 +
73582 + if (!mpnt->vm_mirror)
73583 + continue;
73584 +
73585 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
73586 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
73587 + mpnt->vm_mirror = mpnt_m;
73588 + } else {
73589 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
73590 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
73591 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
73592 + mpnt->vm_mirror->vm_mirror = mpnt;
73593 + }
73594 + }
73595 + BUG_ON(mpnt_m);
73596 + }
73597 +#endif
73598 +
73599 /* a new mm has just been created */
73600 arch_dup_mmap(oldmm, mm);
73601 retval = 0;
73602 @@ -472,14 +523,6 @@ out:
73603 up_write(&oldmm->mmap_sem);
73604 uprobe_end_dup_mmap();
73605 return retval;
73606 -fail_nomem_anon_vma_fork:
73607 - mpol_put(pol);
73608 -fail_nomem_policy:
73609 - kmem_cache_free(vm_area_cachep, tmp);
73610 -fail_nomem:
73611 - retval = -ENOMEM;
73612 - vm_unacct_memory(charge);
73613 - goto out;
73614 }
73615
73616 static inline int mm_alloc_pgd(struct mm_struct *mm)
73617 @@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
73618 return ERR_PTR(err);
73619
73620 mm = get_task_mm(task);
73621 - if (mm && mm != current->mm &&
73622 - !ptrace_may_access(task, mode)) {
73623 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
73624 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
73625 mmput(mm);
73626 mm = ERR_PTR(-EACCES);
73627 }
73628 @@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
73629 spin_unlock(&fs->lock);
73630 return -EAGAIN;
73631 }
73632 - fs->users++;
73633 + atomic_inc(&fs->users);
73634 spin_unlock(&fs->lock);
73635 return 0;
73636 }
73637 tsk->fs = copy_fs_struct(fs);
73638 if (!tsk->fs)
73639 return -ENOMEM;
73640 + /* Carry through gr_chroot_dentry and is_chrooted instead
73641 + of recomputing it here. Already copied when the task struct
73642 + is duplicated. This allows pivot_root to not be treated as
73643 + a chroot
73644 + */
73645 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
73646 +
73647 return 0;
73648 }
73649
73650 @@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
73651 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
73652 #endif
73653 retval = -EAGAIN;
73654 +
73655 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
73656 +
73657 if (atomic_read(&p->real_cred->user->processes) >=
73658 task_rlimit(p, RLIMIT_NPROC)) {
73659 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
73660 @@ -1435,6 +1488,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
73661 goto bad_fork_free_pid;
73662 }
73663
73664 + /* synchronizes with gr_set_acls()
73665 + we need to call this past the point of no return for fork()
73666 + */
73667 + gr_copy_label(p);
73668 +
73669 if (clone_flags & CLONE_THREAD) {
73670 current->signal->nr_threads++;
73671 atomic_inc(&current->signal->live);
73672 @@ -1518,6 +1576,8 @@ bad_fork_cleanup_count:
73673 bad_fork_free:
73674 free_task(p);
73675 fork_out:
73676 + gr_log_forkfail(retval);
73677 +
73678 return ERR_PTR(retval);
73679 }
73680
73681 @@ -1568,6 +1628,23 @@ long do_fork(unsigned long clone_flags,
73682 return -EINVAL;
73683 }
73684
73685 +#ifdef CONFIG_GRKERNSEC
73686 + if (clone_flags & CLONE_NEWUSER) {
73687 + /*
73688 + * This doesn't really inspire confidence:
73689 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
73690 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
73691 + * Increases kernel attack surface in areas developers
73692 + * previously cared little about ("low importance due
73693 + * to requiring "root" capability")
73694 + * To be removed when this code receives *proper* review
73695 + */
73696 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
73697 + !capable(CAP_SETGID))
73698 + return -EPERM;
73699 + }
73700 +#endif
73701 +
73702 /*
73703 * Determine whether and which event to report to ptracer. When
73704 * called from kernel_thread or CLONE_UNTRACED is explicitly
73705 @@ -1602,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
73706 if (clone_flags & CLONE_PARENT_SETTID)
73707 put_user(nr, parent_tidptr);
73708
73709 + gr_handle_brute_check();
73710 +
73711 if (clone_flags & CLONE_VFORK) {
73712 p->vfork_done = &vfork;
73713 init_completion(&vfork);
73714 @@ -1755,7 +1834,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
73715 return 0;
73716
73717 /* don't need lock here; in the worst case we'll do useless copy */
73718 - if (fs->users == 1)
73719 + if (atomic_read(&fs->users) == 1)
73720 return 0;
73721
73722 *new_fsp = copy_fs_struct(fs);
73723 @@ -1869,7 +1948,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
73724 fs = current->fs;
73725 spin_lock(&fs->lock);
73726 current->fs = new_fs;
73727 - if (--fs->users)
73728 + gr_set_chroot_entries(current, &current->fs->root);
73729 + if (atomic_dec_return(&fs->users))
73730 new_fs = NULL;
73731 else
73732 new_fs = fs;
73733 diff --git a/kernel/futex.c b/kernel/futex.c
73734 index 8879430..31696f1 100644
73735 --- a/kernel/futex.c
73736 +++ b/kernel/futex.c
73737 @@ -54,6 +54,7 @@
73738 #include <linux/mount.h>
73739 #include <linux/pagemap.h>
73740 #include <linux/syscalls.h>
73741 +#include <linux/ptrace.h>
73742 #include <linux/signal.h>
73743 #include <linux/export.h>
73744 #include <linux/magic.h>
73745 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
73746 struct page *page, *page_head;
73747 int err, ro = 0;
73748
73749 +#ifdef CONFIG_PAX_SEGMEXEC
73750 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
73751 + return -EFAULT;
73752 +#endif
73753 +
73754 /*
73755 * The futex address must be "naturally" aligned.
73756 */
73757 @@ -2731,6 +2737,7 @@ static int __init futex_init(void)
73758 {
73759 u32 curval;
73760 int i;
73761 + mm_segment_t oldfs;
73762
73763 /*
73764 * This will fail and we want it. Some arch implementations do
73765 @@ -2742,8 +2749,11 @@ static int __init futex_init(void)
73766 * implementation, the non-functional ones will return
73767 * -ENOSYS.
73768 */
73769 + oldfs = get_fs();
73770 + set_fs(USER_DS);
73771 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
73772 futex_cmpxchg_enabled = 1;
73773 + set_fs(oldfs);
73774
73775 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
73776 plist_head_init(&futex_queues[i].chain);
73777 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
73778 index 9b22d03..6295b62 100644
73779 --- a/kernel/gcov/base.c
73780 +++ b/kernel/gcov/base.c
73781 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
73782 }
73783
73784 #ifdef CONFIG_MODULES
73785 -static inline int within(void *addr, void *start, unsigned long size)
73786 -{
73787 - return ((addr >= start) && (addr < start + size));
73788 -}
73789 -
73790 /* Update list and generate events when modules are unloaded. */
73791 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
73792 void *data)
73793 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
73794 prev = NULL;
73795 /* Remove entries located in module from linked list. */
73796 for (info = gcov_info_head; info; info = info->next) {
73797 - if (within(info, mod->module_core, mod->core_size)) {
73798 + if (within_module_core_rw((unsigned long)info, mod)) {
73799 if (prev)
73800 prev->next = info->next;
73801 else
73802 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
73803 index cdd5607..c3fc919 100644
73804 --- a/kernel/hrtimer.c
73805 +++ b/kernel/hrtimer.c
73806 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
73807 local_irq_restore(flags);
73808 }
73809
73810 -static void run_hrtimer_softirq(struct softirq_action *h)
73811 +static void run_hrtimer_softirq(void)
73812 {
73813 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
73814
73815 @@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
73816 return NOTIFY_OK;
73817 }
73818
73819 -static struct notifier_block __cpuinitdata hrtimers_nb = {
73820 +static struct notifier_block hrtimers_nb = {
73821 .notifier_call = hrtimer_cpu_notify,
73822 };
73823
73824 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
73825 index 60f48fa..7f3a770 100644
73826 --- a/kernel/jump_label.c
73827 +++ b/kernel/jump_label.c
73828 @@ -13,6 +13,7 @@
73829 #include <linux/sort.h>
73830 #include <linux/err.h>
73831 #include <linux/static_key.h>
73832 +#include <linux/mm.h>
73833
73834 #ifdef HAVE_JUMP_LABEL
73835
73836 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
73837
73838 size = (((unsigned long)stop - (unsigned long)start)
73839 / sizeof(struct jump_entry));
73840 + pax_open_kernel();
73841 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
73842 + pax_close_kernel();
73843 }
73844
73845 static void jump_label_update(struct static_key *key, int enable);
73846 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
73847 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
73848 struct jump_entry *iter;
73849
73850 + pax_open_kernel();
73851 for (iter = iter_start; iter < iter_stop; iter++) {
73852 if (within_module_init(iter->code, mod))
73853 iter->code = 0;
73854 }
73855 + pax_close_kernel();
73856 }
73857
73858 static int
73859 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
73860 index 2169fee..706ccca 100644
73861 --- a/kernel/kallsyms.c
73862 +++ b/kernel/kallsyms.c
73863 @@ -11,6 +11,9 @@
73864 * Changed the compression method from stem compression to "table lookup"
73865 * compression (see scripts/kallsyms.c for a more complete description)
73866 */
73867 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73868 +#define __INCLUDED_BY_HIDESYM 1
73869 +#endif
73870 #include <linux/kallsyms.h>
73871 #include <linux/module.h>
73872 #include <linux/init.h>
73873 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
73874
73875 static inline int is_kernel_inittext(unsigned long addr)
73876 {
73877 + if (system_state != SYSTEM_BOOTING)
73878 + return 0;
73879 +
73880 if (addr >= (unsigned long)_sinittext
73881 && addr <= (unsigned long)_einittext)
73882 return 1;
73883 return 0;
73884 }
73885
73886 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73887 +#ifdef CONFIG_MODULES
73888 +static inline int is_module_text(unsigned long addr)
73889 +{
73890 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
73891 + return 1;
73892 +
73893 + addr = ktla_ktva(addr);
73894 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
73895 +}
73896 +#else
73897 +static inline int is_module_text(unsigned long addr)
73898 +{
73899 + return 0;
73900 +}
73901 +#endif
73902 +#endif
73903 +
73904 static inline int is_kernel_text(unsigned long addr)
73905 {
73906 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
73907 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
73908
73909 static inline int is_kernel(unsigned long addr)
73910 {
73911 +
73912 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73913 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
73914 + return 1;
73915 +
73916 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
73917 +#else
73918 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
73919 +#endif
73920 +
73921 return 1;
73922 return in_gate_area_no_mm(addr);
73923 }
73924
73925 static int is_ksym_addr(unsigned long addr)
73926 {
73927 +
73928 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73929 + if (is_module_text(addr))
73930 + return 0;
73931 +#endif
73932 +
73933 if (all_var)
73934 return is_kernel(addr);
73935
73936 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
73937
73938 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
73939 {
73940 - iter->name[0] = '\0';
73941 iter->nameoff = get_symbol_offset(new_pos);
73942 iter->pos = new_pos;
73943 }
73944 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
73945 {
73946 struct kallsym_iter *iter = m->private;
73947
73948 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73949 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
73950 + return 0;
73951 +#endif
73952 +
73953 /* Some debugging symbols have no name. Ignore them. */
73954 if (!iter->name[0])
73955 return 0;
73956 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
73957 */
73958 type = iter->exported ? toupper(iter->type) :
73959 tolower(iter->type);
73960 +
73961 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
73962 type, iter->name, iter->module_name);
73963 } else
73964 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
73965 struct kallsym_iter *iter;
73966 int ret;
73967
73968 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
73969 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
73970 if (!iter)
73971 return -ENOMEM;
73972 reset_iter(iter, 0);
73973 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
73974 index e30ac0f..3528cac 100644
73975 --- a/kernel/kcmp.c
73976 +++ b/kernel/kcmp.c
73977 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
73978 struct task_struct *task1, *task2;
73979 int ret;
73980
73981 +#ifdef CONFIG_GRKERNSEC
73982 + return -ENOSYS;
73983 +#endif
73984 +
73985 rcu_read_lock();
73986
73987 /*
73988 diff --git a/kernel/kexec.c b/kernel/kexec.c
73989 index 5e4bd78..00c5b91 100644
73990 --- a/kernel/kexec.c
73991 +++ b/kernel/kexec.c
73992 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
73993 unsigned long flags)
73994 {
73995 struct compat_kexec_segment in;
73996 - struct kexec_segment out, __user *ksegments;
73997 + struct kexec_segment out;
73998 + struct kexec_segment __user *ksegments;
73999 unsigned long i, result;
74000
74001 /* Don't allow clients that don't understand the native
74002 diff --git a/kernel/kmod.c b/kernel/kmod.c
74003 index 0023a87..9c0c068 100644
74004 --- a/kernel/kmod.c
74005 +++ b/kernel/kmod.c
74006 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
74007 kfree(info->argv);
74008 }
74009
74010 -static int call_modprobe(char *module_name, int wait)
74011 +static int call_modprobe(char *module_name, char *module_param, int wait)
74012 {
74013 static char *envp[] = {
74014 "HOME=/",
74015 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
74016 NULL
74017 };
74018
74019 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
74020 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
74021 if (!argv)
74022 goto out;
74023
74024 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
74025 argv[1] = "-q";
74026 argv[2] = "--";
74027 argv[3] = module_name; /* check free_modprobe_argv() */
74028 - argv[4] = NULL;
74029 + argv[4] = module_param;
74030 + argv[5] = NULL;
74031
74032 return call_usermodehelper_fns(modprobe_path, argv, envp,
74033 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
74034 @@ -120,9 +121,8 @@ out:
74035 * If module auto-loading support is disabled then this function
74036 * becomes a no-operation.
74037 */
74038 -int __request_module(bool wait, const char *fmt, ...)
74039 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
74040 {
74041 - va_list args;
74042 char module_name[MODULE_NAME_LEN];
74043 unsigned int max_modprobes;
74044 int ret;
74045 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
74046 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
74047 static int kmod_loop_msg;
74048
74049 - va_start(args, fmt);
74050 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
74051 - va_end(args);
74052 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
74053 if (ret >= MODULE_NAME_LEN)
74054 return -ENAMETOOLONG;
74055
74056 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
74057 if (ret)
74058 return ret;
74059
74060 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74061 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74062 + /* hack to workaround consolekit/udisks stupidity */
74063 + read_lock(&tasklist_lock);
74064 + if (!strcmp(current->comm, "mount") &&
74065 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
74066 + read_unlock(&tasklist_lock);
74067 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
74068 + return -EPERM;
74069 + }
74070 + read_unlock(&tasklist_lock);
74071 + }
74072 +#endif
74073 +
74074 /* If modprobe needs a service that is in a module, we get a recursive
74075 * loop. Limit the number of running kmod threads to max_threads/2 or
74076 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
74077 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
74078
74079 trace_module_request(module_name, wait, _RET_IP_);
74080
74081 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74082 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74083
74084 atomic_dec(&kmod_concurrent);
74085 return ret;
74086 }
74087 +
74088 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
74089 +{
74090 + va_list args;
74091 + int ret;
74092 +
74093 + va_start(args, fmt);
74094 + ret = ____request_module(wait, module_param, fmt, args);
74095 + va_end(args);
74096 +
74097 + return ret;
74098 +}
74099 +
74100 +int __request_module(bool wait, const char *fmt, ...)
74101 +{
74102 + va_list args;
74103 + int ret;
74104 +
74105 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74106 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74107 + char module_param[MODULE_NAME_LEN];
74108 +
74109 + memset(module_param, 0, sizeof(module_param));
74110 +
74111 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
74112 +
74113 + va_start(args, fmt);
74114 + ret = ____request_module(wait, module_param, fmt, args);
74115 + va_end(args);
74116 +
74117 + return ret;
74118 + }
74119 +#endif
74120 +
74121 + va_start(args, fmt);
74122 + ret = ____request_module(wait, NULL, fmt, args);
74123 + va_end(args);
74124 +
74125 + return ret;
74126 +}
74127 +
74128 EXPORT_SYMBOL(__request_module);
74129 #endif /* CONFIG_MODULES */
74130
74131 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
74132 *
74133 * Thus the __user pointer cast is valid here.
74134 */
74135 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
74136 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
74137
74138 /*
74139 * If ret is 0, either ____call_usermodehelper failed and the
74140 @@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
74141 static int proc_cap_handler(struct ctl_table *table, int write,
74142 void __user *buffer, size_t *lenp, loff_t *ppos)
74143 {
74144 - struct ctl_table t;
74145 + ctl_table_no_const t;
74146 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
74147 kernel_cap_t new_cap;
74148 int err, i;
74149 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
74150 index 098f396..fe85ff1 100644
74151 --- a/kernel/kprobes.c
74152 +++ b/kernel/kprobes.c
74153 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
74154 * kernel image and loaded module images reside. This is required
74155 * so x86_64 can correctly handle the %rip-relative fixups.
74156 */
74157 - kip->insns = module_alloc(PAGE_SIZE);
74158 + kip->insns = module_alloc_exec(PAGE_SIZE);
74159 if (!kip->insns) {
74160 kfree(kip);
74161 return NULL;
74162 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
74163 */
74164 if (!list_is_singular(&kip->list)) {
74165 list_del(&kip->list);
74166 - module_free(NULL, kip->insns);
74167 + module_free_exec(NULL, kip->insns);
74168 kfree(kip);
74169 }
74170 return 1;
74171 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
74172 {
74173 int i, err = 0;
74174 unsigned long offset = 0, size = 0;
74175 - char *modname, namebuf[128];
74176 + char *modname, namebuf[KSYM_NAME_LEN];
74177 const char *symbol_name;
74178 void *addr;
74179 struct kprobe_blackpoint *kb;
74180 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
74181 kprobe_type = "k";
74182
74183 if (sym)
74184 - seq_printf(pi, "%p %s %s+0x%x %s ",
74185 + seq_printf(pi, "%pK %s %s+0x%x %s ",
74186 p->addr, kprobe_type, sym, offset,
74187 (modname ? modname : " "));
74188 else
74189 - seq_printf(pi, "%p %s %p ",
74190 + seq_printf(pi, "%pK %s %pK ",
74191 p->addr, kprobe_type, p->addr);
74192
74193 if (!pp)
74194 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
74195 const char *sym = NULL;
74196 unsigned int i = *(loff_t *) v;
74197 unsigned long offset = 0;
74198 - char *modname, namebuf[128];
74199 + char *modname, namebuf[KSYM_NAME_LEN];
74200
74201 head = &kprobe_table[i];
74202 preempt_disable();
74203 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
74204 index 6ada93c..dce7d5d 100644
74205 --- a/kernel/ksysfs.c
74206 +++ b/kernel/ksysfs.c
74207 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
74208 {
74209 if (count+1 > UEVENT_HELPER_PATH_LEN)
74210 return -ENOENT;
74211 + if (!capable(CAP_SYS_ADMIN))
74212 + return -EPERM;
74213 memcpy(uevent_helper, buf, count);
74214 uevent_helper[count] = '\0';
74215 if (count && uevent_helper[count-1] == '\n')
74216 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
74217 return count;
74218 }
74219
74220 -static struct bin_attribute notes_attr = {
74221 +static bin_attribute_no_const notes_attr __read_only = {
74222 .attr = {
74223 .name = "notes",
74224 .mode = S_IRUGO,
74225 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
74226 index 7981e5b..7f2105c 100644
74227 --- a/kernel/lockdep.c
74228 +++ b/kernel/lockdep.c
74229 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
74230 end = (unsigned long) &_end,
74231 addr = (unsigned long) obj;
74232
74233 +#ifdef CONFIG_PAX_KERNEXEC
74234 + start = ktla_ktva(start);
74235 +#endif
74236 +
74237 /*
74238 * static variable?
74239 */
74240 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
74241 if (!static_obj(lock->key)) {
74242 debug_locks_off();
74243 printk("INFO: trying to register non-static key.\n");
74244 + printk("lock:%pS key:%pS.\n", lock, lock->key);
74245 printk("the code is fine but needs lockdep annotation.\n");
74246 printk("turning off the locking correctness validator.\n");
74247 dump_stack();
74248 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
74249 if (!class)
74250 return 0;
74251 }
74252 - atomic_inc((atomic_t *)&class->ops);
74253 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
74254 if (very_verbose(class)) {
74255 printk("\nacquire class [%p] %s", class->key, class->name);
74256 if (class->name_version > 1)
74257 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
74258 index b2c71c5..7b88d63 100644
74259 --- a/kernel/lockdep_proc.c
74260 +++ b/kernel/lockdep_proc.c
74261 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
74262 return 0;
74263 }
74264
74265 - seq_printf(m, "%p", class->key);
74266 + seq_printf(m, "%pK", class->key);
74267 #ifdef CONFIG_DEBUG_LOCKDEP
74268 seq_printf(m, " OPS:%8ld", class->ops);
74269 #endif
74270 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
74271
74272 list_for_each_entry(entry, &class->locks_after, entry) {
74273 if (entry->distance == 1) {
74274 - seq_printf(m, " -> [%p] ", entry->class->key);
74275 + seq_printf(m, " -> [%pK] ", entry->class->key);
74276 print_name(m, entry->class);
74277 seq_puts(m, "\n");
74278 }
74279 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
74280 if (!class->key)
74281 continue;
74282
74283 - seq_printf(m, "[%p] ", class->key);
74284 + seq_printf(m, "[%pK] ", class->key);
74285 print_name(m, class);
74286 seq_puts(m, "\n");
74287 }
74288 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
74289 if (!i)
74290 seq_line(m, '-', 40-namelen, namelen);
74291
74292 - snprintf(ip, sizeof(ip), "[<%p>]",
74293 + snprintf(ip, sizeof(ip), "[<%pK>]",
74294 (void *)class->contention_point[i]);
74295 seq_printf(m, "%40s %14lu %29s %pS\n",
74296 name, stats->contention_point[i],
74297 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
74298 if (!i)
74299 seq_line(m, '-', 40-namelen, namelen);
74300
74301 - snprintf(ip, sizeof(ip), "[<%p>]",
74302 + snprintf(ip, sizeof(ip), "[<%pK>]",
74303 (void *)class->contending_point[i]);
74304 seq_printf(m, "%40s %14lu %29s %pS\n",
74305 name, stats->contending_point[i],
74306 diff --git a/kernel/module.c b/kernel/module.c
74307 index eab0827..f488603 100644
74308 --- a/kernel/module.c
74309 +++ b/kernel/module.c
74310 @@ -61,6 +61,7 @@
74311 #include <linux/pfn.h>
74312 #include <linux/bsearch.h>
74313 #include <linux/fips.h>
74314 +#include <linux/grsecurity.h>
74315 #include <uapi/linux/module.h>
74316 #include "module-internal.h"
74317
74318 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
74319
74320 /* Bounds of module allocation, for speeding __module_address.
74321 * Protected by module_mutex. */
74322 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
74323 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
74324 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
74325
74326 int register_module_notifier(struct notifier_block * nb)
74327 {
74328 @@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
74329 return true;
74330
74331 list_for_each_entry_rcu(mod, &modules, list) {
74332 - struct symsearch arr[] = {
74333 + struct symsearch modarr[] = {
74334 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
74335 NOT_GPL_ONLY, false },
74336 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
74337 @@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
74338 if (mod->state == MODULE_STATE_UNFORMED)
74339 continue;
74340
74341 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
74342 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
74343 return true;
74344 }
74345 return false;
74346 @@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
74347 static int percpu_modalloc(struct module *mod,
74348 unsigned long size, unsigned long align)
74349 {
74350 - if (align > PAGE_SIZE) {
74351 + if (align-1 >= PAGE_SIZE) {
74352 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
74353 mod->name, align, PAGE_SIZE);
74354 align = PAGE_SIZE;
74355 @@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
74356 static ssize_t show_coresize(struct module_attribute *mattr,
74357 struct module_kobject *mk, char *buffer)
74358 {
74359 - return sprintf(buffer, "%u\n", mk->mod->core_size);
74360 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
74361 }
74362
74363 static struct module_attribute modinfo_coresize =
74364 @@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
74365 static ssize_t show_initsize(struct module_attribute *mattr,
74366 struct module_kobject *mk, char *buffer)
74367 {
74368 - return sprintf(buffer, "%u\n", mk->mod->init_size);
74369 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
74370 }
74371
74372 static struct module_attribute modinfo_initsize =
74373 @@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
74374 */
74375 #ifdef CONFIG_SYSFS
74376
74377 -#ifdef CONFIG_KALLSYMS
74378 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74379 static inline bool sect_empty(const Elf_Shdr *sect)
74380 {
74381 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
74382 @@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
74383 {
74384 unsigned int notes, loaded, i;
74385 struct module_notes_attrs *notes_attrs;
74386 - struct bin_attribute *nattr;
74387 + bin_attribute_no_const *nattr;
74388
74389 /* failed to create section attributes, so can't create notes */
74390 if (!mod->sect_attrs)
74391 @@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
74392 static int module_add_modinfo_attrs(struct module *mod)
74393 {
74394 struct module_attribute *attr;
74395 - struct module_attribute *temp_attr;
74396 + module_attribute_no_const *temp_attr;
74397 int error = 0;
74398 int i;
74399
74400 @@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
74401
74402 static void unset_module_core_ro_nx(struct module *mod)
74403 {
74404 - set_page_attributes(mod->module_core + mod->core_text_size,
74405 - mod->module_core + mod->core_size,
74406 + set_page_attributes(mod->module_core_rw,
74407 + mod->module_core_rw + mod->core_size_rw,
74408 set_memory_x);
74409 - set_page_attributes(mod->module_core,
74410 - mod->module_core + mod->core_ro_size,
74411 + set_page_attributes(mod->module_core_rx,
74412 + mod->module_core_rx + mod->core_size_rx,
74413 set_memory_rw);
74414 }
74415
74416 static void unset_module_init_ro_nx(struct module *mod)
74417 {
74418 - set_page_attributes(mod->module_init + mod->init_text_size,
74419 - mod->module_init + mod->init_size,
74420 + set_page_attributes(mod->module_init_rw,
74421 + mod->module_init_rw + mod->init_size_rw,
74422 set_memory_x);
74423 - set_page_attributes(mod->module_init,
74424 - mod->module_init + mod->init_ro_size,
74425 + set_page_attributes(mod->module_init_rx,
74426 + mod->module_init_rx + mod->init_size_rx,
74427 set_memory_rw);
74428 }
74429
74430 @@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
74431 list_for_each_entry_rcu(mod, &modules, list) {
74432 if (mod->state == MODULE_STATE_UNFORMED)
74433 continue;
74434 - if ((mod->module_core) && (mod->core_text_size)) {
74435 - set_page_attributes(mod->module_core,
74436 - mod->module_core + mod->core_text_size,
74437 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
74438 + set_page_attributes(mod->module_core_rx,
74439 + mod->module_core_rx + mod->core_size_rx,
74440 set_memory_rw);
74441 }
74442 - if ((mod->module_init) && (mod->init_text_size)) {
74443 - set_page_attributes(mod->module_init,
74444 - mod->module_init + mod->init_text_size,
74445 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
74446 + set_page_attributes(mod->module_init_rx,
74447 + mod->module_init_rx + mod->init_size_rx,
74448 set_memory_rw);
74449 }
74450 }
74451 @@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
74452 list_for_each_entry_rcu(mod, &modules, list) {
74453 if (mod->state == MODULE_STATE_UNFORMED)
74454 continue;
74455 - if ((mod->module_core) && (mod->core_text_size)) {
74456 - set_page_attributes(mod->module_core,
74457 - mod->module_core + mod->core_text_size,
74458 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
74459 + set_page_attributes(mod->module_core_rx,
74460 + mod->module_core_rx + mod->core_size_rx,
74461 set_memory_ro);
74462 }
74463 - if ((mod->module_init) && (mod->init_text_size)) {
74464 - set_page_attributes(mod->module_init,
74465 - mod->module_init + mod->init_text_size,
74466 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
74467 + set_page_attributes(mod->module_init_rx,
74468 + mod->module_init_rx + mod->init_size_rx,
74469 set_memory_ro);
74470 }
74471 }
74472 @@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
74473
74474 /* This may be NULL, but that's OK */
74475 unset_module_init_ro_nx(mod);
74476 - module_free(mod, mod->module_init);
74477 + module_free(mod, mod->module_init_rw);
74478 + module_free_exec(mod, mod->module_init_rx);
74479 kfree(mod->args);
74480 percpu_modfree(mod);
74481
74482 /* Free lock-classes: */
74483 - lockdep_free_key_range(mod->module_core, mod->core_size);
74484 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
74485 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
74486
74487 /* Finally, free the core (containing the module structure) */
74488 unset_module_core_ro_nx(mod);
74489 - module_free(mod, mod->module_core);
74490 + module_free_exec(mod, mod->module_core_rx);
74491 + module_free(mod, mod->module_core_rw);
74492
74493 #ifdef CONFIG_MPU
74494 update_protections(current->mm);
74495 @@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74496 int ret = 0;
74497 const struct kernel_symbol *ksym;
74498
74499 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74500 + int is_fs_load = 0;
74501 + int register_filesystem_found = 0;
74502 + char *p;
74503 +
74504 + p = strstr(mod->args, "grsec_modharden_fs");
74505 + if (p) {
74506 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
74507 + /* copy \0 as well */
74508 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
74509 + is_fs_load = 1;
74510 + }
74511 +#endif
74512 +
74513 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
74514 const char *name = info->strtab + sym[i].st_name;
74515
74516 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74517 + /* it's a real shame this will never get ripped and copied
74518 + upstream! ;(
74519 + */
74520 + if (is_fs_load && !strcmp(name, "register_filesystem"))
74521 + register_filesystem_found = 1;
74522 +#endif
74523 +
74524 switch (sym[i].st_shndx) {
74525 case SHN_COMMON:
74526 /* We compiled with -fno-common. These are not
74527 @@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74528 ksym = resolve_symbol_wait(mod, info, name);
74529 /* Ok if resolved. */
74530 if (ksym && !IS_ERR(ksym)) {
74531 + pax_open_kernel();
74532 sym[i].st_value = ksym->value;
74533 + pax_close_kernel();
74534 break;
74535 }
74536
74537 @@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74538 secbase = (unsigned long)mod_percpu(mod);
74539 else
74540 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
74541 + pax_open_kernel();
74542 sym[i].st_value += secbase;
74543 + pax_close_kernel();
74544 break;
74545 }
74546 }
74547
74548 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74549 + if (is_fs_load && !register_filesystem_found) {
74550 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
74551 + ret = -EPERM;
74552 + }
74553 +#endif
74554 +
74555 return ret;
74556 }
74557
74558 @@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
74559 || s->sh_entsize != ~0UL
74560 || strstarts(sname, ".init"))
74561 continue;
74562 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
74563 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
74564 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
74565 + else
74566 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
74567 pr_debug("\t%s\n", sname);
74568 }
74569 - switch (m) {
74570 - case 0: /* executable */
74571 - mod->core_size = debug_align(mod->core_size);
74572 - mod->core_text_size = mod->core_size;
74573 - break;
74574 - case 1: /* RO: text and ro-data */
74575 - mod->core_size = debug_align(mod->core_size);
74576 - mod->core_ro_size = mod->core_size;
74577 - break;
74578 - case 3: /* whole core */
74579 - mod->core_size = debug_align(mod->core_size);
74580 - break;
74581 - }
74582 }
74583
74584 pr_debug("Init section allocation order:\n");
74585 @@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
74586 || s->sh_entsize != ~0UL
74587 || !strstarts(sname, ".init"))
74588 continue;
74589 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
74590 - | INIT_OFFSET_MASK);
74591 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
74592 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
74593 + else
74594 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
74595 + s->sh_entsize |= INIT_OFFSET_MASK;
74596 pr_debug("\t%s\n", sname);
74597 }
74598 - switch (m) {
74599 - case 0: /* executable */
74600 - mod->init_size = debug_align(mod->init_size);
74601 - mod->init_text_size = mod->init_size;
74602 - break;
74603 - case 1: /* RO: text and ro-data */
74604 - mod->init_size = debug_align(mod->init_size);
74605 - mod->init_ro_size = mod->init_size;
74606 - break;
74607 - case 3: /* whole init */
74608 - mod->init_size = debug_align(mod->init_size);
74609 - break;
74610 - }
74611 }
74612 }
74613
74614 @@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
74615
74616 /* Put symbol section at end of init part of module. */
74617 symsect->sh_flags |= SHF_ALLOC;
74618 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
74619 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
74620 info->index.sym) | INIT_OFFSET_MASK;
74621 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
74622
74623 @@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
74624 }
74625
74626 /* Append room for core symbols at end of core part. */
74627 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
74628 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
74629 - mod->core_size += strtab_size;
74630 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
74631 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
74632 + mod->core_size_rx += strtab_size;
74633
74634 /* Put string table section at end of init part of module. */
74635 strsect->sh_flags |= SHF_ALLOC;
74636 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
74637 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
74638 info->index.str) | INIT_OFFSET_MASK;
74639 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
74640 }
74641 @@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
74642 /* Make sure we get permanent strtab: don't use info->strtab. */
74643 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
74644
74645 + pax_open_kernel();
74646 +
74647 /* Set types up while we still have access to sections. */
74648 for (i = 0; i < mod->num_symtab; i++)
74649 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
74650
74651 - mod->core_symtab = dst = mod->module_core + info->symoffs;
74652 - mod->core_strtab = s = mod->module_core + info->stroffs;
74653 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
74654 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
74655 src = mod->symtab;
74656 for (ndst = i = 0; i < mod->num_symtab; i++) {
74657 if (i == 0 ||
74658 @@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
74659 }
74660 }
74661 mod->core_num_syms = ndst;
74662 +
74663 + pax_close_kernel();
74664 }
74665 #else
74666 static inline void layout_symtab(struct module *mod, struct load_info *info)
74667 @@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
74668 return vmalloc_exec(size);
74669 }
74670
74671 -static void *module_alloc_update_bounds(unsigned long size)
74672 +static void *module_alloc_update_bounds_rw(unsigned long size)
74673 {
74674 void *ret = module_alloc(size);
74675
74676 if (ret) {
74677 mutex_lock(&module_mutex);
74678 /* Update module bounds. */
74679 - if ((unsigned long)ret < module_addr_min)
74680 - module_addr_min = (unsigned long)ret;
74681 - if ((unsigned long)ret + size > module_addr_max)
74682 - module_addr_max = (unsigned long)ret + size;
74683 + if ((unsigned long)ret < module_addr_min_rw)
74684 + module_addr_min_rw = (unsigned long)ret;
74685 + if ((unsigned long)ret + size > module_addr_max_rw)
74686 + module_addr_max_rw = (unsigned long)ret + size;
74687 + mutex_unlock(&module_mutex);
74688 + }
74689 + return ret;
74690 +}
74691 +
74692 +static void *module_alloc_update_bounds_rx(unsigned long size)
74693 +{
74694 + void *ret = module_alloc_exec(size);
74695 +
74696 + if (ret) {
74697 + mutex_lock(&module_mutex);
74698 + /* Update module bounds. */
74699 + if ((unsigned long)ret < module_addr_min_rx)
74700 + module_addr_min_rx = (unsigned long)ret;
74701 + if ((unsigned long)ret + size > module_addr_max_rx)
74702 + module_addr_max_rx = (unsigned long)ret + size;
74703 mutex_unlock(&module_mutex);
74704 }
74705 return ret;
74706 @@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
74707 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
74708 {
74709 const char *modmagic = get_modinfo(info, "vermagic");
74710 + const char *license = get_modinfo(info, "license");
74711 int err;
74712
74713 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
74714 + if (!license || !license_is_gpl_compatible(license))
74715 + return -ENOEXEC;
74716 +#endif
74717 +
74718 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
74719 modmagic = NULL;
74720
74721 @@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
74722 }
74723
74724 /* Set up license info based on the info section */
74725 - set_license(mod, get_modinfo(info, "license"));
74726 + set_license(mod, license);
74727
74728 return 0;
74729 }
74730 @@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
74731 void *ptr;
74732
74733 /* Do the allocs. */
74734 - ptr = module_alloc_update_bounds(mod->core_size);
74735 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
74736 /*
74737 * The pointer to this block is stored in the module structure
74738 * which is inside the block. Just mark it as not being a
74739 @@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
74740 if (!ptr)
74741 return -ENOMEM;
74742
74743 - memset(ptr, 0, mod->core_size);
74744 - mod->module_core = ptr;
74745 + memset(ptr, 0, mod->core_size_rw);
74746 + mod->module_core_rw = ptr;
74747
74748 - if (mod->init_size) {
74749 - ptr = module_alloc_update_bounds(mod->init_size);
74750 + if (mod->init_size_rw) {
74751 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
74752 /*
74753 * The pointer to this block is stored in the module structure
74754 * which is inside the block. This block doesn't need to be
74755 @@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
74756 */
74757 kmemleak_ignore(ptr);
74758 if (!ptr) {
74759 - module_free(mod, mod->module_core);
74760 + module_free(mod, mod->module_core_rw);
74761 return -ENOMEM;
74762 }
74763 - memset(ptr, 0, mod->init_size);
74764 - mod->module_init = ptr;
74765 + memset(ptr, 0, mod->init_size_rw);
74766 + mod->module_init_rw = ptr;
74767 } else
74768 - mod->module_init = NULL;
74769 + mod->module_init_rw = NULL;
74770 +
74771 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
74772 + kmemleak_not_leak(ptr);
74773 + if (!ptr) {
74774 + if (mod->module_init_rw)
74775 + module_free(mod, mod->module_init_rw);
74776 + module_free(mod, mod->module_core_rw);
74777 + return -ENOMEM;
74778 + }
74779 +
74780 + pax_open_kernel();
74781 + memset(ptr, 0, mod->core_size_rx);
74782 + pax_close_kernel();
74783 + mod->module_core_rx = ptr;
74784 +
74785 + if (mod->init_size_rx) {
74786 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
74787 + kmemleak_ignore(ptr);
74788 + if (!ptr && mod->init_size_rx) {
74789 + module_free_exec(mod, mod->module_core_rx);
74790 + if (mod->module_init_rw)
74791 + module_free(mod, mod->module_init_rw);
74792 + module_free(mod, mod->module_core_rw);
74793 + return -ENOMEM;
74794 + }
74795 +
74796 + pax_open_kernel();
74797 + memset(ptr, 0, mod->init_size_rx);
74798 + pax_close_kernel();
74799 + mod->module_init_rx = ptr;
74800 + } else
74801 + mod->module_init_rx = NULL;
74802
74803 /* Transfer each section which specifies SHF_ALLOC */
74804 pr_debug("final section addresses:\n");
74805 @@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
74806 if (!(shdr->sh_flags & SHF_ALLOC))
74807 continue;
74808
74809 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
74810 - dest = mod->module_init
74811 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74812 - else
74813 - dest = mod->module_core + shdr->sh_entsize;
74814 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
74815 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
74816 + dest = mod->module_init_rw
74817 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74818 + else
74819 + dest = mod->module_init_rx
74820 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74821 + } else {
74822 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
74823 + dest = mod->module_core_rw + shdr->sh_entsize;
74824 + else
74825 + dest = mod->module_core_rx + shdr->sh_entsize;
74826 + }
74827 +
74828 + if (shdr->sh_type != SHT_NOBITS) {
74829 +
74830 +#ifdef CONFIG_PAX_KERNEXEC
74831 +#ifdef CONFIG_X86_64
74832 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
74833 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
74834 +#endif
74835 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
74836 + pax_open_kernel();
74837 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
74838 + pax_close_kernel();
74839 + } else
74840 +#endif
74841
74842 - if (shdr->sh_type != SHT_NOBITS)
74843 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
74844 + }
74845 /* Update sh_addr to point to copy in image. */
74846 - shdr->sh_addr = (unsigned long)dest;
74847 +
74848 +#ifdef CONFIG_PAX_KERNEXEC
74849 + if (shdr->sh_flags & SHF_EXECINSTR)
74850 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
74851 + else
74852 +#endif
74853 +
74854 + shdr->sh_addr = (unsigned long)dest;
74855 pr_debug("\t0x%lx %s\n",
74856 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
74857 }
74858 @@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
74859 * Do it before processing of module parameters, so the module
74860 * can provide parameter accessor functions of its own.
74861 */
74862 - if (mod->module_init)
74863 - flush_icache_range((unsigned long)mod->module_init,
74864 - (unsigned long)mod->module_init
74865 - + mod->init_size);
74866 - flush_icache_range((unsigned long)mod->module_core,
74867 - (unsigned long)mod->module_core + mod->core_size);
74868 + if (mod->module_init_rx)
74869 + flush_icache_range((unsigned long)mod->module_init_rx,
74870 + (unsigned long)mod->module_init_rx
74871 + + mod->init_size_rx);
74872 + flush_icache_range((unsigned long)mod->module_core_rx,
74873 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
74874
74875 set_fs(old_fs);
74876 }
74877 @@ -2983,8 +3088,10 @@ out:
74878 static void module_deallocate(struct module *mod, struct load_info *info)
74879 {
74880 percpu_modfree(mod);
74881 - module_free(mod, mod->module_init);
74882 - module_free(mod, mod->module_core);
74883 + module_free_exec(mod, mod->module_init_rx);
74884 + module_free_exec(mod, mod->module_core_rx);
74885 + module_free(mod, mod->module_init_rw);
74886 + module_free(mod, mod->module_core_rw);
74887 }
74888
74889 int __weak module_finalize(const Elf_Ehdr *hdr,
74890 @@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
74891 static int post_relocation(struct module *mod, const struct load_info *info)
74892 {
74893 /* Sort exception table now relocations are done. */
74894 + pax_open_kernel();
74895 sort_extable(mod->extable, mod->extable + mod->num_exentries);
74896 + pax_close_kernel();
74897
74898 /* Copy relocated percpu area over. */
74899 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
74900 @@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
74901 MODULE_STATE_COMING, mod);
74902
74903 /* Set RO and NX regions for core */
74904 - set_section_ro_nx(mod->module_core,
74905 - mod->core_text_size,
74906 - mod->core_ro_size,
74907 - mod->core_size);
74908 + set_section_ro_nx(mod->module_core_rx,
74909 + mod->core_size_rx,
74910 + mod->core_size_rx,
74911 + mod->core_size_rx);
74912
74913 /* Set RO and NX regions for init */
74914 - set_section_ro_nx(mod->module_init,
74915 - mod->init_text_size,
74916 - mod->init_ro_size,
74917 - mod->init_size);
74918 + set_section_ro_nx(mod->module_init_rx,
74919 + mod->init_size_rx,
74920 + mod->init_size_rx,
74921 + mod->init_size_rx);
74922
74923 do_mod_ctors(mod);
74924 /* Start the module */
74925 @@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
74926 mod->strtab = mod->core_strtab;
74927 #endif
74928 unset_module_init_ro_nx(mod);
74929 - module_free(mod, mod->module_init);
74930 - mod->module_init = NULL;
74931 - mod->init_size = 0;
74932 - mod->init_ro_size = 0;
74933 - mod->init_text_size = 0;
74934 + module_free(mod, mod->module_init_rw);
74935 + module_free_exec(mod, mod->module_init_rx);
74936 + mod->module_init_rw = NULL;
74937 + mod->module_init_rx = NULL;
74938 + mod->init_size_rw = 0;
74939 + mod->init_size_rx = 0;
74940 mutex_unlock(&module_mutex);
74941 wake_up_all(&module_wq);
74942
74943 @@ -3209,9 +3319,38 @@ again:
74944 if (err)
74945 goto free_unload;
74946
74947 + /* Now copy in args */
74948 + mod->args = strndup_user(uargs, ~0UL >> 1);
74949 + if (IS_ERR(mod->args)) {
74950 + err = PTR_ERR(mod->args);
74951 + goto free_unload;
74952 + }
74953 +
74954 /* Set up MODINFO_ATTR fields */
74955 setup_modinfo(mod, info);
74956
74957 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74958 + {
74959 + char *p, *p2;
74960 +
74961 + if (strstr(mod->args, "grsec_modharden_netdev")) {
74962 + 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);
74963 + err = -EPERM;
74964 + goto free_modinfo;
74965 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
74966 + p += sizeof("grsec_modharden_normal") - 1;
74967 + p2 = strstr(p, "_");
74968 + if (p2) {
74969 + *p2 = '\0';
74970 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
74971 + *p2 = '_';
74972 + }
74973 + err = -EPERM;
74974 + goto free_modinfo;
74975 + }
74976 + }
74977 +#endif
74978 +
74979 /* Fix up syms, so that st_value is a pointer to location. */
74980 err = simplify_symbols(mod, info);
74981 if (err < 0)
74982 @@ -3227,13 +3366,6 @@ again:
74983
74984 flush_module_icache(mod);
74985
74986 - /* Now copy in args */
74987 - mod->args = strndup_user(uargs, ~0UL >> 1);
74988 - if (IS_ERR(mod->args)) {
74989 - err = PTR_ERR(mod->args);
74990 - goto free_arch_cleanup;
74991 - }
74992 -
74993 dynamic_debug_setup(info->debug, info->num_debug);
74994
74995 mutex_lock(&module_mutex);
74996 @@ -3278,11 +3410,10 @@ again:
74997 mutex_unlock(&module_mutex);
74998 dynamic_debug_remove(info->debug);
74999 synchronize_sched();
75000 - kfree(mod->args);
75001 - free_arch_cleanup:
75002 module_arch_cleanup(mod);
75003 free_modinfo:
75004 free_modinfo(mod);
75005 + kfree(mod->args);
75006 free_unload:
75007 module_unload_free(mod);
75008 unlink_mod:
75009 @@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
75010 unsigned long nextval;
75011
75012 /* At worse, next value is at end of module */
75013 - if (within_module_init(addr, mod))
75014 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
75015 + if (within_module_init_rx(addr, mod))
75016 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
75017 + else if (within_module_init_rw(addr, mod))
75018 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
75019 + else if (within_module_core_rx(addr, mod))
75020 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
75021 + else if (within_module_core_rw(addr, mod))
75022 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
75023 else
75024 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
75025 + return NULL;
75026
75027 /* Scan for closest preceding symbol, and next symbol. (ELF
75028 starts real symbols at 1). */
75029 @@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
75030 return 0;
75031
75032 seq_printf(m, "%s %u",
75033 - mod->name, mod->init_size + mod->core_size);
75034 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
75035 print_unload_info(m, mod);
75036
75037 /* Informative for users. */
75038 @@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
75039 mod->state == MODULE_STATE_COMING ? "Loading":
75040 "Live");
75041 /* Used by oprofile and other similar tools. */
75042 - seq_printf(m, " 0x%pK", mod->module_core);
75043 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
75044
75045 /* Taints info */
75046 if (mod->taints)
75047 @@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
75048
75049 static int __init proc_modules_init(void)
75050 {
75051 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75052 +#ifdef CONFIG_GRKERNSEC_PROC_USER
75053 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75054 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75055 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
75056 +#else
75057 proc_create("modules", 0, NULL, &proc_modules_operations);
75058 +#endif
75059 +#else
75060 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75061 +#endif
75062 return 0;
75063 }
75064 module_init(proc_modules_init);
75065 @@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
75066 {
75067 struct module *mod;
75068
75069 - if (addr < module_addr_min || addr > module_addr_max)
75070 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
75071 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
75072 return NULL;
75073
75074 list_for_each_entry_rcu(mod, &modules, list) {
75075 if (mod->state == MODULE_STATE_UNFORMED)
75076 continue;
75077 - if (within_module_core(addr, mod)
75078 - || within_module_init(addr, mod))
75079 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
75080 return mod;
75081 }
75082 return NULL;
75083 @@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
75084 */
75085 struct module *__module_text_address(unsigned long addr)
75086 {
75087 - struct module *mod = __module_address(addr);
75088 + struct module *mod;
75089 +
75090 +#ifdef CONFIG_X86_32
75091 + addr = ktla_ktva(addr);
75092 +#endif
75093 +
75094 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
75095 + return NULL;
75096 +
75097 + mod = __module_address(addr);
75098 +
75099 if (mod) {
75100 /* Make sure it's within the text section. */
75101 - if (!within(addr, mod->module_init, mod->init_text_size)
75102 - && !within(addr, mod->module_core, mod->core_text_size))
75103 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
75104 mod = NULL;
75105 }
75106 return mod;
75107 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
75108 index 7e3443f..b2a1e6b 100644
75109 --- a/kernel/mutex-debug.c
75110 +++ b/kernel/mutex-debug.c
75111 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
75112 }
75113
75114 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75115 - struct thread_info *ti)
75116 + struct task_struct *task)
75117 {
75118 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
75119
75120 /* Mark the current thread as blocked on the lock: */
75121 - ti->task->blocked_on = waiter;
75122 + task->blocked_on = waiter;
75123 }
75124
75125 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75126 - struct thread_info *ti)
75127 + struct task_struct *task)
75128 {
75129 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
75130 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
75131 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
75132 - ti->task->blocked_on = NULL;
75133 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
75134 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
75135 + task->blocked_on = NULL;
75136
75137 list_del_init(&waiter->list);
75138 waiter->task = NULL;
75139 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
75140 index 0799fd3..d06ae3b 100644
75141 --- a/kernel/mutex-debug.h
75142 +++ b/kernel/mutex-debug.h
75143 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
75144 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
75145 extern void debug_mutex_add_waiter(struct mutex *lock,
75146 struct mutex_waiter *waiter,
75147 - struct thread_info *ti);
75148 + struct task_struct *task);
75149 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75150 - struct thread_info *ti);
75151 + struct task_struct *task);
75152 extern void debug_mutex_unlock(struct mutex *lock);
75153 extern void debug_mutex_init(struct mutex *lock, const char *name,
75154 struct lock_class_key *key);
75155 diff --git a/kernel/mutex.c b/kernel/mutex.c
75156 index a307cc9..27fd2e9 100644
75157 --- a/kernel/mutex.c
75158 +++ b/kernel/mutex.c
75159 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75160 spin_lock_mutex(&lock->wait_lock, flags);
75161
75162 debug_mutex_lock_common(lock, &waiter);
75163 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
75164 + debug_mutex_add_waiter(lock, &waiter, task);
75165
75166 /* add waiting tasks to the end of the waitqueue (FIFO): */
75167 list_add_tail(&waiter.list, &lock->wait_list);
75168 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75169 * TASK_UNINTERRUPTIBLE case.)
75170 */
75171 if (unlikely(signal_pending_state(state, task))) {
75172 - mutex_remove_waiter(lock, &waiter,
75173 - task_thread_info(task));
75174 + mutex_remove_waiter(lock, &waiter, task);
75175 mutex_release(&lock->dep_map, 1, ip);
75176 spin_unlock_mutex(&lock->wait_lock, flags);
75177
75178 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75179 done:
75180 lock_acquired(&lock->dep_map, ip);
75181 /* got the lock - rejoice! */
75182 - mutex_remove_waiter(lock, &waiter, current_thread_info());
75183 + mutex_remove_waiter(lock, &waiter, task);
75184 mutex_set_owner(lock);
75185
75186 /* set it to 0 if there are no waiters left: */
75187 diff --git a/kernel/notifier.c b/kernel/notifier.c
75188 index 2d5cc4c..d9ea600 100644
75189 --- a/kernel/notifier.c
75190 +++ b/kernel/notifier.c
75191 @@ -5,6 +5,7 @@
75192 #include <linux/rcupdate.h>
75193 #include <linux/vmalloc.h>
75194 #include <linux/reboot.h>
75195 +#include <linux/mm.h>
75196
75197 /*
75198 * Notifier list for kernel code which wants to be called
75199 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
75200 while ((*nl) != NULL) {
75201 if (n->priority > (*nl)->priority)
75202 break;
75203 - nl = &((*nl)->next);
75204 + nl = (struct notifier_block **)&((*nl)->next);
75205 }
75206 - n->next = *nl;
75207 + pax_open_kernel();
75208 + *(const void **)&n->next = *nl;
75209 rcu_assign_pointer(*nl, n);
75210 + pax_close_kernel();
75211 return 0;
75212 }
75213
75214 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
75215 return 0;
75216 if (n->priority > (*nl)->priority)
75217 break;
75218 - nl = &((*nl)->next);
75219 + nl = (struct notifier_block **)&((*nl)->next);
75220 }
75221 - n->next = *nl;
75222 + pax_open_kernel();
75223 + *(const void **)&n->next = *nl;
75224 rcu_assign_pointer(*nl, n);
75225 + pax_close_kernel();
75226 return 0;
75227 }
75228
75229 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
75230 {
75231 while ((*nl) != NULL) {
75232 if ((*nl) == n) {
75233 + pax_open_kernel();
75234 rcu_assign_pointer(*nl, n->next);
75235 + pax_close_kernel();
75236 return 0;
75237 }
75238 - nl = &((*nl)->next);
75239 + nl = (struct notifier_block **)&((*nl)->next);
75240 }
75241 return -ENOENT;
75242 }
75243 diff --git a/kernel/panic.c b/kernel/panic.c
75244 index e1b2822..5edc1d9 100644
75245 --- a/kernel/panic.c
75246 +++ b/kernel/panic.c
75247 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
75248 const char *board;
75249
75250 printk(KERN_WARNING "------------[ cut here ]------------\n");
75251 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
75252 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
75253 board = dmi_get_system_info(DMI_PRODUCT_NAME);
75254 if (board)
75255 printk(KERN_WARNING "Hardware name: %s\n", board);
75256 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
75257 */
75258 void __stack_chk_fail(void)
75259 {
75260 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
75261 + dump_stack();
75262 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
75263 __builtin_return_address(0));
75264 }
75265 EXPORT_SYMBOL(__stack_chk_fail);
75266 diff --git a/kernel/pid.c b/kernel/pid.c
75267 index f2c6a68..4922d97 100644
75268 --- a/kernel/pid.c
75269 +++ b/kernel/pid.c
75270 @@ -33,6 +33,7 @@
75271 #include <linux/rculist.h>
75272 #include <linux/bootmem.h>
75273 #include <linux/hash.h>
75274 +#include <linux/security.h>
75275 #include <linux/pid_namespace.h>
75276 #include <linux/init_task.h>
75277 #include <linux/syscalls.h>
75278 @@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
75279
75280 int pid_max = PID_MAX_DEFAULT;
75281
75282 -#define RESERVED_PIDS 300
75283 +#define RESERVED_PIDS 500
75284
75285 int pid_max_min = RESERVED_PIDS + 1;
75286 int pid_max_max = PID_MAX_LIMIT;
75287 @@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
75288 */
75289 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
75290 {
75291 + struct task_struct *task;
75292 +
75293 rcu_lockdep_assert(rcu_read_lock_held(),
75294 "find_task_by_pid_ns() needs rcu_read_lock()"
75295 " protection");
75296 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
75297 +
75298 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
75299 +
75300 + if (gr_pid_is_chrooted(task))
75301 + return NULL;
75302 +
75303 + return task;
75304 }
75305
75306 struct task_struct *find_task_by_vpid(pid_t vnr)
75307 @@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
75308 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
75309 }
75310
75311 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
75312 +{
75313 + rcu_lockdep_assert(rcu_read_lock_held(),
75314 + "find_task_by_pid_ns() needs rcu_read_lock()"
75315 + " protection");
75316 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
75317 +}
75318 +
75319 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
75320 {
75321 struct pid *pid;
75322 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
75323 index c1c3dc1..bbeaf31 100644
75324 --- a/kernel/pid_namespace.c
75325 +++ b/kernel/pid_namespace.c
75326 @@ -248,7 +248,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
75327 void __user *buffer, size_t *lenp, loff_t *ppos)
75328 {
75329 struct pid_namespace *pid_ns = task_active_pid_ns(current);
75330 - struct ctl_table tmp = *table;
75331 + ctl_table_no_const tmp = *table;
75332
75333 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
75334 return -EPERM;
75335 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
75336 index 942ca27..111e609 100644
75337 --- a/kernel/posix-cpu-timers.c
75338 +++ b/kernel/posix-cpu-timers.c
75339 @@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
75340
75341 static __init int init_posix_cpu_timers(void)
75342 {
75343 - struct k_clock process = {
75344 + static struct k_clock process = {
75345 .clock_getres = process_cpu_clock_getres,
75346 .clock_get = process_cpu_clock_get,
75347 .timer_create = process_cpu_timer_create,
75348 .nsleep = process_cpu_nsleep,
75349 .nsleep_restart = process_cpu_nsleep_restart,
75350 };
75351 - struct k_clock thread = {
75352 + static struct k_clock thread = {
75353 .clock_getres = thread_cpu_clock_getres,
75354 .clock_get = thread_cpu_clock_get,
75355 .timer_create = thread_cpu_timer_create,
75356 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
75357 index e885be1..380fe76 100644
75358 --- a/kernel/posix-timers.c
75359 +++ b/kernel/posix-timers.c
75360 @@ -43,6 +43,7 @@
75361 #include <linux/idr.h>
75362 #include <linux/posix-clock.h>
75363 #include <linux/posix-timers.h>
75364 +#include <linux/grsecurity.h>
75365 #include <linux/syscalls.h>
75366 #include <linux/wait.h>
75367 #include <linux/workqueue.h>
75368 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
75369 * which we beg off on and pass to do_sys_settimeofday().
75370 */
75371
75372 -static struct k_clock posix_clocks[MAX_CLOCKS];
75373 +static struct k_clock *posix_clocks[MAX_CLOCKS];
75374
75375 /*
75376 * These ones are defined below.
75377 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
75378 */
75379 static __init int init_posix_timers(void)
75380 {
75381 - struct k_clock clock_realtime = {
75382 + static struct k_clock clock_realtime = {
75383 .clock_getres = hrtimer_get_res,
75384 .clock_get = posix_clock_realtime_get,
75385 .clock_set = posix_clock_realtime_set,
75386 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
75387 .timer_get = common_timer_get,
75388 .timer_del = common_timer_del,
75389 };
75390 - struct k_clock clock_monotonic = {
75391 + static struct k_clock clock_monotonic = {
75392 .clock_getres = hrtimer_get_res,
75393 .clock_get = posix_ktime_get_ts,
75394 .nsleep = common_nsleep,
75395 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
75396 .timer_get = common_timer_get,
75397 .timer_del = common_timer_del,
75398 };
75399 - struct k_clock clock_monotonic_raw = {
75400 + static struct k_clock clock_monotonic_raw = {
75401 .clock_getres = hrtimer_get_res,
75402 .clock_get = posix_get_monotonic_raw,
75403 };
75404 - struct k_clock clock_realtime_coarse = {
75405 + static struct k_clock clock_realtime_coarse = {
75406 .clock_getres = posix_get_coarse_res,
75407 .clock_get = posix_get_realtime_coarse,
75408 };
75409 - struct k_clock clock_monotonic_coarse = {
75410 + static struct k_clock clock_monotonic_coarse = {
75411 .clock_getres = posix_get_coarse_res,
75412 .clock_get = posix_get_monotonic_coarse,
75413 };
75414 - struct k_clock clock_boottime = {
75415 + static struct k_clock clock_boottime = {
75416 .clock_getres = hrtimer_get_res,
75417 .clock_get = posix_get_boottime,
75418 .nsleep = common_nsleep,
75419 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
75420 return;
75421 }
75422
75423 - posix_clocks[clock_id] = *new_clock;
75424 + posix_clocks[clock_id] = new_clock;
75425 }
75426 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
75427
75428 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
75429 return (id & CLOCKFD_MASK) == CLOCKFD ?
75430 &clock_posix_dynamic : &clock_posix_cpu;
75431
75432 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
75433 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
75434 return NULL;
75435 - return &posix_clocks[id];
75436 + return posix_clocks[id];
75437 }
75438
75439 static int common_timer_create(struct k_itimer *new_timer)
75440 @@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
75441 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
75442 return -EFAULT;
75443
75444 + /* only the CLOCK_REALTIME clock can be set, all other clocks
75445 + have their clock_set fptr set to a nosettime dummy function
75446 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
75447 + call common_clock_set, which calls do_sys_settimeofday, which
75448 + we hook
75449 + */
75450 +
75451 return kc->clock_set(which_clock, &new_tp);
75452 }
75453
75454 diff --git a/kernel/power/process.c b/kernel/power/process.c
75455 index d5a258b..4271191 100644
75456 --- a/kernel/power/process.c
75457 +++ b/kernel/power/process.c
75458 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
75459 u64 elapsed_csecs64;
75460 unsigned int elapsed_csecs;
75461 bool wakeup = false;
75462 + bool timedout = false;
75463
75464 do_gettimeofday(&start);
75465
75466 @@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
75467
75468 while (true) {
75469 todo = 0;
75470 + if (time_after(jiffies, end_time))
75471 + timedout = true;
75472 read_lock(&tasklist_lock);
75473 do_each_thread(g, p) {
75474 if (p == current || !freeze_task(p))
75475 continue;
75476
75477 - if (!freezer_should_skip(p))
75478 + if (!freezer_should_skip(p)) {
75479 todo++;
75480 + if (timedout) {
75481 + printk(KERN_ERR "Task refusing to freeze:\n");
75482 + sched_show_task(p);
75483 + }
75484 + }
75485 } while_each_thread(g, p);
75486 read_unlock(&tasklist_lock);
75487
75488 @@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
75489 todo += wq_busy;
75490 }
75491
75492 - if (!todo || time_after(jiffies, end_time))
75493 + if (!todo || timedout)
75494 break;
75495
75496 if (pm_wakeup_pending()) {
75497 diff --git a/kernel/printk.c b/kernel/printk.c
75498 index 267ce78..2487112 100644
75499 --- a/kernel/printk.c
75500 +++ b/kernel/printk.c
75501 @@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
75502 return ret;
75503 }
75504
75505 +static int check_syslog_permissions(int type, bool from_file);
75506 +
75507 static int devkmsg_open(struct inode *inode, struct file *file)
75508 {
75509 struct devkmsg_user *user;
75510 int err;
75511
75512 + err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
75513 + if (err)
75514 + return err;
75515 +
75516 /* write-only does not need any file context */
75517 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
75518 return 0;
75519 @@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
75520 if (dmesg_restrict)
75521 return 1;
75522 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
75523 - return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
75524 + return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
75525 }
75526
75527 static int check_syslog_permissions(int type, bool from_file)
75528 @@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
75529 if (from_file && type != SYSLOG_ACTION_OPEN)
75530 return 0;
75531
75532 +#ifdef CONFIG_GRKERNSEC_DMESG
75533 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
75534 + return -EPERM;
75535 +#endif
75536 +
75537 if (syslog_action_restricted(type)) {
75538 if (capable(CAP_SYSLOG))
75539 return 0;
75540 diff --git a/kernel/profile.c b/kernel/profile.c
75541 index 1f39181..86093471 100644
75542 --- a/kernel/profile.c
75543 +++ b/kernel/profile.c
75544 @@ -40,7 +40,7 @@ struct profile_hit {
75545 /* Oprofile timer tick hook */
75546 static int (*timer_hook)(struct pt_regs *) __read_mostly;
75547
75548 -static atomic_t *prof_buffer;
75549 +static atomic_unchecked_t *prof_buffer;
75550 static unsigned long prof_len, prof_shift;
75551
75552 int prof_on __read_mostly;
75553 @@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
75554 hits[i].pc = 0;
75555 continue;
75556 }
75557 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
75558 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
75559 hits[i].hits = hits[i].pc = 0;
75560 }
75561 }
75562 @@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
75563 * Add the current hit(s) and flush the write-queue out
75564 * to the global buffer:
75565 */
75566 - atomic_add(nr_hits, &prof_buffer[pc]);
75567 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
75568 for (i = 0; i < NR_PROFILE_HIT; ++i) {
75569 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
75570 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
75571 hits[i].pc = hits[i].hits = 0;
75572 }
75573 out:
75574 @@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
75575 {
75576 unsigned long pc;
75577 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
75578 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
75579 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
75580 }
75581 #endif /* !CONFIG_SMP */
75582
75583 @@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
75584 return -EFAULT;
75585 buf++; p++; count--; read++;
75586 }
75587 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
75588 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
75589 if (copy_to_user(buf, (void *)pnt, count))
75590 return -EFAULT;
75591 read += count;
75592 @@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
75593 }
75594 #endif
75595 profile_discard_flip_buffers();
75596 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
75597 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
75598 return count;
75599 }
75600
75601 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
75602 index 6cbeaae..363c48a 100644
75603 --- a/kernel/ptrace.c
75604 +++ b/kernel/ptrace.c
75605 @@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
75606 if (seize)
75607 flags |= PT_SEIZED;
75608 rcu_read_lock();
75609 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
75610 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
75611 flags |= PT_PTRACE_CAP;
75612 rcu_read_unlock();
75613 task->ptrace = flags;
75614 @@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
75615 break;
75616 return -EIO;
75617 }
75618 - if (copy_to_user(dst, buf, retval))
75619 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
75620 return -EFAULT;
75621 copied += retval;
75622 src += retval;
75623 @@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
75624 bool seized = child->ptrace & PT_SEIZED;
75625 int ret = -EIO;
75626 siginfo_t siginfo, *si;
75627 - void __user *datavp = (void __user *) data;
75628 + void __user *datavp = (__force void __user *) data;
75629 unsigned long __user *datalp = datavp;
75630 unsigned long flags;
75631
75632 @@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
75633 goto out;
75634 }
75635
75636 + if (gr_handle_ptrace(child, request)) {
75637 + ret = -EPERM;
75638 + goto out_put_task_struct;
75639 + }
75640 +
75641 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
75642 ret = ptrace_attach(child, request, addr, data);
75643 /*
75644 * Some architectures need to do book-keeping after
75645 * a ptrace attach.
75646 */
75647 - if (!ret)
75648 + if (!ret) {
75649 arch_ptrace_attach(child);
75650 + gr_audit_ptrace(child);
75651 + }
75652 goto out_put_task_struct;
75653 }
75654
75655 @@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
75656 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
75657 if (copied != sizeof(tmp))
75658 return -EIO;
75659 - return put_user(tmp, (unsigned long __user *)data);
75660 + return put_user(tmp, (__force unsigned long __user *)data);
75661 }
75662
75663 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
75664 @@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
75665 goto out;
75666 }
75667
75668 + if (gr_handle_ptrace(child, request)) {
75669 + ret = -EPERM;
75670 + goto out_put_task_struct;
75671 + }
75672 +
75673 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
75674 ret = ptrace_attach(child, request, addr, data);
75675 /*
75676 * Some architectures need to do book-keeping after
75677 * a ptrace attach.
75678 */
75679 - if (!ret)
75680 + if (!ret) {
75681 arch_ptrace_attach(child);
75682 + gr_audit_ptrace(child);
75683 + }
75684 goto out_put_task_struct;
75685 }
75686
75687 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
75688 index e7dce58..ad0d7b7 100644
75689 --- a/kernel/rcutiny.c
75690 +++ b/kernel/rcutiny.c
75691 @@ -46,7 +46,7 @@
75692 struct rcu_ctrlblk;
75693 static void invoke_rcu_callbacks(void);
75694 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
75695 -static void rcu_process_callbacks(struct softirq_action *unused);
75696 +static void rcu_process_callbacks(void);
75697 static void __call_rcu(struct rcu_head *head,
75698 void (*func)(struct rcu_head *rcu),
75699 struct rcu_ctrlblk *rcp);
75700 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
75701 rcu_is_callbacks_kthread()));
75702 }
75703
75704 -static void rcu_process_callbacks(struct softirq_action *unused)
75705 +static void rcu_process_callbacks(void)
75706 {
75707 __rcu_process_callbacks(&rcu_sched_ctrlblk);
75708 __rcu_process_callbacks(&rcu_bh_ctrlblk);
75709 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
75710 index f85016a..91cb03b 100644
75711 --- a/kernel/rcutiny_plugin.h
75712 +++ b/kernel/rcutiny_plugin.h
75713 @@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
75714 have_rcu_kthread_work = morework;
75715 local_irq_restore(flags);
75716 if (work)
75717 - rcu_process_callbacks(NULL);
75718 + rcu_process_callbacks();
75719 schedule_timeout_interruptible(1); /* Leave CPU for others. */
75720 }
75721
75722 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
75723 index 31dea01..ad91ffb 100644
75724 --- a/kernel/rcutorture.c
75725 +++ b/kernel/rcutorture.c
75726 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
75727 { 0 };
75728 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
75729 { 0 };
75730 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
75731 -static atomic_t n_rcu_torture_alloc;
75732 -static atomic_t n_rcu_torture_alloc_fail;
75733 -static atomic_t n_rcu_torture_free;
75734 -static atomic_t n_rcu_torture_mberror;
75735 -static atomic_t n_rcu_torture_error;
75736 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
75737 +static atomic_unchecked_t n_rcu_torture_alloc;
75738 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
75739 +static atomic_unchecked_t n_rcu_torture_free;
75740 +static atomic_unchecked_t n_rcu_torture_mberror;
75741 +static atomic_unchecked_t n_rcu_torture_error;
75742 static long n_rcu_torture_barrier_error;
75743 static long n_rcu_torture_boost_ktrerror;
75744 static long n_rcu_torture_boost_rterror;
75745 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
75746
75747 spin_lock_bh(&rcu_torture_lock);
75748 if (list_empty(&rcu_torture_freelist)) {
75749 - atomic_inc(&n_rcu_torture_alloc_fail);
75750 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
75751 spin_unlock_bh(&rcu_torture_lock);
75752 return NULL;
75753 }
75754 - atomic_inc(&n_rcu_torture_alloc);
75755 + atomic_inc_unchecked(&n_rcu_torture_alloc);
75756 p = rcu_torture_freelist.next;
75757 list_del_init(p);
75758 spin_unlock_bh(&rcu_torture_lock);
75759 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
75760 static void
75761 rcu_torture_free(struct rcu_torture *p)
75762 {
75763 - atomic_inc(&n_rcu_torture_free);
75764 + atomic_inc_unchecked(&n_rcu_torture_free);
75765 spin_lock_bh(&rcu_torture_lock);
75766 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
75767 spin_unlock_bh(&rcu_torture_lock);
75768 @@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
75769 i = rp->rtort_pipe_count;
75770 if (i > RCU_TORTURE_PIPE_LEN)
75771 i = RCU_TORTURE_PIPE_LEN;
75772 - atomic_inc(&rcu_torture_wcount[i]);
75773 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
75774 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
75775 rp->rtort_mbtest = 0;
75776 rcu_torture_free(rp);
75777 @@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
75778 i = rp->rtort_pipe_count;
75779 if (i > RCU_TORTURE_PIPE_LEN)
75780 i = RCU_TORTURE_PIPE_LEN;
75781 - atomic_inc(&rcu_torture_wcount[i]);
75782 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
75783 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
75784 rp->rtort_mbtest = 0;
75785 list_del(&rp->rtort_free);
75786 @@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
75787 i = old_rp->rtort_pipe_count;
75788 if (i > RCU_TORTURE_PIPE_LEN)
75789 i = RCU_TORTURE_PIPE_LEN;
75790 - atomic_inc(&rcu_torture_wcount[i]);
75791 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
75792 old_rp->rtort_pipe_count++;
75793 cur_ops->deferred_free(old_rp);
75794 }
75795 @@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
75796 }
75797 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
75798 if (p->rtort_mbtest == 0)
75799 - atomic_inc(&n_rcu_torture_mberror);
75800 + atomic_inc_unchecked(&n_rcu_torture_mberror);
75801 spin_lock(&rand_lock);
75802 cur_ops->read_delay(&rand);
75803 n_rcu_torture_timers++;
75804 @@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
75805 }
75806 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
75807 if (p->rtort_mbtest == 0)
75808 - atomic_inc(&n_rcu_torture_mberror);
75809 + atomic_inc_unchecked(&n_rcu_torture_mberror);
75810 cur_ops->read_delay(&rand);
75811 preempt_disable();
75812 pipe_count = p->rtort_pipe_count;
75813 @@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
75814 rcu_torture_current,
75815 rcu_torture_current_version,
75816 list_empty(&rcu_torture_freelist),
75817 - atomic_read(&n_rcu_torture_alloc),
75818 - atomic_read(&n_rcu_torture_alloc_fail),
75819 - atomic_read(&n_rcu_torture_free));
75820 + atomic_read_unchecked(&n_rcu_torture_alloc),
75821 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
75822 + atomic_read_unchecked(&n_rcu_torture_free));
75823 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
75824 - atomic_read(&n_rcu_torture_mberror),
75825 + atomic_read_unchecked(&n_rcu_torture_mberror),
75826 n_rcu_torture_boost_ktrerror,
75827 n_rcu_torture_boost_rterror);
75828 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
75829 @@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
75830 n_barrier_attempts,
75831 n_rcu_torture_barrier_error);
75832 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
75833 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
75834 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
75835 n_rcu_torture_barrier_error != 0 ||
75836 n_rcu_torture_boost_ktrerror != 0 ||
75837 n_rcu_torture_boost_rterror != 0 ||
75838 n_rcu_torture_boost_failure != 0 ||
75839 i > 1) {
75840 cnt += sprintf(&page[cnt], "!!! ");
75841 - atomic_inc(&n_rcu_torture_error);
75842 + atomic_inc_unchecked(&n_rcu_torture_error);
75843 WARN_ON_ONCE(1);
75844 }
75845 cnt += sprintf(&page[cnt], "Reader Pipe: ");
75846 @@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
75847 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
75848 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
75849 cnt += sprintf(&page[cnt], " %d",
75850 - atomic_read(&rcu_torture_wcount[i]));
75851 + atomic_read_unchecked(&rcu_torture_wcount[i]));
75852 }
75853 cnt += sprintf(&page[cnt], "\n");
75854 if (cur_ops->stats)
75855 @@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
75856
75857 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
75858
75859 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
75860 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
75861 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
75862 else if (n_online_successes != n_online_attempts ||
75863 n_offline_successes != n_offline_attempts)
75864 @@ -1989,18 +1989,18 @@ rcu_torture_init(void)
75865
75866 rcu_torture_current = NULL;
75867 rcu_torture_current_version = 0;
75868 - atomic_set(&n_rcu_torture_alloc, 0);
75869 - atomic_set(&n_rcu_torture_alloc_fail, 0);
75870 - atomic_set(&n_rcu_torture_free, 0);
75871 - atomic_set(&n_rcu_torture_mberror, 0);
75872 - atomic_set(&n_rcu_torture_error, 0);
75873 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
75874 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
75875 + atomic_set_unchecked(&n_rcu_torture_free, 0);
75876 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
75877 + atomic_set_unchecked(&n_rcu_torture_error, 0);
75878 n_rcu_torture_barrier_error = 0;
75879 n_rcu_torture_boost_ktrerror = 0;
75880 n_rcu_torture_boost_rterror = 0;
75881 n_rcu_torture_boost_failure = 0;
75882 n_rcu_torture_boosts = 0;
75883 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
75884 - atomic_set(&rcu_torture_wcount[i], 0);
75885 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
75886 for_each_possible_cpu(cpu) {
75887 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
75888 per_cpu(rcu_torture_count, cpu)[i] = 0;
75889 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
75890 index e441b77..dd54f17 100644
75891 --- a/kernel/rcutree.c
75892 +++ b/kernel/rcutree.c
75893 @@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
75894 rcu_prepare_for_idle(smp_processor_id());
75895 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
75896 smp_mb__before_atomic_inc(); /* See above. */
75897 - atomic_inc(&rdtp->dynticks);
75898 + atomic_inc_unchecked(&rdtp->dynticks);
75899 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
75900 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
75901 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
75902
75903 /*
75904 * It is illegal to enter an extended quiescent state while
75905 @@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
75906 int user)
75907 {
75908 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
75909 - atomic_inc(&rdtp->dynticks);
75910 + atomic_inc_unchecked(&rdtp->dynticks);
75911 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
75912 smp_mb__after_atomic_inc(); /* See above. */
75913 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
75914 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
75915 rcu_cleanup_after_idle(smp_processor_id());
75916 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
75917 if (!user && !is_idle_task(current)) {
75918 @@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
75919 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
75920
75921 if (rdtp->dynticks_nmi_nesting == 0 &&
75922 - (atomic_read(&rdtp->dynticks) & 0x1))
75923 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
75924 return;
75925 rdtp->dynticks_nmi_nesting++;
75926 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
75927 - atomic_inc(&rdtp->dynticks);
75928 + atomic_inc_unchecked(&rdtp->dynticks);
75929 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
75930 smp_mb__after_atomic_inc(); /* See above. */
75931 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
75932 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
75933 }
75934
75935 /**
75936 @@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
75937 return;
75938 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
75939 smp_mb__before_atomic_inc(); /* See above. */
75940 - atomic_inc(&rdtp->dynticks);
75941 + atomic_inc_unchecked(&rdtp->dynticks);
75942 smp_mb__after_atomic_inc(); /* Force delay to next write. */
75943 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
75944 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
75945 }
75946
75947 /**
75948 @@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
75949 int ret;
75950
75951 preempt_disable();
75952 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
75953 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
75954 preempt_enable();
75955 return ret;
75956 }
75957 @@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
75958 */
75959 static int dyntick_save_progress_counter(struct rcu_data *rdp)
75960 {
75961 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
75962 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
75963 return (rdp->dynticks_snap & 0x1) == 0;
75964 }
75965
75966 @@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
75967 unsigned int curr;
75968 unsigned int snap;
75969
75970 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
75971 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
75972 snap = (unsigned int)rdp->dynticks_snap;
75973
75974 /*
75975 @@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
75976 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
75977 */
75978 if (till_stall_check < 3) {
75979 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
75980 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
75981 till_stall_check = 3;
75982 } else if (till_stall_check > 300) {
75983 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
75984 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
75985 till_stall_check = 300;
75986 }
75987 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
75988 @@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
75989 rsp->qlen += rdp->qlen;
75990 rdp->n_cbs_orphaned += rdp->qlen;
75991 rdp->qlen_lazy = 0;
75992 - ACCESS_ONCE(rdp->qlen) = 0;
75993 + ACCESS_ONCE_RW(rdp->qlen) = 0;
75994 }
75995
75996 /*
75997 @@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
75998 }
75999 smp_mb(); /* List handling before counting for rcu_barrier(). */
76000 rdp->qlen_lazy -= count_lazy;
76001 - ACCESS_ONCE(rdp->qlen) -= count;
76002 + ACCESS_ONCE_RW(rdp->qlen) -= count;
76003 rdp->n_cbs_invoked += count;
76004
76005 /* Reinstate batch limit if we have worked down the excess. */
76006 @@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
76007 /*
76008 * Do RCU core processing for the current CPU.
76009 */
76010 -static void rcu_process_callbacks(struct softirq_action *unused)
76011 +static void rcu_process_callbacks(void)
76012 {
76013 struct rcu_state *rsp;
76014
76015 @@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
76016 local_irq_restore(flags);
76017 return;
76018 }
76019 - ACCESS_ONCE(rdp->qlen)++;
76020 + ACCESS_ONCE_RW(rdp->qlen)++;
76021 if (lazy)
76022 rdp->qlen_lazy++;
76023 else
76024 @@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
76025 * counter wrap on a 32-bit system. Quite a few more CPUs would of
76026 * course be required on a 64-bit system.
76027 */
76028 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
76029 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
76030 (ulong)atomic_long_read(&rsp->expedited_done) +
76031 ULONG_MAX / 8)) {
76032 synchronize_sched();
76033 - atomic_long_inc(&rsp->expedited_wrap);
76034 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
76035 return;
76036 }
76037
76038 @@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
76039 * Take a ticket. Note that atomic_inc_return() implies a
76040 * full memory barrier.
76041 */
76042 - snap = atomic_long_inc_return(&rsp->expedited_start);
76043 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
76044 firstsnap = snap;
76045 get_online_cpus();
76046 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
76047 @@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
76048 synchronize_sched_expedited_cpu_stop,
76049 NULL) == -EAGAIN) {
76050 put_online_cpus();
76051 - atomic_long_inc(&rsp->expedited_tryfail);
76052 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
76053
76054 /* Check to see if someone else did our work for us. */
76055 s = atomic_long_read(&rsp->expedited_done);
76056 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76057 /* ensure test happens before caller kfree */
76058 smp_mb__before_atomic_inc(); /* ^^^ */
76059 - atomic_long_inc(&rsp->expedited_workdone1);
76060 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
76061 return;
76062 }
76063
76064 @@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
76065 udelay(trycount * num_online_cpus());
76066 } else {
76067 wait_rcu_gp(call_rcu_sched);
76068 - atomic_long_inc(&rsp->expedited_normal);
76069 + atomic_long_inc_unchecked(&rsp->expedited_normal);
76070 return;
76071 }
76072
76073 @@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
76074 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76075 /* ensure test happens before caller kfree */
76076 smp_mb__before_atomic_inc(); /* ^^^ */
76077 - atomic_long_inc(&rsp->expedited_workdone2);
76078 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
76079 return;
76080 }
76081
76082 @@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
76083 * period works for us.
76084 */
76085 get_online_cpus();
76086 - snap = atomic_long_read(&rsp->expedited_start);
76087 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
76088 smp_mb(); /* ensure read is before try_stop_cpus(). */
76089 }
76090 - atomic_long_inc(&rsp->expedited_stoppedcpus);
76091 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
76092
76093 /*
76094 * Everyone up to our most recent fetch is covered by our grace
76095 @@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
76096 * than we did already did their update.
76097 */
76098 do {
76099 - atomic_long_inc(&rsp->expedited_done_tries);
76100 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
76101 s = atomic_long_read(&rsp->expedited_done);
76102 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
76103 /* ensure test happens before caller kfree */
76104 smp_mb__before_atomic_inc(); /* ^^^ */
76105 - atomic_long_inc(&rsp->expedited_done_lost);
76106 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
76107 break;
76108 }
76109 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
76110 - atomic_long_inc(&rsp->expedited_done_exit);
76111 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
76112
76113 put_online_cpus();
76114 }
76115 @@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76116 * ACCESS_ONCE() to prevent the compiler from speculating
76117 * the increment to precede the early-exit check.
76118 */
76119 - ACCESS_ONCE(rsp->n_barrier_done)++;
76120 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76121 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
76122 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
76123 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
76124 @@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76125
76126 /* Increment ->n_barrier_done to prevent duplicate work. */
76127 smp_mb(); /* Keep increment after above mechanism. */
76128 - ACCESS_ONCE(rsp->n_barrier_done)++;
76129 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76130 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
76131 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
76132 smp_mb(); /* Keep increment before caller's subsequent code. */
76133 @@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
76134 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
76135 init_callback_list(rdp);
76136 rdp->qlen_lazy = 0;
76137 - ACCESS_ONCE(rdp->qlen) = 0;
76138 + ACCESS_ONCE_RW(rdp->qlen) = 0;
76139 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
76140 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
76141 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
76142 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
76143 #ifdef CONFIG_RCU_USER_QS
76144 WARN_ON_ONCE(rdp->dynticks->in_user);
76145 #endif
76146 @@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
76147 rdp->blimit = blimit;
76148 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
76149 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
76150 - atomic_set(&rdp->dynticks->dynticks,
76151 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
76152 + atomic_set_unchecked(&rdp->dynticks->dynticks,
76153 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
76154 rcu_prepare_for_idle_init(cpu);
76155 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
76156
76157 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
76158 index 4b69291..704c92e 100644
76159 --- a/kernel/rcutree.h
76160 +++ b/kernel/rcutree.h
76161 @@ -86,7 +86,7 @@ struct rcu_dynticks {
76162 long long dynticks_nesting; /* Track irq/process nesting level. */
76163 /* Process level is worth LLONG_MAX/2. */
76164 int dynticks_nmi_nesting; /* Track NMI nesting level. */
76165 - atomic_t dynticks; /* Even value for idle, else odd. */
76166 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
76167 #ifdef CONFIG_RCU_FAST_NO_HZ
76168 int dyntick_drain; /* Prepare-for-idle state variable. */
76169 unsigned long dyntick_holdoff;
76170 @@ -423,17 +423,17 @@ struct rcu_state {
76171 /* _rcu_barrier(). */
76172 /* End of fields guarded by barrier_mutex. */
76173
76174 - atomic_long_t expedited_start; /* Starting ticket. */
76175 - atomic_long_t expedited_done; /* Done ticket. */
76176 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
76177 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
76178 - atomic_long_t expedited_workdone1; /* # done by others #1. */
76179 - atomic_long_t expedited_workdone2; /* # done by others #2. */
76180 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
76181 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
76182 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
76183 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
76184 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
76185 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
76186 + atomic_long_t expedited_done; /* Done ticket. */
76187 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
76188 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
76189 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
76190 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
76191 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
76192 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
76193 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
76194 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
76195 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
76196
76197 unsigned long jiffies_force_qs; /* Time at which to invoke */
76198 /* force_quiescent_state(). */
76199 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
76200 index c1cc7e1..f62e436 100644
76201 --- a/kernel/rcutree_plugin.h
76202 +++ b/kernel/rcutree_plugin.h
76203 @@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
76204
76205 /* Clean up and exit. */
76206 smp_mb(); /* ensure expedited GP seen before counter increment. */
76207 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
76208 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
76209 unlock_mb_ret:
76210 mutex_unlock(&sync_rcu_preempt_exp_mutex);
76211 mb_ret:
76212 @@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
76213 free_cpumask_var(cm);
76214 }
76215
76216 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
76217 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
76218 .store = &rcu_cpu_kthread_task,
76219 .thread_should_run = rcu_cpu_kthread_should_run,
76220 .thread_fn = rcu_cpu_kthread,
76221 @@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
76222 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
76223 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
76224 cpu, ticks_value, ticks_title,
76225 - atomic_read(&rdtp->dynticks) & 0xfff,
76226 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
76227 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
76228 fast_no_hz);
76229 }
76230 @@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
76231
76232 /* Enqueue the callback on the nocb list and update counts. */
76233 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
76234 - ACCESS_ONCE(*old_rhpp) = rhp;
76235 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
76236 atomic_long_add(rhcount, &rdp->nocb_q_count);
76237 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
76238
76239 @@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
76240 * Extract queued callbacks, update counts, and wait
76241 * for a grace period to elapse.
76242 */
76243 - ACCESS_ONCE(rdp->nocb_head) = NULL;
76244 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
76245 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
76246 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
76247 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
76248 - ACCESS_ONCE(rdp->nocb_p_count) += c;
76249 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
76250 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
76251 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
76252 wait_rcu_gp(rdp->rsp->call_remote);
76253
76254 /* Each pass through the following loop invokes a callback. */
76255 @@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
76256 list = next;
76257 }
76258 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
76259 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
76260 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
76261 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
76262 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
76263 rdp->n_nocbs_invoked += c;
76264 }
76265 return 0;
76266 @@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
76267 rdp = per_cpu_ptr(rsp->rda, cpu);
76268 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
76269 BUG_ON(IS_ERR(t));
76270 - ACCESS_ONCE(rdp->nocb_kthread) = t;
76271 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
76272 }
76273 }
76274
76275 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
76276 index 0d095dc..1985b19 100644
76277 --- a/kernel/rcutree_trace.c
76278 +++ b/kernel/rcutree_trace.c
76279 @@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
76280 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
76281 rdp->passed_quiesce, rdp->qs_pending);
76282 seq_printf(m, " dt=%d/%llx/%d df=%lu",
76283 - atomic_read(&rdp->dynticks->dynticks),
76284 + atomic_read_unchecked(&rdp->dynticks->dynticks),
76285 rdp->dynticks->dynticks_nesting,
76286 rdp->dynticks->dynticks_nmi_nesting,
76287 rdp->dynticks_fqs);
76288 @@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
76289 struct rcu_state *rsp = (struct rcu_state *)m->private;
76290
76291 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",
76292 - atomic_long_read(&rsp->expedited_start),
76293 + atomic_long_read_unchecked(&rsp->expedited_start),
76294 atomic_long_read(&rsp->expedited_done),
76295 - atomic_long_read(&rsp->expedited_wrap),
76296 - atomic_long_read(&rsp->expedited_tryfail),
76297 - atomic_long_read(&rsp->expedited_workdone1),
76298 - atomic_long_read(&rsp->expedited_workdone2),
76299 - atomic_long_read(&rsp->expedited_normal),
76300 - atomic_long_read(&rsp->expedited_stoppedcpus),
76301 - atomic_long_read(&rsp->expedited_done_tries),
76302 - atomic_long_read(&rsp->expedited_done_lost),
76303 - atomic_long_read(&rsp->expedited_done_exit));
76304 + atomic_long_read_unchecked(&rsp->expedited_wrap),
76305 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
76306 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
76307 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
76308 + atomic_long_read_unchecked(&rsp->expedited_normal),
76309 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
76310 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
76311 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
76312 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
76313 return 0;
76314 }
76315
76316 diff --git a/kernel/resource.c b/kernel/resource.c
76317 index 73f35d4..4684fc4 100644
76318 --- a/kernel/resource.c
76319 +++ b/kernel/resource.c
76320 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
76321
76322 static int __init ioresources_init(void)
76323 {
76324 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
76325 +#ifdef CONFIG_GRKERNSEC_PROC_USER
76326 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
76327 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
76328 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76329 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
76330 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
76331 +#endif
76332 +#else
76333 proc_create("ioports", 0, NULL, &proc_ioports_operations);
76334 proc_create("iomem", 0, NULL, &proc_iomem_operations);
76335 +#endif
76336 return 0;
76337 }
76338 __initcall(ioresources_init);
76339 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
76340 index 98ec494..4241d6d 100644
76341 --- a/kernel/rtmutex-tester.c
76342 +++ b/kernel/rtmutex-tester.c
76343 @@ -20,7 +20,7 @@
76344 #define MAX_RT_TEST_MUTEXES 8
76345
76346 static spinlock_t rttest_lock;
76347 -static atomic_t rttest_event;
76348 +static atomic_unchecked_t rttest_event;
76349
76350 struct test_thread_data {
76351 int opcode;
76352 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76353
76354 case RTTEST_LOCKCONT:
76355 td->mutexes[td->opdata] = 1;
76356 - td->event = atomic_add_return(1, &rttest_event);
76357 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76358 return 0;
76359
76360 case RTTEST_RESET:
76361 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76362 return 0;
76363
76364 case RTTEST_RESETEVENT:
76365 - atomic_set(&rttest_event, 0);
76366 + atomic_set_unchecked(&rttest_event, 0);
76367 return 0;
76368
76369 default:
76370 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76371 return ret;
76372
76373 td->mutexes[id] = 1;
76374 - td->event = atomic_add_return(1, &rttest_event);
76375 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76376 rt_mutex_lock(&mutexes[id]);
76377 - td->event = atomic_add_return(1, &rttest_event);
76378 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76379 td->mutexes[id] = 4;
76380 return 0;
76381
76382 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76383 return ret;
76384
76385 td->mutexes[id] = 1;
76386 - td->event = atomic_add_return(1, &rttest_event);
76387 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76388 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
76389 - td->event = atomic_add_return(1, &rttest_event);
76390 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76391 td->mutexes[id] = ret ? 0 : 4;
76392 return ret ? -EINTR : 0;
76393
76394 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76395 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
76396 return ret;
76397
76398 - td->event = atomic_add_return(1, &rttest_event);
76399 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76400 rt_mutex_unlock(&mutexes[id]);
76401 - td->event = atomic_add_return(1, &rttest_event);
76402 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76403 td->mutexes[id] = 0;
76404 return 0;
76405
76406 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76407 break;
76408
76409 td->mutexes[dat] = 2;
76410 - td->event = atomic_add_return(1, &rttest_event);
76411 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76412 break;
76413
76414 default:
76415 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76416 return;
76417
76418 td->mutexes[dat] = 3;
76419 - td->event = atomic_add_return(1, &rttest_event);
76420 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76421 break;
76422
76423 case RTTEST_LOCKNOWAIT:
76424 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76425 return;
76426
76427 td->mutexes[dat] = 1;
76428 - td->event = atomic_add_return(1, &rttest_event);
76429 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76430 return;
76431
76432 default:
76433 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
76434 index 0984a21..939f183 100644
76435 --- a/kernel/sched/auto_group.c
76436 +++ b/kernel/sched/auto_group.c
76437 @@ -11,7 +11,7 @@
76438
76439 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
76440 static struct autogroup autogroup_default;
76441 -static atomic_t autogroup_seq_nr;
76442 +static atomic_unchecked_t autogroup_seq_nr;
76443
76444 void __init autogroup_init(struct task_struct *init_task)
76445 {
76446 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
76447
76448 kref_init(&ag->kref);
76449 init_rwsem(&ag->lock);
76450 - ag->id = atomic_inc_return(&autogroup_seq_nr);
76451 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
76452 ag->tg = tg;
76453 #ifdef CONFIG_RT_GROUP_SCHED
76454 /*
76455 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
76456 index 26058d0..f9d3c76 100644
76457 --- a/kernel/sched/core.c
76458 +++ b/kernel/sched/core.c
76459 @@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
76460 /* convert nice value [19,-20] to rlimit style value [1,40] */
76461 int nice_rlim = 20 - nice;
76462
76463 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
76464 +
76465 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
76466 capable(CAP_SYS_NICE));
76467 }
76468 @@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
76469 if (nice > 19)
76470 nice = 19;
76471
76472 - if (increment < 0 && !can_nice(current, nice))
76473 + if (increment < 0 && (!can_nice(current, nice) ||
76474 + gr_handle_chroot_nice()))
76475 return -EPERM;
76476
76477 retval = security_task_setnice(current, nice);
76478 @@ -3818,6 +3821,7 @@ recheck:
76479 unsigned long rlim_rtprio =
76480 task_rlimit(p, RLIMIT_RTPRIO);
76481
76482 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
76483 /* can't set/change the rt policy */
76484 if (policy != p->policy && !rlim_rtprio)
76485 return -EPERM;
76486 @@ -4901,7 +4905,7 @@ static void migrate_tasks(unsigned int dead_cpu)
76487
76488 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
76489
76490 -static struct ctl_table sd_ctl_dir[] = {
76491 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
76492 {
76493 .procname = "sched_domain",
76494 .mode = 0555,
76495 @@ -4918,17 +4922,17 @@ static struct ctl_table sd_ctl_root[] = {
76496 {}
76497 };
76498
76499 -static struct ctl_table *sd_alloc_ctl_entry(int n)
76500 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
76501 {
76502 - struct ctl_table *entry =
76503 + ctl_table_no_const *entry =
76504 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
76505
76506 return entry;
76507 }
76508
76509 -static void sd_free_ctl_entry(struct ctl_table **tablep)
76510 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
76511 {
76512 - struct ctl_table *entry;
76513 + ctl_table_no_const *entry;
76514
76515 /*
76516 * In the intermediate directories, both the child directory and
76517 @@ -4936,22 +4940,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
76518 * will always be set. In the lowest directory the names are
76519 * static strings and all have proc handlers.
76520 */
76521 - for (entry = *tablep; entry->mode; entry++) {
76522 - if (entry->child)
76523 - sd_free_ctl_entry(&entry->child);
76524 + for (entry = tablep; entry->mode; entry++) {
76525 + if (entry->child) {
76526 + sd_free_ctl_entry(entry->child);
76527 + pax_open_kernel();
76528 + entry->child = NULL;
76529 + pax_close_kernel();
76530 + }
76531 if (entry->proc_handler == NULL)
76532 kfree(entry->procname);
76533 }
76534
76535 - kfree(*tablep);
76536 - *tablep = NULL;
76537 + kfree(tablep);
76538 }
76539
76540 static int min_load_idx = 0;
76541 static int max_load_idx = CPU_LOAD_IDX_MAX;
76542
76543 static void
76544 -set_table_entry(struct ctl_table *entry,
76545 +set_table_entry(ctl_table_no_const *entry,
76546 const char *procname, void *data, int maxlen,
76547 umode_t mode, proc_handler *proc_handler,
76548 bool load_idx)
76549 @@ -4971,7 +4978,7 @@ set_table_entry(struct ctl_table *entry,
76550 static struct ctl_table *
76551 sd_alloc_ctl_domain_table(struct sched_domain *sd)
76552 {
76553 - struct ctl_table *table = sd_alloc_ctl_entry(13);
76554 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
76555
76556 if (table == NULL)
76557 return NULL;
76558 @@ -5006,9 +5013,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
76559 return table;
76560 }
76561
76562 -static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
76563 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
76564 {
76565 - struct ctl_table *entry, *table;
76566 + ctl_table_no_const *entry, *table;
76567 struct sched_domain *sd;
76568 int domain_num = 0, i;
76569 char buf[32];
76570 @@ -5035,11 +5042,13 @@ static struct ctl_table_header *sd_sysctl_header;
76571 static void register_sched_domain_sysctl(void)
76572 {
76573 int i, cpu_num = num_possible_cpus();
76574 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
76575 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
76576 char buf[32];
76577
76578 WARN_ON(sd_ctl_dir[0].child);
76579 + pax_open_kernel();
76580 sd_ctl_dir[0].child = entry;
76581 + pax_close_kernel();
76582
76583 if (entry == NULL)
76584 return;
76585 @@ -5062,8 +5071,12 @@ static void unregister_sched_domain_sysctl(void)
76586 if (sd_sysctl_header)
76587 unregister_sysctl_table(sd_sysctl_header);
76588 sd_sysctl_header = NULL;
76589 - if (sd_ctl_dir[0].child)
76590 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
76591 + if (sd_ctl_dir[0].child) {
76592 + sd_free_ctl_entry(sd_ctl_dir[0].child);
76593 + pax_open_kernel();
76594 + sd_ctl_dir[0].child = NULL;
76595 + pax_close_kernel();
76596 + }
76597 }
76598 #else
76599 static void register_sched_domain_sysctl(void)
76600 @@ -5162,7 +5175,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
76601 * happens before everything else. This has to be lower priority than
76602 * the notifier in the perf_event subsystem, though.
76603 */
76604 -static struct notifier_block __cpuinitdata migration_notifier = {
76605 +static struct notifier_block migration_notifier = {
76606 .notifier_call = migration_call,
76607 .priority = CPU_PRI_MIGRATION,
76608 };
76609 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
76610 index 81fa536..6ccf96a 100644
76611 --- a/kernel/sched/fair.c
76612 +++ b/kernel/sched/fair.c
76613 @@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
76614
76615 static void reset_ptenuma_scan(struct task_struct *p)
76616 {
76617 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
76618 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
76619 p->mm->numa_scan_offset = 0;
76620 }
76621
76622 @@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
76623 */
76624 static int select_idle_sibling(struct task_struct *p, int target)
76625 {
76626 - int cpu = smp_processor_id();
76627 - int prev_cpu = task_cpu(p);
76628 struct sched_domain *sd;
76629 struct sched_group *sg;
76630 - int i;
76631 + int i = task_cpu(p);
76632
76633 - /*
76634 - * If the task is going to be woken-up on this cpu and if it is
76635 - * already idle, then it is the right target.
76636 - */
76637 - if (target == cpu && idle_cpu(cpu))
76638 - return cpu;
76639 + if (idle_cpu(target))
76640 + return target;
76641
76642 /*
76643 - * If the task is going to be woken-up on the cpu where it previously
76644 - * ran and if it is currently idle, then it the right target.
76645 + * If the prevous cpu is cache affine and idle, don't be stupid.
76646 */
76647 - if (target == prev_cpu && idle_cpu(prev_cpu))
76648 - return prev_cpu;
76649 + if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
76650 + return i;
76651
76652 /*
76653 * Otherwise, iterate the domains and find an elegible idle cpu.
76654 @@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
76655 goto next;
76656
76657 for_each_cpu(i, sched_group_cpus(sg)) {
76658 - if (!idle_cpu(i))
76659 + if (i == target || !idle_cpu(i))
76660 goto next;
76661 }
76662
76663 @@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
76664 * run_rebalance_domains is triggered when needed from the scheduler tick.
76665 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
76666 */
76667 -static void run_rebalance_domains(struct softirq_action *h)
76668 +static void run_rebalance_domains(void)
76669 {
76670 int this_cpu = smp_processor_id();
76671 struct rq *this_rq = cpu_rq(this_cpu);
76672 diff --git a/kernel/signal.c b/kernel/signal.c
76673 index 3d09cf6..8988390 100644
76674 --- a/kernel/signal.c
76675 +++ b/kernel/signal.c
76676 @@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
76677
76678 int print_fatal_signals __read_mostly;
76679
76680 -static void __user *sig_handler(struct task_struct *t, int sig)
76681 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
76682 {
76683 return t->sighand->action[sig - 1].sa.sa_handler;
76684 }
76685
76686 -static int sig_handler_ignored(void __user *handler, int sig)
76687 +static int sig_handler_ignored(__sighandler_t handler, int sig)
76688 {
76689 /* Is it explicitly or implicitly ignored? */
76690 return handler == SIG_IGN ||
76691 @@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
76692
76693 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
76694 {
76695 - void __user *handler;
76696 + __sighandler_t handler;
76697
76698 handler = sig_handler(t, sig);
76699
76700 @@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
76701 atomic_inc(&user->sigpending);
76702 rcu_read_unlock();
76703
76704 + if (!override_rlimit)
76705 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
76706 +
76707 if (override_rlimit ||
76708 atomic_read(&user->sigpending) <=
76709 task_rlimit(t, RLIMIT_SIGPENDING)) {
76710 @@ -485,6 +488,9 @@ flush_signal_handlers(struct task_struct *t, int force_default)
76711 if (force_default || ka->sa.sa_handler != SIG_IGN)
76712 ka->sa.sa_handler = SIG_DFL;
76713 ka->sa.sa_flags = 0;
76714 +#ifdef SA_RESTORER
76715 + ka->sa.sa_restorer = NULL;
76716 +#endif
76717 sigemptyset(&ka->sa.sa_mask);
76718 ka++;
76719 }
76720 @@ -492,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
76721
76722 int unhandled_signal(struct task_struct *tsk, int sig)
76723 {
76724 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
76725 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
76726 if (is_global_init(tsk))
76727 return 1;
76728 if (handler != SIG_IGN && handler != SIG_DFL)
76729 @@ -812,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
76730 }
76731 }
76732
76733 + /* allow glibc communication via tgkill to other threads in our
76734 + thread group */
76735 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
76736 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
76737 + && gr_handle_signal(t, sig))
76738 + return -EPERM;
76739 +
76740 return security_task_kill(t, info, sig, 0);
76741 }
76742
76743 @@ -1194,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
76744 return send_signal(sig, info, p, 1);
76745 }
76746
76747 -static int
76748 +int
76749 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76750 {
76751 return send_signal(sig, info, t, 0);
76752 @@ -1231,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76753 unsigned long int flags;
76754 int ret, blocked, ignored;
76755 struct k_sigaction *action;
76756 + int is_unhandled = 0;
76757
76758 spin_lock_irqsave(&t->sighand->siglock, flags);
76759 action = &t->sighand->action[sig-1];
76760 @@ -1245,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76761 }
76762 if (action->sa.sa_handler == SIG_DFL)
76763 t->signal->flags &= ~SIGNAL_UNKILLABLE;
76764 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
76765 + is_unhandled = 1;
76766 ret = specific_send_sig_info(sig, info, t);
76767 spin_unlock_irqrestore(&t->sighand->siglock, flags);
76768
76769 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
76770 + normal operation */
76771 + if (is_unhandled) {
76772 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
76773 + gr_handle_crash(t, sig);
76774 + }
76775 +
76776 return ret;
76777 }
76778
76779 @@ -1314,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
76780 ret = check_kill_permission(sig, info, p);
76781 rcu_read_unlock();
76782
76783 - if (!ret && sig)
76784 + if (!ret && sig) {
76785 ret = do_send_sig_info(sig, info, p, true);
76786 + if (!ret)
76787 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
76788 + }
76789
76790 return ret;
76791 }
76792 @@ -2852,7 +2878,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
76793 int error = -ESRCH;
76794
76795 rcu_read_lock();
76796 - p = find_task_by_vpid(pid);
76797 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76798 + /* allow glibc communication via tgkill to other threads in our
76799 + thread group */
76800 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
76801 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
76802 + p = find_task_by_vpid_unrestricted(pid);
76803 + else
76804 +#endif
76805 + p = find_task_by_vpid(pid);
76806 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
76807 error = check_kill_permission(sig, info, p);
76808 /*
76809 @@ -3135,8 +3169,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
76810 }
76811 seg = get_fs();
76812 set_fs(KERNEL_DS);
76813 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
76814 - (stack_t __force __user *) &uoss,
76815 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
76816 + (stack_t __force_user *) &uoss,
76817 compat_user_stack_pointer());
76818 set_fs(seg);
76819 if (ret >= 0 && uoss_ptr) {
76820 diff --git a/kernel/smp.c b/kernel/smp.c
76821 index 69f38bd..77bbf12 100644
76822 --- a/kernel/smp.c
76823 +++ b/kernel/smp.c
76824 @@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
76825 return NOTIFY_OK;
76826 }
76827
76828 -static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
76829 +static struct notifier_block hotplug_cfd_notifier = {
76830 .notifier_call = hotplug_cfd,
76831 };
76832
76833 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
76834 index d6c5fc0..530560c 100644
76835 --- a/kernel/smpboot.c
76836 +++ b/kernel/smpboot.c
76837 @@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
76838 }
76839 smpboot_unpark_thread(plug_thread, cpu);
76840 }
76841 - list_add(&plug_thread->list, &hotplug_threads);
76842 + pax_list_add(&plug_thread->list, &hotplug_threads);
76843 out:
76844 mutex_unlock(&smpboot_threads_lock);
76845 return ret;
76846 @@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
76847 {
76848 get_online_cpus();
76849 mutex_lock(&smpboot_threads_lock);
76850 - list_del(&plug_thread->list);
76851 + pax_list_del(&plug_thread->list);
76852 smpboot_destroy_threads(plug_thread);
76853 mutex_unlock(&smpboot_threads_lock);
76854 put_online_cpus();
76855 diff --git a/kernel/softirq.c b/kernel/softirq.c
76856 index ed567ba..e71dabf 100644
76857 --- a/kernel/softirq.c
76858 +++ b/kernel/softirq.c
76859 @@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
76860 EXPORT_SYMBOL(irq_stat);
76861 #endif
76862
76863 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
76864 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
76865
76866 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
76867
76868 -char *softirq_to_name[NR_SOFTIRQS] = {
76869 +const char * const softirq_to_name[NR_SOFTIRQS] = {
76870 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
76871 "TASKLET", "SCHED", "HRTIMER", "RCU"
76872 };
76873 @@ -244,7 +244,7 @@ restart:
76874 kstat_incr_softirqs_this_cpu(vec_nr);
76875
76876 trace_softirq_entry(vec_nr);
76877 - h->action(h);
76878 + h->action();
76879 trace_softirq_exit(vec_nr);
76880 if (unlikely(prev_count != preempt_count())) {
76881 printk(KERN_ERR "huh, entered softirq %u %s %p"
76882 @@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
76883 or_softirq_pending(1UL << nr);
76884 }
76885
76886 -void open_softirq(int nr, void (*action)(struct softirq_action *))
76887 +void __init open_softirq(int nr, void (*action)(void))
76888 {
76889 softirq_vec[nr].action = action;
76890 }
76891 @@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
76892
76893 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
76894
76895 -static void tasklet_action(struct softirq_action *a)
76896 +static void tasklet_action(void)
76897 {
76898 struct tasklet_struct *list;
76899
76900 @@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
76901 }
76902 }
76903
76904 -static void tasklet_hi_action(struct softirq_action *a)
76905 +static void tasklet_hi_action(void)
76906 {
76907 struct tasklet_struct *list;
76908
76909 @@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
76910 return NOTIFY_OK;
76911 }
76912
76913 -static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
76914 +static struct notifier_block remote_softirq_cpu_notifier = {
76915 .notifier_call = remote_softirq_cpu_notify,
76916 };
76917
76918 @@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
76919 return NOTIFY_OK;
76920 }
76921
76922 -static struct notifier_block __cpuinitdata cpu_nfb = {
76923 +static struct notifier_block cpu_nfb = {
76924 .notifier_call = cpu_callback
76925 };
76926
76927 -static struct smp_hotplug_thread softirq_threads = {
76928 +static struct smp_hotplug_thread softirq_threads __read_only = {
76929 .store = &ksoftirqd,
76930 .thread_should_run = ksoftirqd_should_run,
76931 .thread_fn = run_ksoftirqd,
76932 diff --git a/kernel/srcu.c b/kernel/srcu.c
76933 index 2b85982..d52ab26 100644
76934 --- a/kernel/srcu.c
76935 +++ b/kernel/srcu.c
76936 @@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
76937 preempt_disable();
76938 idx = rcu_dereference_index_check(sp->completed,
76939 rcu_read_lock_sched_held()) & 0x1;
76940 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
76941 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
76942 smp_mb(); /* B */ /* Avoid leaking the critical section. */
76943 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
76944 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
76945 preempt_enable();
76946 return idx;
76947 }
76948 @@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
76949 {
76950 preempt_disable();
76951 smp_mb(); /* C */ /* Avoid leaking the critical section. */
76952 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
76953 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
76954 preempt_enable();
76955 }
76956 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
76957 diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
76958 index 2f194e9..2c05ea9 100644
76959 --- a/kernel/stop_machine.c
76960 +++ b/kernel/stop_machine.c
76961 @@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
76962 * cpu notifiers. It currently shares the same priority as sched
76963 * migration_notifier.
76964 */
76965 -static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
76966 +static struct notifier_block cpu_stop_cpu_notifier = {
76967 .notifier_call = cpu_stop_cpu_callback,
76968 .priority = 10,
76969 };
76970 diff --git a/kernel/sys.c b/kernel/sys.c
76971 index 265b376..4e42ef5 100644
76972 --- a/kernel/sys.c
76973 +++ b/kernel/sys.c
76974 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
76975 error = -EACCES;
76976 goto out;
76977 }
76978 +
76979 + if (gr_handle_chroot_setpriority(p, niceval)) {
76980 + error = -EACCES;
76981 + goto out;
76982 + }
76983 +
76984 no_nice = security_task_setnice(p, niceval);
76985 if (no_nice) {
76986 error = no_nice;
76987 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
76988 goto error;
76989 }
76990
76991 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
76992 + goto error;
76993 +
76994 if (rgid != (gid_t) -1 ||
76995 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
76996 new->sgid = new->egid;
76997 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
76998 old = current_cred();
76999
77000 retval = -EPERM;
77001 +
77002 + if (gr_check_group_change(kgid, kgid, kgid))
77003 + goto error;
77004 +
77005 if (nsown_capable(CAP_SETGID))
77006 new->gid = new->egid = new->sgid = new->fsgid = kgid;
77007 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
77008 @@ -647,7 +660,7 @@ error:
77009 /*
77010 * change the user struct in a credentials set to match the new UID
77011 */
77012 -static int set_user(struct cred *new)
77013 +int set_user(struct cred *new)
77014 {
77015 struct user_struct *new_user;
77016
77017 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
77018 goto error;
77019 }
77020
77021 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
77022 + goto error;
77023 +
77024 if (!uid_eq(new->uid, old->uid)) {
77025 retval = set_user(new);
77026 if (retval < 0)
77027 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
77028 old = current_cred();
77029
77030 retval = -EPERM;
77031 +
77032 + if (gr_check_crash_uid(kuid))
77033 + goto error;
77034 + if (gr_check_user_change(kuid, kuid, kuid))
77035 + goto error;
77036 +
77037 if (nsown_capable(CAP_SETUID)) {
77038 new->suid = new->uid = kuid;
77039 if (!uid_eq(kuid, old->uid)) {
77040 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
77041 goto error;
77042 }
77043
77044 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
77045 + goto error;
77046 +
77047 if (ruid != (uid_t) -1) {
77048 new->uid = kruid;
77049 if (!uid_eq(kruid, old->uid)) {
77050 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
77051 goto error;
77052 }
77053
77054 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
77055 + goto error;
77056 +
77057 if (rgid != (gid_t) -1)
77058 new->gid = krgid;
77059 if (egid != (gid_t) -1)
77060 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77061 if (!uid_valid(kuid))
77062 return old_fsuid;
77063
77064 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
77065 + goto error;
77066 +
77067 new = prepare_creds();
77068 if (!new)
77069 return old_fsuid;
77070 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77071 }
77072 }
77073
77074 +error:
77075 abort_creds(new);
77076 return old_fsuid;
77077
77078 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
77079 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
77080 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
77081 nsown_capable(CAP_SETGID)) {
77082 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
77083 + goto error;
77084 +
77085 if (!gid_eq(kgid, old->fsgid)) {
77086 new->fsgid = kgid;
77087 goto change_okay;
77088 }
77089 }
77090
77091 +error:
77092 abort_creds(new);
77093 return old_fsgid;
77094
77095 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
77096 return -EFAULT;
77097
77098 down_read(&uts_sem);
77099 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
77100 + error = __copy_to_user(name->sysname, &utsname()->sysname,
77101 __OLD_UTS_LEN);
77102 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
77103 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
77104 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
77105 __OLD_UTS_LEN);
77106 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
77107 - error |= __copy_to_user(&name->release, &utsname()->release,
77108 + error |= __copy_to_user(name->release, &utsname()->release,
77109 __OLD_UTS_LEN);
77110 error |= __put_user(0, name->release + __OLD_UTS_LEN);
77111 - error |= __copy_to_user(&name->version, &utsname()->version,
77112 + error |= __copy_to_user(name->version, &utsname()->version,
77113 __OLD_UTS_LEN);
77114 error |= __put_user(0, name->version + __OLD_UTS_LEN);
77115 - error |= __copy_to_user(&name->machine, &utsname()->machine,
77116 + error |= __copy_to_user(name->machine, &utsname()->machine,
77117 __OLD_UTS_LEN);
77118 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
77119 up_read(&uts_sem);
77120 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
77121 error = get_dumpable(me->mm);
77122 break;
77123 case PR_SET_DUMPABLE:
77124 - if (arg2 < 0 || arg2 > 1) {
77125 + if (arg2 > 1) {
77126 error = -EINVAL;
77127 break;
77128 }
77129 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
77130 index c88878d..e4fa5d1 100644
77131 --- a/kernel/sysctl.c
77132 +++ b/kernel/sysctl.c
77133 @@ -92,7 +92,6 @@
77134
77135
77136 #if defined(CONFIG_SYSCTL)
77137 -
77138 /* External variables not in a header file. */
77139 extern int sysctl_overcommit_memory;
77140 extern int sysctl_overcommit_ratio;
77141 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
77142 void __user *buffer, size_t *lenp, loff_t *ppos);
77143 #endif
77144
77145 -#ifdef CONFIG_PRINTK
77146 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77147 void __user *buffer, size_t *lenp, loff_t *ppos);
77148 -#endif
77149
77150 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
77151 void __user *buffer, size_t *lenp, loff_t *ppos);
77152 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
77153
77154 #endif
77155
77156 +extern struct ctl_table grsecurity_table[];
77157 +
77158 static struct ctl_table kern_table[];
77159 static struct ctl_table vm_table[];
77160 static struct ctl_table fs_table[];
77161 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
77162 int sysctl_legacy_va_layout;
77163 #endif
77164
77165 +#ifdef CONFIG_PAX_SOFTMODE
77166 +static ctl_table pax_table[] = {
77167 + {
77168 + .procname = "softmode",
77169 + .data = &pax_softmode,
77170 + .maxlen = sizeof(unsigned int),
77171 + .mode = 0600,
77172 + .proc_handler = &proc_dointvec,
77173 + },
77174 +
77175 + { }
77176 +};
77177 +#endif
77178 +
77179 /* The default sysctl tables: */
77180
77181 static struct ctl_table sysctl_base_table[] = {
77182 @@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
77183 #endif
77184
77185 static struct ctl_table kern_table[] = {
77186 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
77187 + {
77188 + .procname = "grsecurity",
77189 + .mode = 0500,
77190 + .child = grsecurity_table,
77191 + },
77192 +#endif
77193 +
77194 +#ifdef CONFIG_PAX_SOFTMODE
77195 + {
77196 + .procname = "pax",
77197 + .mode = 0500,
77198 + .child = pax_table,
77199 + },
77200 +#endif
77201 +
77202 {
77203 .procname = "sched_child_runs_first",
77204 .data = &sysctl_sched_child_runs_first,
77205 @@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
77206 .data = &modprobe_path,
77207 .maxlen = KMOD_PATH_LEN,
77208 .mode = 0644,
77209 - .proc_handler = proc_dostring,
77210 + .proc_handler = proc_dostring_modpriv,
77211 },
77212 {
77213 .procname = "modules_disabled",
77214 @@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
77215 .extra1 = &zero,
77216 .extra2 = &one,
77217 },
77218 +#endif
77219 {
77220 .procname = "kptr_restrict",
77221 .data = &kptr_restrict,
77222 .maxlen = sizeof(int),
77223 .mode = 0644,
77224 .proc_handler = proc_dointvec_minmax_sysadmin,
77225 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77226 + .extra1 = &two,
77227 +#else
77228 .extra1 = &zero,
77229 +#endif
77230 .extra2 = &two,
77231 },
77232 -#endif
77233 {
77234 .procname = "ngroups_max",
77235 .data = &ngroups_max,
77236 @@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
77237 .proc_handler = proc_dointvec_minmax,
77238 .extra1 = &zero,
77239 },
77240 + {
77241 + .procname = "heap_stack_gap",
77242 + .data = &sysctl_heap_stack_gap,
77243 + .maxlen = sizeof(sysctl_heap_stack_gap),
77244 + .mode = 0644,
77245 + .proc_handler = proc_doulongvec_minmax,
77246 + },
77247 #else
77248 {
77249 .procname = "nr_trim_pages",
77250 @@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
77251 buffer, lenp, ppos);
77252 }
77253
77254 +int proc_dostring_modpriv(struct ctl_table *table, int write,
77255 + void __user *buffer, size_t *lenp, loff_t *ppos)
77256 +{
77257 + if (write && !capable(CAP_SYS_MODULE))
77258 + return -EPERM;
77259 +
77260 + return _proc_do_string(table->data, table->maxlen, write,
77261 + buffer, lenp, ppos);
77262 +}
77263 +
77264 static size_t proc_skip_spaces(char **buf)
77265 {
77266 size_t ret;
77267 @@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
77268 len = strlen(tmp);
77269 if (len > *size)
77270 len = *size;
77271 + if (len > sizeof(tmp))
77272 + len = sizeof(tmp);
77273 if (copy_to_user(*buf, tmp, len))
77274 return -EFAULT;
77275 *size -= len;
77276 @@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
77277 static int proc_taint(struct ctl_table *table, int write,
77278 void __user *buffer, size_t *lenp, loff_t *ppos)
77279 {
77280 - struct ctl_table t;
77281 + ctl_table_no_const t;
77282 unsigned long tmptaint = get_taint();
77283 int err;
77284
77285 @@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
77286 return err;
77287 }
77288
77289 -#ifdef CONFIG_PRINTK
77290 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77291 void __user *buffer, size_t *lenp, loff_t *ppos)
77292 {
77293 @@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77294
77295 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
77296 }
77297 -#endif
77298
77299 struct do_proc_dointvec_minmax_conv_param {
77300 int *min;
77301 @@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
77302 *i = val;
77303 } else {
77304 val = convdiv * (*i) / convmul;
77305 - if (!first)
77306 + if (!first) {
77307 err = proc_put_char(&buffer, &left, '\t');
77308 + if (err)
77309 + break;
77310 + }
77311 err = proc_put_long(&buffer, &left, val, false);
77312 if (err)
77313 break;
77314 @@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
77315 return -ENOSYS;
77316 }
77317
77318 +int proc_dostring_modpriv(struct ctl_table *table, int write,
77319 + void __user *buffer, size_t *lenp, loff_t *ppos)
77320 +{
77321 + return -ENOSYS;
77322 +}
77323 +
77324 int proc_dointvec(struct ctl_table *table, int write,
77325 void __user *buffer, size_t *lenp, loff_t *ppos)
77326 {
77327 @@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
77328 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
77329 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
77330 EXPORT_SYMBOL(proc_dostring);
77331 +EXPORT_SYMBOL(proc_dostring_modpriv);
77332 EXPORT_SYMBOL(proc_doulongvec_minmax);
77333 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
77334 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
77335 index 0ddf3a0..a199f50 100644
77336 --- a/kernel/sysctl_binary.c
77337 +++ b/kernel/sysctl_binary.c
77338 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
77339 int i;
77340
77341 set_fs(KERNEL_DS);
77342 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
77343 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
77344 set_fs(old_fs);
77345 if (result < 0)
77346 goto out_kfree;
77347 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
77348 }
77349
77350 set_fs(KERNEL_DS);
77351 - result = vfs_write(file, buffer, str - buffer, &pos);
77352 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
77353 set_fs(old_fs);
77354 if (result < 0)
77355 goto out_kfree;
77356 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
77357 int i;
77358
77359 set_fs(KERNEL_DS);
77360 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
77361 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
77362 set_fs(old_fs);
77363 if (result < 0)
77364 goto out_kfree;
77365 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
77366 }
77367
77368 set_fs(KERNEL_DS);
77369 - result = vfs_write(file, buffer, str - buffer, &pos);
77370 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
77371 set_fs(old_fs);
77372 if (result < 0)
77373 goto out_kfree;
77374 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
77375 int i;
77376
77377 set_fs(KERNEL_DS);
77378 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
77379 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
77380 set_fs(old_fs);
77381 if (result < 0)
77382 goto out;
77383 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
77384 __le16 dnaddr;
77385
77386 set_fs(KERNEL_DS);
77387 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
77388 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
77389 set_fs(old_fs);
77390 if (result < 0)
77391 goto out;
77392 @@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
77393 le16_to_cpu(dnaddr) & 0x3ff);
77394
77395 set_fs(KERNEL_DS);
77396 - result = vfs_write(file, buf, len, &pos);
77397 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
77398 set_fs(old_fs);
77399 if (result < 0)
77400 goto out;
77401 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
77402 index 145bb4d..b2aa969 100644
77403 --- a/kernel/taskstats.c
77404 +++ b/kernel/taskstats.c
77405 @@ -28,9 +28,12 @@
77406 #include <linux/fs.h>
77407 #include <linux/file.h>
77408 #include <linux/pid_namespace.h>
77409 +#include <linux/grsecurity.h>
77410 #include <net/genetlink.h>
77411 #include <linux/atomic.h>
77412
77413 +extern int gr_is_taskstats_denied(int pid);
77414 +
77415 /*
77416 * Maximum length of a cpumask that can be specified in
77417 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
77418 @@ -570,6 +573,9 @@ err:
77419
77420 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
77421 {
77422 + if (gr_is_taskstats_denied(current->pid))
77423 + return -EACCES;
77424 +
77425 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
77426 return cmd_attr_register_cpumask(info);
77427 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
77428 diff --git a/kernel/time.c b/kernel/time.c
77429 index d226c6a..c7c0960 100644
77430 --- a/kernel/time.c
77431 +++ b/kernel/time.c
77432 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
77433 return error;
77434
77435 if (tz) {
77436 + /* we log in do_settimeofday called below, so don't log twice
77437 + */
77438 + if (!tv)
77439 + gr_log_timechange();
77440 +
77441 sys_tz = *tz;
77442 update_vsyscall_tz();
77443 if (firsttime) {
77444 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
77445 index f11d83b..d016d91 100644
77446 --- a/kernel/time/alarmtimer.c
77447 +++ b/kernel/time/alarmtimer.c
77448 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
77449 struct platform_device *pdev;
77450 int error = 0;
77451 int i;
77452 - struct k_clock alarm_clock = {
77453 + static struct k_clock alarm_clock = {
77454 .clock_getres = alarm_clock_getres,
77455 .clock_get = alarm_clock_get,
77456 .timer_create = alarm_timer_create,
77457 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
77458 index f113755..ec24223 100644
77459 --- a/kernel/time/tick-broadcast.c
77460 +++ b/kernel/time/tick-broadcast.c
77461 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
77462 * then clear the broadcast bit.
77463 */
77464 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
77465 - int cpu = smp_processor_id();
77466 + cpu = smp_processor_id();
77467
77468 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
77469 tick_broadcast_clear_oneshot(cpu);
77470 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
77471 index cbc6acb..3a77191 100644
77472 --- a/kernel/time/timekeeping.c
77473 +++ b/kernel/time/timekeeping.c
77474 @@ -15,6 +15,7 @@
77475 #include <linux/init.h>
77476 #include <linux/mm.h>
77477 #include <linux/sched.h>
77478 +#include <linux/grsecurity.h>
77479 #include <linux/syscore_ops.h>
77480 #include <linux/clocksource.h>
77481 #include <linux/jiffies.h>
77482 @@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
77483 if (!timespec_valid_strict(tv))
77484 return -EINVAL;
77485
77486 + gr_log_timechange();
77487 +
77488 write_seqlock_irqsave(&tk->lock, flags);
77489
77490 timekeeping_forward_now(tk);
77491 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
77492 index af5a7e9..715611a 100644
77493 --- a/kernel/time/timer_list.c
77494 +++ b/kernel/time/timer_list.c
77495 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
77496
77497 static void print_name_offset(struct seq_file *m, void *sym)
77498 {
77499 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77500 + SEQ_printf(m, "<%p>", NULL);
77501 +#else
77502 char symname[KSYM_NAME_LEN];
77503
77504 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
77505 SEQ_printf(m, "<%pK>", sym);
77506 else
77507 SEQ_printf(m, "%s", symname);
77508 +#endif
77509 }
77510
77511 static void
77512 @@ -112,7 +116,11 @@ next_one:
77513 static void
77514 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
77515 {
77516 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77517 + SEQ_printf(m, " .base: %p\n", NULL);
77518 +#else
77519 SEQ_printf(m, " .base: %pK\n", base);
77520 +#endif
77521 SEQ_printf(m, " .index: %d\n",
77522 base->index);
77523 SEQ_printf(m, " .resolution: %Lu nsecs\n",
77524 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
77525 {
77526 struct proc_dir_entry *pe;
77527
77528 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
77529 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
77530 +#else
77531 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
77532 +#endif
77533 if (!pe)
77534 return -ENOMEM;
77535 return 0;
77536 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
77537 index 0b537f2..40d6c20 100644
77538 --- a/kernel/time/timer_stats.c
77539 +++ b/kernel/time/timer_stats.c
77540 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
77541 static unsigned long nr_entries;
77542 static struct entry entries[MAX_ENTRIES];
77543
77544 -static atomic_t overflow_count;
77545 +static atomic_unchecked_t overflow_count;
77546
77547 /*
77548 * The entries are in a hash-table, for fast lookup:
77549 @@ -140,7 +140,7 @@ static void reset_entries(void)
77550 nr_entries = 0;
77551 memset(entries, 0, sizeof(entries));
77552 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
77553 - atomic_set(&overflow_count, 0);
77554 + atomic_set_unchecked(&overflow_count, 0);
77555 }
77556
77557 static struct entry *alloc_entry(void)
77558 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
77559 if (likely(entry))
77560 entry->count++;
77561 else
77562 - atomic_inc(&overflow_count);
77563 + atomic_inc_unchecked(&overflow_count);
77564
77565 out_unlock:
77566 raw_spin_unlock_irqrestore(lock, flags);
77567 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
77568
77569 static void print_name_offset(struct seq_file *m, unsigned long addr)
77570 {
77571 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77572 + seq_printf(m, "<%p>", NULL);
77573 +#else
77574 char symname[KSYM_NAME_LEN];
77575
77576 if (lookup_symbol_name(addr, symname) < 0)
77577 - seq_printf(m, "<%p>", (void *)addr);
77578 + seq_printf(m, "<%pK>", (void *)addr);
77579 else
77580 seq_printf(m, "%s", symname);
77581 +#endif
77582 }
77583
77584 static int tstats_show(struct seq_file *m, void *v)
77585 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
77586
77587 seq_puts(m, "Timer Stats Version: v0.2\n");
77588 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
77589 - if (atomic_read(&overflow_count))
77590 + if (atomic_read_unchecked(&overflow_count))
77591 seq_printf(m, "Overflow: %d entries\n",
77592 - atomic_read(&overflow_count));
77593 + atomic_read_unchecked(&overflow_count));
77594
77595 for (i = 0; i < nr_entries; i++) {
77596 entry = entries + i;
77597 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
77598 {
77599 struct proc_dir_entry *pe;
77600
77601 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
77602 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
77603 +#else
77604 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
77605 +#endif
77606 if (!pe)
77607 return -ENOMEM;
77608 return 0;
77609 diff --git a/kernel/timer.c b/kernel/timer.c
77610 index 367d008..1ee9ed9 100644
77611 --- a/kernel/timer.c
77612 +++ b/kernel/timer.c
77613 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
77614 /*
77615 * This function runs timers and the timer-tq in bottom half context.
77616 */
77617 -static void run_timer_softirq(struct softirq_action *h)
77618 +static void run_timer_softirq(void)
77619 {
77620 struct tvec_base *base = __this_cpu_read(tvec_bases);
77621
77622 @@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
77623 return NOTIFY_OK;
77624 }
77625
77626 -static struct notifier_block __cpuinitdata timers_nb = {
77627 +static struct notifier_block timers_nb = {
77628 .notifier_call = timer_cpu_notify,
77629 };
77630
77631 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
77632 index c0bd030..62a1927 100644
77633 --- a/kernel/trace/blktrace.c
77634 +++ b/kernel/trace/blktrace.c
77635 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
77636 struct blk_trace *bt = filp->private_data;
77637 char buf[16];
77638
77639 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
77640 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
77641
77642 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
77643 }
77644 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
77645 return 1;
77646
77647 bt = buf->chan->private_data;
77648 - atomic_inc(&bt->dropped);
77649 + atomic_inc_unchecked(&bt->dropped);
77650 return 0;
77651 }
77652
77653 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
77654
77655 bt->dir = dir;
77656 bt->dev = dev;
77657 - atomic_set(&bt->dropped, 0);
77658 + atomic_set_unchecked(&bt->dropped, 0);
77659
77660 ret = -EIO;
77661 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
77662 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
77663 index 43defd1..76da436 100644
77664 --- a/kernel/trace/ftrace.c
77665 +++ b/kernel/trace/ftrace.c
77666 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
77667 if (unlikely(ftrace_disabled))
77668 return 0;
77669
77670 + ret = ftrace_arch_code_modify_prepare();
77671 + FTRACE_WARN_ON(ret);
77672 + if (ret)
77673 + return 0;
77674 +
77675 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
77676 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
77677 if (ret) {
77678 ftrace_bug(ret, ip);
77679 - return 0;
77680 }
77681 - return 1;
77682 + return ret ? 0 : 1;
77683 }
77684
77685 /*
77686 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
77687
77688 int
77689 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
77690 - void *data)
77691 + void *data)
77692 {
77693 struct ftrace_func_probe *entry;
77694 struct ftrace_page *pg;
77695 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
77696 if (!count)
77697 return 0;
77698
77699 + pax_open_kernel();
77700 sort(start, count, sizeof(*start),
77701 ftrace_cmp_ips, ftrace_swap_ips);
77702 + pax_close_kernel();
77703
77704 start_pg = ftrace_allocate_pages(count);
77705 if (!start_pg)
77706 @@ -4559,8 +4566,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
77707 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
77708
77709 static int ftrace_graph_active;
77710 -static struct notifier_block ftrace_suspend_notifier;
77711 -
77712 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
77713 {
77714 return 0;
77715 @@ -4704,6 +4709,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
77716 return NOTIFY_DONE;
77717 }
77718
77719 +static struct notifier_block ftrace_suspend_notifier = {
77720 + .notifier_call = ftrace_suspend_notifier_call
77721 +};
77722 +
77723 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
77724 trace_func_graph_ent_t entryfunc)
77725 {
77726 @@ -4717,7 +4726,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
77727 goto out;
77728 }
77729
77730 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
77731 register_pm_notifier(&ftrace_suspend_notifier);
77732
77733 ftrace_graph_active++;
77734 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
77735 index ce8514f..8233573 100644
77736 --- a/kernel/trace/ring_buffer.c
77737 +++ b/kernel/trace/ring_buffer.c
77738 @@ -346,9 +346,9 @@ struct buffer_data_page {
77739 */
77740 struct buffer_page {
77741 struct list_head list; /* list of buffer pages */
77742 - local_t write; /* index for next write */
77743 + local_unchecked_t write; /* index for next write */
77744 unsigned read; /* index for next read */
77745 - local_t entries; /* entries on this page */
77746 + local_unchecked_t entries; /* entries on this page */
77747 unsigned long real_end; /* real end of data */
77748 struct buffer_data_page *page; /* Actual data page */
77749 };
77750 @@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
77751 unsigned long last_overrun;
77752 local_t entries_bytes;
77753 local_t entries;
77754 - local_t overrun;
77755 - local_t commit_overrun;
77756 + local_unchecked_t overrun;
77757 + local_unchecked_t commit_overrun;
77758 local_t dropped_events;
77759 local_t committing;
77760 local_t commits;
77761 @@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
77762 *
77763 * We add a counter to the write field to denote this.
77764 */
77765 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
77766 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
77767 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
77768 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
77769
77770 /*
77771 * Just make sure we have seen our old_write and synchronize
77772 @@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
77773 * cmpxchg to only update if an interrupt did not already
77774 * do it for us. If the cmpxchg fails, we don't care.
77775 */
77776 - (void)local_cmpxchg(&next_page->write, old_write, val);
77777 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
77778 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
77779 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
77780
77781 /*
77782 * No need to worry about races with clearing out the commit.
77783 @@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
77784
77785 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
77786 {
77787 - return local_read(&bpage->entries) & RB_WRITE_MASK;
77788 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
77789 }
77790
77791 static inline unsigned long rb_page_write(struct buffer_page *bpage)
77792 {
77793 - return local_read(&bpage->write) & RB_WRITE_MASK;
77794 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
77795 }
77796
77797 static int
77798 @@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
77799 * bytes consumed in ring buffer from here.
77800 * Increment overrun to account for the lost events.
77801 */
77802 - local_add(page_entries, &cpu_buffer->overrun);
77803 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
77804 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
77805 }
77806
77807 @@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
77808 * it is our responsibility to update
77809 * the counters.
77810 */
77811 - local_add(entries, &cpu_buffer->overrun);
77812 + local_add_unchecked(entries, &cpu_buffer->overrun);
77813 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
77814
77815 /*
77816 @@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77817 if (tail == BUF_PAGE_SIZE)
77818 tail_page->real_end = 0;
77819
77820 - local_sub(length, &tail_page->write);
77821 + local_sub_unchecked(length, &tail_page->write);
77822 return;
77823 }
77824
77825 @@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77826 rb_event_set_padding(event);
77827
77828 /* Set the write back to the previous setting */
77829 - local_sub(length, &tail_page->write);
77830 + local_sub_unchecked(length, &tail_page->write);
77831 return;
77832 }
77833
77834 @@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77835
77836 /* Set write to end of buffer */
77837 length = (tail + length) - BUF_PAGE_SIZE;
77838 - local_sub(length, &tail_page->write);
77839 + local_sub_unchecked(length, &tail_page->write);
77840 }
77841
77842 /*
77843 @@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
77844 * about it.
77845 */
77846 if (unlikely(next_page == commit_page)) {
77847 - local_inc(&cpu_buffer->commit_overrun);
77848 + local_inc_unchecked(&cpu_buffer->commit_overrun);
77849 goto out_reset;
77850 }
77851
77852 @@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
77853 cpu_buffer->tail_page) &&
77854 (cpu_buffer->commit_page ==
77855 cpu_buffer->reader_page))) {
77856 - local_inc(&cpu_buffer->commit_overrun);
77857 + local_inc_unchecked(&cpu_buffer->commit_overrun);
77858 goto out_reset;
77859 }
77860 }
77861 @@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
77862 length += RB_LEN_TIME_EXTEND;
77863
77864 tail_page = cpu_buffer->tail_page;
77865 - write = local_add_return(length, &tail_page->write);
77866 + write = local_add_return_unchecked(length, &tail_page->write);
77867
77868 /* set write to only the index of the write */
77869 write &= RB_WRITE_MASK;
77870 @@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
77871 kmemcheck_annotate_bitfield(event, bitfield);
77872 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
77873
77874 - local_inc(&tail_page->entries);
77875 + local_inc_unchecked(&tail_page->entries);
77876
77877 /*
77878 * If this is the first commit on the page, then update
77879 @@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
77880
77881 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
77882 unsigned long write_mask =
77883 - local_read(&bpage->write) & ~RB_WRITE_MASK;
77884 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
77885 unsigned long event_length = rb_event_length(event);
77886 /*
77887 * This is on the tail page. It is possible that
77888 @@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
77889 */
77890 old_index += write_mask;
77891 new_index += write_mask;
77892 - index = local_cmpxchg(&bpage->write, old_index, new_index);
77893 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
77894 if (index == old_index) {
77895 /* update counters */
77896 local_sub(event_length, &cpu_buffer->entries_bytes);
77897 @@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
77898
77899 /* Do the likely case first */
77900 if (likely(bpage->page == (void *)addr)) {
77901 - local_dec(&bpage->entries);
77902 + local_dec_unchecked(&bpage->entries);
77903 return;
77904 }
77905
77906 @@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
77907 start = bpage;
77908 do {
77909 if (bpage->page == (void *)addr) {
77910 - local_dec(&bpage->entries);
77911 + local_dec_unchecked(&bpage->entries);
77912 return;
77913 }
77914 rb_inc_page(cpu_buffer, &bpage);
77915 @@ -2926,7 +2926,7 @@ static inline unsigned long
77916 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
77917 {
77918 return local_read(&cpu_buffer->entries) -
77919 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
77920 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
77921 }
77922
77923 /**
77924 @@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
77925 return 0;
77926
77927 cpu_buffer = buffer->buffers[cpu];
77928 - ret = local_read(&cpu_buffer->overrun);
77929 + ret = local_read_unchecked(&cpu_buffer->overrun);
77930
77931 return ret;
77932 }
77933 @@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
77934 return 0;
77935
77936 cpu_buffer = buffer->buffers[cpu];
77937 - ret = local_read(&cpu_buffer->commit_overrun);
77938 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
77939
77940 return ret;
77941 }
77942 @@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
77943 /* if you care about this being correct, lock the buffer */
77944 for_each_buffer_cpu(buffer, cpu) {
77945 cpu_buffer = buffer->buffers[cpu];
77946 - overruns += local_read(&cpu_buffer->overrun);
77947 + overruns += local_read_unchecked(&cpu_buffer->overrun);
77948 }
77949
77950 return overruns;
77951 @@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
77952 /*
77953 * Reset the reader page to size zero.
77954 */
77955 - local_set(&cpu_buffer->reader_page->write, 0);
77956 - local_set(&cpu_buffer->reader_page->entries, 0);
77957 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
77958 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
77959 local_set(&cpu_buffer->reader_page->page->commit, 0);
77960 cpu_buffer->reader_page->real_end = 0;
77961
77962 @@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
77963 * want to compare with the last_overrun.
77964 */
77965 smp_mb();
77966 - overwrite = local_read(&(cpu_buffer->overrun));
77967 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
77968
77969 /*
77970 * Here's the tricky part.
77971 @@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
77972
77973 cpu_buffer->head_page
77974 = list_entry(cpu_buffer->pages, struct buffer_page, list);
77975 - local_set(&cpu_buffer->head_page->write, 0);
77976 - local_set(&cpu_buffer->head_page->entries, 0);
77977 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
77978 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
77979 local_set(&cpu_buffer->head_page->page->commit, 0);
77980
77981 cpu_buffer->head_page->read = 0;
77982 @@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
77983
77984 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
77985 INIT_LIST_HEAD(&cpu_buffer->new_pages);
77986 - local_set(&cpu_buffer->reader_page->write, 0);
77987 - local_set(&cpu_buffer->reader_page->entries, 0);
77988 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
77989 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
77990 local_set(&cpu_buffer->reader_page->page->commit, 0);
77991 cpu_buffer->reader_page->read = 0;
77992
77993 local_set(&cpu_buffer->entries_bytes, 0);
77994 - local_set(&cpu_buffer->overrun, 0);
77995 - local_set(&cpu_buffer->commit_overrun, 0);
77996 + local_set_unchecked(&cpu_buffer->overrun, 0);
77997 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
77998 local_set(&cpu_buffer->dropped_events, 0);
77999 local_set(&cpu_buffer->entries, 0);
78000 local_set(&cpu_buffer->committing, 0);
78001 @@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
78002 rb_init_page(bpage);
78003 bpage = reader->page;
78004 reader->page = *data_page;
78005 - local_set(&reader->write, 0);
78006 - local_set(&reader->entries, 0);
78007 + local_set_unchecked(&reader->write, 0);
78008 + local_set_unchecked(&reader->entries, 0);
78009 reader->read = 0;
78010 *data_page = bpage;
78011
78012 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
78013 index 3c13e46..883d039 100644
78014 --- a/kernel/trace/trace.c
78015 +++ b/kernel/trace/trace.c
78016 @@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
78017 };
78018 #endif
78019
78020 -static struct dentry *d_tracer;
78021 -
78022 struct dentry *tracing_init_dentry(void)
78023 {
78024 + static struct dentry *d_tracer;
78025 static int once;
78026
78027 if (d_tracer)
78028 @@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
78029 return d_tracer;
78030 }
78031
78032 -static struct dentry *d_percpu;
78033 -
78034 struct dentry *tracing_dentry_percpu(void)
78035 {
78036 + static struct dentry *d_percpu;
78037 static int once;
78038 struct dentry *d_tracer;
78039
78040 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
78041 index 880073d..42db7c3 100644
78042 --- a/kernel/trace/trace_events.c
78043 +++ b/kernel/trace/trace_events.c
78044 @@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
78045 struct ftrace_module_file_ops {
78046 struct list_head list;
78047 struct module *mod;
78048 - struct file_operations id;
78049 - struct file_operations enable;
78050 - struct file_operations format;
78051 - struct file_operations filter;
78052 };
78053
78054 static struct ftrace_module_file_ops *
78055 @@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
78056
78057 file_ops->mod = mod;
78058
78059 - file_ops->id = ftrace_event_id_fops;
78060 - file_ops->id.owner = mod;
78061 -
78062 - file_ops->enable = ftrace_enable_fops;
78063 - file_ops->enable.owner = mod;
78064 -
78065 - file_ops->filter = ftrace_event_filter_fops;
78066 - file_ops->filter.owner = mod;
78067 -
78068 - file_ops->format = ftrace_event_format_fops;
78069 - file_ops->format.owner = mod;
78070 + pax_open_kernel();
78071 + mod->trace_id.owner = mod;
78072 + mod->trace_enable.owner = mod;
78073 + mod->trace_filter.owner = mod;
78074 + mod->trace_format.owner = mod;
78075 + pax_close_kernel();
78076
78077 list_add(&file_ops->list, &ftrace_module_file_list);
78078
78079 @@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
78080
78081 for_each_event(call, start, end) {
78082 __trace_add_event_call(*call, mod,
78083 - &file_ops->id, &file_ops->enable,
78084 - &file_ops->filter, &file_ops->format);
78085 + &mod->trace_id, &mod->trace_enable,
78086 + &mod->trace_filter, &mod->trace_format);
78087 }
78088 }
78089
78090 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
78091 index fd3c8aa..5f324a6 100644
78092 --- a/kernel/trace/trace_mmiotrace.c
78093 +++ b/kernel/trace/trace_mmiotrace.c
78094 @@ -24,7 +24,7 @@ struct header_iter {
78095 static struct trace_array *mmio_trace_array;
78096 static bool overrun_detected;
78097 static unsigned long prev_overruns;
78098 -static atomic_t dropped_count;
78099 +static atomic_unchecked_t dropped_count;
78100
78101 static void mmio_reset_data(struct trace_array *tr)
78102 {
78103 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
78104
78105 static unsigned long count_overruns(struct trace_iterator *iter)
78106 {
78107 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
78108 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
78109 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
78110
78111 if (over > prev_overruns)
78112 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
78113 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
78114 sizeof(*entry), 0, pc);
78115 if (!event) {
78116 - atomic_inc(&dropped_count);
78117 + atomic_inc_unchecked(&dropped_count);
78118 return;
78119 }
78120 entry = ring_buffer_event_data(event);
78121 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
78122 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
78123 sizeof(*entry), 0, pc);
78124 if (!event) {
78125 - atomic_inc(&dropped_count);
78126 + atomic_inc_unchecked(&dropped_count);
78127 return;
78128 }
78129 entry = ring_buffer_event_data(event);
78130 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
78131 index 194d796..76edb8f 100644
78132 --- a/kernel/trace/trace_output.c
78133 +++ b/kernel/trace/trace_output.c
78134 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
78135
78136 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
78137 if (!IS_ERR(p)) {
78138 - p = mangle_path(s->buffer + s->len, p, "\n");
78139 + p = mangle_path(s->buffer + s->len, p, "\n\\");
78140 if (p) {
78141 s->len = p - s->buffer;
78142 return 1;
78143 @@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
78144 goto out;
78145 }
78146
78147 + pax_open_kernel();
78148 if (event->funcs->trace == NULL)
78149 - event->funcs->trace = trace_nop_print;
78150 + *(void **)&event->funcs->trace = trace_nop_print;
78151 if (event->funcs->raw == NULL)
78152 - event->funcs->raw = trace_nop_print;
78153 + *(void **)&event->funcs->raw = trace_nop_print;
78154 if (event->funcs->hex == NULL)
78155 - event->funcs->hex = trace_nop_print;
78156 + *(void **)&event->funcs->hex = trace_nop_print;
78157 if (event->funcs->binary == NULL)
78158 - event->funcs->binary = trace_nop_print;
78159 + *(void **)&event->funcs->binary = trace_nop_print;
78160 + pax_close_kernel();
78161
78162 key = event->type & (EVENT_HASHSIZE - 1);
78163
78164 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
78165 index 42ca822..cdcacc6 100644
78166 --- a/kernel/trace/trace_stack.c
78167 +++ b/kernel/trace/trace_stack.c
78168 @@ -52,7 +52,7 @@ static inline void check_stack(void)
78169 return;
78170
78171 /* we do not handle interrupt stacks yet */
78172 - if (!object_is_on_stack(&this_size))
78173 + if (!object_starts_on_stack(&this_size))
78174 return;
78175
78176 local_irq_save(flags);
78177 diff --git a/kernel/user.c b/kernel/user.c
78178 index 33acb5e..57ebfd4 100644
78179 --- a/kernel/user.c
78180 +++ b/kernel/user.c
78181 @@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
78182 .count = 4294967295U,
78183 },
78184 },
78185 - .kref = {
78186 - .refcount = ATOMIC_INIT(3),
78187 - },
78188 + .count = ATOMIC_INIT(3),
78189 .owner = GLOBAL_ROOT_UID,
78190 .group = GLOBAL_ROOT_GID,
78191 .proc_inum = PROC_USER_INIT_INO,
78192 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
78193 index dbfe36a7..6d36e9a 100644
78194 --- a/kernel/user_namespace.c
78195 +++ b/kernel/user_namespace.c
78196 @@ -79,7 +79,7 @@ int create_user_ns(struct cred *new)
78197 return ret;
78198 }
78199
78200 - kref_init(&ns->kref);
78201 + atomic_set(&ns->count, 1);
78202 /* Leave the new->user_ns reference with the new user namespace. */
78203 ns->parent = parent_ns;
78204 ns->owner = owner;
78205 @@ -105,15 +105,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
78206 return create_user_ns(cred);
78207 }
78208
78209 -void free_user_ns(struct kref *kref)
78210 +void free_user_ns(struct user_namespace *ns)
78211 {
78212 - struct user_namespace *parent, *ns =
78213 - container_of(kref, struct user_namespace, kref);
78214 + struct user_namespace *parent;
78215
78216 - parent = ns->parent;
78217 - proc_free_inum(ns->proc_inum);
78218 - kmem_cache_free(user_ns_cachep, ns);
78219 - put_user_ns(parent);
78220 + do {
78221 + parent = ns->parent;
78222 + proc_free_inum(ns->proc_inum);
78223 + kmem_cache_free(user_ns_cachep, ns);
78224 + ns = parent;
78225 + } while (atomic_dec_and_test(&parent->count));
78226 }
78227 EXPORT_SYMBOL(free_user_ns);
78228
78229 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
78230 index 63da38c..639904e 100644
78231 --- a/kernel/utsname_sysctl.c
78232 +++ b/kernel/utsname_sysctl.c
78233 @@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
78234 static int proc_do_uts_string(ctl_table *table, int write,
78235 void __user *buffer, size_t *lenp, loff_t *ppos)
78236 {
78237 - struct ctl_table uts_table;
78238 + ctl_table_no_const uts_table;
78239 int r;
78240 memcpy(&uts_table, table, sizeof(uts_table));
78241 uts_table.data = get_uts(table, write);
78242 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
78243 index 75a2ab3..5961da7 100644
78244 --- a/kernel/watchdog.c
78245 +++ b/kernel/watchdog.c
78246 @@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
78247 }
78248 #endif /* CONFIG_SYSCTL */
78249
78250 -static struct smp_hotplug_thread watchdog_threads = {
78251 +static struct smp_hotplug_thread watchdog_threads __read_only = {
78252 .store = &softlockup_watchdog,
78253 .thread_should_run = watchdog_should_run,
78254 .thread_fn = watchdog,
78255 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
78256 index 67604e5..fe94fb1 100644
78257 --- a/lib/Kconfig.debug
78258 +++ b/lib/Kconfig.debug
78259 @@ -550,7 +550,7 @@ config DEBUG_MUTEXES
78260
78261 config DEBUG_LOCK_ALLOC
78262 bool "Lock debugging: detect incorrect freeing of live locks"
78263 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78264 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78265 select DEBUG_SPINLOCK
78266 select DEBUG_MUTEXES
78267 select LOCKDEP
78268 @@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
78269
78270 config PROVE_LOCKING
78271 bool "Lock debugging: prove locking correctness"
78272 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78273 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78274 select LOCKDEP
78275 select DEBUG_SPINLOCK
78276 select DEBUG_MUTEXES
78277 @@ -670,7 +670,7 @@ config LOCKDEP
78278
78279 config LOCK_STAT
78280 bool "Lock usage statistics"
78281 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78282 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78283 select LOCKDEP
78284 select DEBUG_SPINLOCK
78285 select DEBUG_MUTEXES
78286 @@ -1278,6 +1278,7 @@ config LATENCYTOP
78287 depends on DEBUG_KERNEL
78288 depends on STACKTRACE_SUPPORT
78289 depends on PROC_FS
78290 + depends on !GRKERNSEC_HIDESYM
78291 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
78292 select KALLSYMS
78293 select KALLSYMS_ALL
78294 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
78295
78296 config PROVIDE_OHCI1394_DMA_INIT
78297 bool "Remote debugging over FireWire early on boot"
78298 - depends on PCI && X86
78299 + depends on PCI && X86 && !GRKERNSEC
78300 help
78301 If you want to debug problems which hang or crash the kernel early
78302 on boot and the crashing machine has a FireWire port, you can use
78303 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
78304
78305 config FIREWIRE_OHCI_REMOTE_DMA
78306 bool "Remote debugging over FireWire with firewire-ohci"
78307 - depends on FIREWIRE_OHCI
78308 + depends on FIREWIRE_OHCI && !GRKERNSEC
78309 help
78310 This option lets you use the FireWire bus for remote debugging
78311 with help of the firewire-ohci driver. It enables unfiltered
78312 diff --git a/lib/Makefile b/lib/Makefile
78313 index 02ed6c0..bd243da 100644
78314 --- a/lib/Makefile
78315 +++ b/lib/Makefile
78316 @@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
78317
78318 obj-$(CONFIG_BTREE) += btree.o
78319 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
78320 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
78321 +obj-y += list_debug.o
78322 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
78323
78324 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
78325 diff --git a/lib/bitmap.c b/lib/bitmap.c
78326 index 06f7e4f..f3cf2b0 100644
78327 --- a/lib/bitmap.c
78328 +++ b/lib/bitmap.c
78329 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
78330 {
78331 int c, old_c, totaldigits, ndigits, nchunks, nbits;
78332 u32 chunk;
78333 - const char __user __force *ubuf = (const char __user __force *)buf;
78334 + const char __user *ubuf = (const char __force_user *)buf;
78335
78336 bitmap_zero(maskp, nmaskbits);
78337
78338 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
78339 {
78340 if (!access_ok(VERIFY_READ, ubuf, ulen))
78341 return -EFAULT;
78342 - return __bitmap_parse((const char __force *)ubuf,
78343 + return __bitmap_parse((const char __force_kernel *)ubuf,
78344 ulen, 1, maskp, nmaskbits);
78345
78346 }
78347 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
78348 {
78349 unsigned a, b;
78350 int c, old_c, totaldigits;
78351 - const char __user __force *ubuf = (const char __user __force *)buf;
78352 + const char __user *ubuf = (const char __force_user *)buf;
78353 int exp_digit, in_range;
78354
78355 totaldigits = c = 0;
78356 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
78357 {
78358 if (!access_ok(VERIFY_READ, ubuf, ulen))
78359 return -EFAULT;
78360 - return __bitmap_parselist((const char __force *)ubuf,
78361 + return __bitmap_parselist((const char __force_kernel *)ubuf,
78362 ulen, 1, maskp, nmaskbits);
78363 }
78364 EXPORT_SYMBOL(bitmap_parselist_user);
78365 diff --git a/lib/bug.c b/lib/bug.c
78366 index d0cdf14..4d07bd2 100644
78367 --- a/lib/bug.c
78368 +++ b/lib/bug.c
78369 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
78370 return BUG_TRAP_TYPE_NONE;
78371
78372 bug = find_bug(bugaddr);
78373 + if (!bug)
78374 + return BUG_TRAP_TYPE_NONE;
78375
78376 file = NULL;
78377 line = 0;
78378 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
78379 index d11808c..dc2d6f8 100644
78380 --- a/lib/debugobjects.c
78381 +++ b/lib/debugobjects.c
78382 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
78383 if (limit > 4)
78384 return;
78385
78386 - is_on_stack = object_is_on_stack(addr);
78387 + is_on_stack = object_starts_on_stack(addr);
78388 if (is_on_stack == onstack)
78389 return;
78390
78391 diff --git a/lib/devres.c b/lib/devres.c
78392 index 80b9c76..9e32279 100644
78393 --- a/lib/devres.c
78394 +++ b/lib/devres.c
78395 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
78396 void devm_iounmap(struct device *dev, void __iomem *addr)
78397 {
78398 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
78399 - (void *)addr));
78400 + (void __force *)addr));
78401 iounmap(addr);
78402 }
78403 EXPORT_SYMBOL(devm_iounmap);
78404 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
78405 {
78406 ioport_unmap(addr);
78407 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
78408 - devm_ioport_map_match, (void *)addr));
78409 + devm_ioport_map_match, (void __force *)addr));
78410 }
78411 EXPORT_SYMBOL(devm_ioport_unmap);
78412
78413 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
78414 index 5e396ac..58d5de1 100644
78415 --- a/lib/dma-debug.c
78416 +++ b/lib/dma-debug.c
78417 @@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
78418
78419 void dma_debug_add_bus(struct bus_type *bus)
78420 {
78421 - struct notifier_block *nb;
78422 + notifier_block_no_const *nb;
78423
78424 if (global_disable)
78425 return;
78426 @@ -942,7 +942,7 @@ out:
78427
78428 static void check_for_stack(struct device *dev, void *addr)
78429 {
78430 - if (object_is_on_stack(addr))
78431 + if (object_starts_on_stack(addr))
78432 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
78433 "stack [addr=%p]\n", addr);
78434 }
78435 diff --git a/lib/inflate.c b/lib/inflate.c
78436 index 013a761..c28f3fc 100644
78437 --- a/lib/inflate.c
78438 +++ b/lib/inflate.c
78439 @@ -269,7 +269,7 @@ static void free(void *where)
78440 malloc_ptr = free_mem_ptr;
78441 }
78442 #else
78443 -#define malloc(a) kmalloc(a, GFP_KERNEL)
78444 +#define malloc(a) kmalloc((a), GFP_KERNEL)
78445 #define free(a) kfree(a)
78446 #endif
78447
78448 diff --git a/lib/ioremap.c b/lib/ioremap.c
78449 index 0c9216c..863bd89 100644
78450 --- a/lib/ioremap.c
78451 +++ b/lib/ioremap.c
78452 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
78453 unsigned long next;
78454
78455 phys_addr -= addr;
78456 - pmd = pmd_alloc(&init_mm, pud, addr);
78457 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
78458 if (!pmd)
78459 return -ENOMEM;
78460 do {
78461 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
78462 unsigned long next;
78463
78464 phys_addr -= addr;
78465 - pud = pud_alloc(&init_mm, pgd, addr);
78466 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
78467 if (!pud)
78468 return -ENOMEM;
78469 do {
78470 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
78471 index bd2bea9..6b3c95e 100644
78472 --- a/lib/is_single_threaded.c
78473 +++ b/lib/is_single_threaded.c
78474 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
78475 struct task_struct *p, *t;
78476 bool ret;
78477
78478 + if (!mm)
78479 + return true;
78480 +
78481 if (atomic_read(&task->signal->live) != 1)
78482 return false;
78483
78484 diff --git a/lib/kobject.c b/lib/kobject.c
78485 index e07ee1f..998489d 100644
78486 --- a/lib/kobject.c
78487 +++ b/lib/kobject.c
78488 @@ -852,9 +852,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
78489
78490
78491 static DEFINE_SPINLOCK(kobj_ns_type_lock);
78492 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
78493 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
78494
78495 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
78496 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
78497 {
78498 enum kobj_ns_type type = ops->type;
78499 int error;
78500 diff --git a/lib/list_debug.c b/lib/list_debug.c
78501 index c24c2f7..0475b78 100644
78502 --- a/lib/list_debug.c
78503 +++ b/lib/list_debug.c
78504 @@ -11,7 +11,9 @@
78505 #include <linux/bug.h>
78506 #include <linux/kernel.h>
78507 #include <linux/rculist.h>
78508 +#include <linux/mm.h>
78509
78510 +#ifdef CONFIG_DEBUG_LIST
78511 /*
78512 * Insert a new entry between two known consecutive entries.
78513 *
78514 @@ -19,21 +21,32 @@
78515 * the prev/next entries already!
78516 */
78517
78518 -void __list_add(struct list_head *new,
78519 - struct list_head *prev,
78520 - struct list_head *next)
78521 +static bool __list_add_debug(struct list_head *new,
78522 + struct list_head *prev,
78523 + struct list_head *next)
78524 {
78525 - WARN(next->prev != prev,
78526 + if (WARN(next->prev != prev,
78527 "list_add corruption. next->prev should be "
78528 "prev (%p), but was %p. (next=%p).\n",
78529 - prev, next->prev, next);
78530 - WARN(prev->next != next,
78531 + prev, next->prev, next) ||
78532 + WARN(prev->next != next,
78533 "list_add corruption. prev->next should be "
78534 "next (%p), but was %p. (prev=%p).\n",
78535 - next, prev->next, prev);
78536 - WARN(new == prev || new == next,
78537 + next, prev->next, prev) ||
78538 + WARN(new == prev || new == next,
78539 "list_add double add: new=%p, prev=%p, next=%p.\n",
78540 - new, prev, next);
78541 + new, prev, next))
78542 + return false;
78543 + return true;
78544 +}
78545 +
78546 +void __list_add(struct list_head *new,
78547 + struct list_head *prev,
78548 + struct list_head *next)
78549 +{
78550 + if (!__list_add_debug(new, prev, next))
78551 + return;
78552 +
78553 next->prev = new;
78554 new->next = next;
78555 new->prev = prev;
78556 @@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
78557 }
78558 EXPORT_SYMBOL(__list_add);
78559
78560 -void __list_del_entry(struct list_head *entry)
78561 +static bool __list_del_entry_debug(struct list_head *entry)
78562 {
78563 struct list_head *prev, *next;
78564
78565 @@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
78566 WARN(next->prev != entry,
78567 "list_del corruption. next->prev should be %p, "
78568 "but was %p\n", entry, next->prev))
78569 + return false;
78570 + return true;
78571 +}
78572 +
78573 +void __list_del_entry(struct list_head *entry)
78574 +{
78575 + if (!__list_del_entry_debug(entry))
78576 return;
78577
78578 - __list_del(prev, next);
78579 + __list_del(entry->prev, entry->next);
78580 }
78581 EXPORT_SYMBOL(__list_del_entry);
78582
78583 @@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
78584 void __list_add_rcu(struct list_head *new,
78585 struct list_head *prev, struct list_head *next)
78586 {
78587 - WARN(next->prev != prev,
78588 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
78589 - prev, next->prev, next);
78590 - WARN(prev->next != next,
78591 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
78592 - next, prev->next, prev);
78593 + if (!__list_add_debug(new, prev, next))
78594 + return;
78595 +
78596 new->next = next;
78597 new->prev = prev;
78598 rcu_assign_pointer(list_next_rcu(prev), new);
78599 next->prev = new;
78600 }
78601 EXPORT_SYMBOL(__list_add_rcu);
78602 +#endif
78603 +
78604 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
78605 +{
78606 +#ifdef CONFIG_DEBUG_LIST
78607 + if (!__list_add_debug(new, prev, next))
78608 + return;
78609 +#endif
78610 +
78611 + pax_open_kernel();
78612 + next->prev = new;
78613 + new->next = next;
78614 + new->prev = prev;
78615 + prev->next = new;
78616 + pax_close_kernel();
78617 +}
78618 +EXPORT_SYMBOL(__pax_list_add);
78619 +
78620 +void pax_list_del(struct list_head *entry)
78621 +{
78622 +#ifdef CONFIG_DEBUG_LIST
78623 + if (!__list_del_entry_debug(entry))
78624 + return;
78625 +#endif
78626 +
78627 + pax_open_kernel();
78628 + __list_del(entry->prev, entry->next);
78629 + entry->next = LIST_POISON1;
78630 + entry->prev = LIST_POISON2;
78631 + pax_close_kernel();
78632 +}
78633 +EXPORT_SYMBOL(pax_list_del);
78634 +
78635 +void pax_list_del_init(struct list_head *entry)
78636 +{
78637 + pax_open_kernel();
78638 + __list_del(entry->prev, entry->next);
78639 + INIT_LIST_HEAD(entry);
78640 + pax_close_kernel();
78641 +}
78642 +EXPORT_SYMBOL(pax_list_del_init);
78643 +
78644 +void __pax_list_add_rcu(struct list_head *new,
78645 + struct list_head *prev, struct list_head *next)
78646 +{
78647 +#ifdef CONFIG_DEBUG_LIST
78648 + if (!__list_add_debug(new, prev, next))
78649 + return;
78650 +#endif
78651 +
78652 + pax_open_kernel();
78653 + new->next = next;
78654 + new->prev = prev;
78655 + rcu_assign_pointer(list_next_rcu(prev), new);
78656 + next->prev = new;
78657 + pax_close_kernel();
78658 +}
78659 +EXPORT_SYMBOL(__pax_list_add_rcu);
78660 +
78661 +void pax_list_del_rcu(struct list_head *entry)
78662 +{
78663 +#ifdef CONFIG_DEBUG_LIST
78664 + if (!__list_del_entry_debug(entry))
78665 + return;
78666 +#endif
78667 +
78668 + pax_open_kernel();
78669 + __list_del(entry->prev, entry->next);
78670 + entry->next = LIST_POISON1;
78671 + entry->prev = LIST_POISON2;
78672 + pax_close_kernel();
78673 +}
78674 +EXPORT_SYMBOL(pax_list_del_rcu);
78675 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
78676 index e796429..6e38f9f 100644
78677 --- a/lib/radix-tree.c
78678 +++ b/lib/radix-tree.c
78679 @@ -92,7 +92,7 @@ struct radix_tree_preload {
78680 int nr;
78681 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
78682 };
78683 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
78684 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
78685
78686 static inline void *ptr_to_indirect(void *ptr)
78687 {
78688 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
78689 index bb2b201..46abaf9 100644
78690 --- a/lib/strncpy_from_user.c
78691 +++ b/lib/strncpy_from_user.c
78692 @@ -21,7 +21,7 @@
78693 */
78694 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
78695 {
78696 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78697 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78698 long res = 0;
78699
78700 /*
78701 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
78702 index a28df52..3d55877 100644
78703 --- a/lib/strnlen_user.c
78704 +++ b/lib/strnlen_user.c
78705 @@ -26,7 +26,7 @@
78706 */
78707 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
78708 {
78709 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78710 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78711 long align, res = 0;
78712 unsigned long c;
78713
78714 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
78715 index 196b069..358f342 100644
78716 --- a/lib/swiotlb.c
78717 +++ b/lib/swiotlb.c
78718 @@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
78719
78720 void
78721 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
78722 - dma_addr_t dev_addr)
78723 + dma_addr_t dev_addr, struct dma_attrs *attrs)
78724 {
78725 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
78726
78727 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
78728 index fab33a9..3b5fe68 100644
78729 --- a/lib/vsprintf.c
78730 +++ b/lib/vsprintf.c
78731 @@ -16,6 +16,9 @@
78732 * - scnprintf and vscnprintf
78733 */
78734
78735 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78736 +#define __INCLUDED_BY_HIDESYM 1
78737 +#endif
78738 #include <stdarg.h>
78739 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
78740 #include <linux/types.h>
78741 @@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
78742 char sym[KSYM_SYMBOL_LEN];
78743 if (ext == 'B')
78744 sprint_backtrace(sym, value);
78745 - else if (ext != 'f' && ext != 's')
78746 + else if (ext != 'f' && ext != 's' && ext != 'a')
78747 sprint_symbol(sym, value);
78748 else
78749 sprint_symbol_no_offset(sym, value);
78750 @@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
78751 return number(buf, end, *(const netdev_features_t *)addr, spec);
78752 }
78753
78754 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78755 +int kptr_restrict __read_mostly = 2;
78756 +#else
78757 int kptr_restrict __read_mostly;
78758 +#endif
78759
78760 /*
78761 * Show a '%p' thing. A kernel extension is that the '%p' is followed
78762 @@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
78763 * - 'S' For symbolic direct pointers with offset
78764 * - 's' For symbolic direct pointers without offset
78765 * - 'B' For backtraced symbolic direct pointers with offset
78766 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
78767 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
78768 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
78769 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
78770 * - 'M' For a 6-byte MAC address, it prints the address in the
78771 @@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78772
78773 if (!ptr && *fmt != 'K') {
78774 /*
78775 - * Print (null) with the same width as a pointer so it makes
78776 + * Print (nil) with the same width as a pointer so it makes
78777 * tabular output look nice.
78778 */
78779 if (spec.field_width == -1)
78780 spec.field_width = default_width;
78781 - return string(buf, end, "(null)", spec);
78782 + return string(buf, end, "(nil)", spec);
78783 }
78784
78785 switch (*fmt) {
78786 @@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78787 /* Fallthrough */
78788 case 'S':
78789 case 's':
78790 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78791 + break;
78792 +#else
78793 + return symbol_string(buf, end, ptr, spec, *fmt);
78794 +#endif
78795 + case 'A':
78796 + case 'a':
78797 case 'B':
78798 return symbol_string(buf, end, ptr, spec, *fmt);
78799 case 'R':
78800 @@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78801 va_end(va);
78802 return buf;
78803 }
78804 + case 'P':
78805 + break;
78806 case 'K':
78807 /*
78808 * %pK cannot be used in IRQ context because its test
78809 @@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78810 }
78811 break;
78812 }
78813 +
78814 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78815 + /* 'P' = approved pointers to copy to userland,
78816 + as in the /proc/kallsyms case, as we make it display nothing
78817 + for non-root users, and the real contents for root users
78818 + Also ignore 'K' pointers, since we force their NULLing for non-root users
78819 + above
78820 + */
78821 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
78822 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
78823 + dump_stack();
78824 + ptr = NULL;
78825 + }
78826 +#endif
78827 +
78828 spec.flags |= SMALL;
78829 if (spec.field_width == -1) {
78830 spec.field_width = default_width;
78831 @@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
78832 typeof(type) value; \
78833 if (sizeof(type) == 8) { \
78834 args = PTR_ALIGN(args, sizeof(u32)); \
78835 - *(u32 *)&value = *(u32 *)args; \
78836 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
78837 + *(u32 *)&value = *(const u32 *)args; \
78838 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
78839 } else { \
78840 args = PTR_ALIGN(args, sizeof(type)); \
78841 - value = *(typeof(type) *)args; \
78842 + value = *(const typeof(type) *)args; \
78843 } \
78844 args += sizeof(type); \
78845 value; \
78846 @@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
78847 case FORMAT_TYPE_STR: {
78848 const char *str_arg = args;
78849 args += strlen(str_arg) + 1;
78850 - str = string(str, end, (char *)str_arg, spec);
78851 + str = string(str, end, str_arg, spec);
78852 break;
78853 }
78854
78855 diff --git a/localversion-grsec b/localversion-grsec
78856 new file mode 100644
78857 index 0000000..7cd6065
78858 --- /dev/null
78859 +++ b/localversion-grsec
78860 @@ -0,0 +1 @@
78861 +-grsec
78862 diff --git a/mm/Kconfig b/mm/Kconfig
78863 index 278e3ab..87c384d 100644
78864 --- a/mm/Kconfig
78865 +++ b/mm/Kconfig
78866 @@ -286,10 +286,10 @@ config KSM
78867 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
78868
78869 config DEFAULT_MMAP_MIN_ADDR
78870 - int "Low address space to protect from user allocation"
78871 + int "Low address space to protect from user allocation"
78872 depends on MMU
78873 - default 4096
78874 - help
78875 + default 65536
78876 + help
78877 This is the portion of low virtual memory which should be protected
78878 from userspace allocation. Keeping a user from writing to low pages
78879 can help reduce the impact of kernel NULL pointer bugs.
78880 @@ -320,7 +320,7 @@ config MEMORY_FAILURE
78881
78882 config HWPOISON_INJECT
78883 tristate "HWPoison pages injector"
78884 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
78885 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
78886 select PROC_PAGE_MONITOR
78887
78888 config NOMMU_INITIAL_TRIM_EXCESS
78889 diff --git a/mm/filemap.c b/mm/filemap.c
78890 index 83efee7..3f99381 100644
78891 --- a/mm/filemap.c
78892 +++ b/mm/filemap.c
78893 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
78894 struct address_space *mapping = file->f_mapping;
78895
78896 if (!mapping->a_ops->readpage)
78897 - return -ENOEXEC;
78898 + return -ENODEV;
78899 file_accessed(file);
78900 vma->vm_ops = &generic_file_vm_ops;
78901 return 0;
78902 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
78903 *pos = i_size_read(inode);
78904
78905 if (limit != RLIM_INFINITY) {
78906 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
78907 if (*pos >= limit) {
78908 send_sig(SIGXFSZ, current, 0);
78909 return -EFBIG;
78910 diff --git a/mm/fremap.c b/mm/fremap.c
78911 index a0aaf0e..20325c3 100644
78912 --- a/mm/fremap.c
78913 +++ b/mm/fremap.c
78914 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
78915 retry:
78916 vma = find_vma(mm, start);
78917
78918 +#ifdef CONFIG_PAX_SEGMEXEC
78919 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
78920 + goto out;
78921 +#endif
78922 +
78923 /*
78924 * Make sure the vma is shared, that it supports prefaulting,
78925 * and that the remapped range is valid and fully within
78926 diff --git a/mm/highmem.c b/mm/highmem.c
78927 index b32b70c..e512eb0 100644
78928 --- a/mm/highmem.c
78929 +++ b/mm/highmem.c
78930 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
78931 * So no dangers, even with speculative execution.
78932 */
78933 page = pte_page(pkmap_page_table[i]);
78934 + pax_open_kernel();
78935 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
78936 -
78937 + pax_close_kernel();
78938 set_page_address(page, NULL);
78939 need_flush = 1;
78940 }
78941 @@ -198,9 +199,11 @@ start:
78942 }
78943 }
78944 vaddr = PKMAP_ADDR(last_pkmap_nr);
78945 +
78946 + pax_open_kernel();
78947 set_pte_at(&init_mm, vaddr,
78948 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
78949 -
78950 + pax_close_kernel();
78951 pkmap_count[last_pkmap_nr] = 1;
78952 set_page_address(page, (void *)vaddr);
78953
78954 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
78955 index 546db81..34830af 100644
78956 --- a/mm/hugetlb.c
78957 +++ b/mm/hugetlb.c
78958 @@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
78959 struct hstate *h = &default_hstate;
78960 unsigned long tmp;
78961 int ret;
78962 + ctl_table_no_const hugetlb_table;
78963
78964 tmp = h->max_huge_pages;
78965
78966 if (write && h->order >= MAX_ORDER)
78967 return -EINVAL;
78968
78969 - table->data = &tmp;
78970 - table->maxlen = sizeof(unsigned long);
78971 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
78972 + hugetlb_table = *table;
78973 + hugetlb_table.data = &tmp;
78974 + hugetlb_table.maxlen = sizeof(unsigned long);
78975 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
78976 if (ret)
78977 goto out;
78978
78979 @@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
78980 struct hstate *h = &default_hstate;
78981 unsigned long tmp;
78982 int ret;
78983 + ctl_table_no_const hugetlb_table;
78984
78985 tmp = h->nr_overcommit_huge_pages;
78986
78987 if (write && h->order >= MAX_ORDER)
78988 return -EINVAL;
78989
78990 - table->data = &tmp;
78991 - table->maxlen = sizeof(unsigned long);
78992 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
78993 + hugetlb_table = *table;
78994 + hugetlb_table.data = &tmp;
78995 + hugetlb_table.maxlen = sizeof(unsigned long);
78996 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
78997 if (ret)
78998 goto out;
78999
79000 @@ -2511,6 +2515,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
79001 return 1;
79002 }
79003
79004 +#ifdef CONFIG_PAX_SEGMEXEC
79005 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
79006 +{
79007 + struct mm_struct *mm = vma->vm_mm;
79008 + struct vm_area_struct *vma_m;
79009 + unsigned long address_m;
79010 + pte_t *ptep_m;
79011 +
79012 + vma_m = pax_find_mirror_vma(vma);
79013 + if (!vma_m)
79014 + return;
79015 +
79016 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79017 + address_m = address + SEGMEXEC_TASK_SIZE;
79018 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
79019 + get_page(page_m);
79020 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
79021 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
79022 +}
79023 +#endif
79024 +
79025 /*
79026 * Hugetlb_cow() should be called with page lock of the original hugepage held.
79027 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
79028 @@ -2629,6 +2654,11 @@ retry_avoidcopy:
79029 make_huge_pte(vma, new_page, 1));
79030 page_remove_rmap(old_page);
79031 hugepage_add_new_anon_rmap(new_page, vma, address);
79032 +
79033 +#ifdef CONFIG_PAX_SEGMEXEC
79034 + pax_mirror_huge_pte(vma, address, new_page);
79035 +#endif
79036 +
79037 /* Make the old page be freed below */
79038 new_page = old_page;
79039 }
79040 @@ -2788,6 +2818,10 @@ retry:
79041 && (vma->vm_flags & VM_SHARED)));
79042 set_huge_pte_at(mm, address, ptep, new_pte);
79043
79044 +#ifdef CONFIG_PAX_SEGMEXEC
79045 + pax_mirror_huge_pte(vma, address, page);
79046 +#endif
79047 +
79048 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
79049 /* Optimization, do the COW without a second fault */
79050 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
79051 @@ -2817,6 +2851,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79052 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
79053 struct hstate *h = hstate_vma(vma);
79054
79055 +#ifdef CONFIG_PAX_SEGMEXEC
79056 + struct vm_area_struct *vma_m;
79057 +#endif
79058 +
79059 address &= huge_page_mask(h);
79060
79061 ptep = huge_pte_offset(mm, address);
79062 @@ -2830,6 +2868,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79063 VM_FAULT_SET_HINDEX(hstate_index(h));
79064 }
79065
79066 +#ifdef CONFIG_PAX_SEGMEXEC
79067 + vma_m = pax_find_mirror_vma(vma);
79068 + if (vma_m) {
79069 + unsigned long address_m;
79070 +
79071 + if (vma->vm_start > vma_m->vm_start) {
79072 + address_m = address;
79073 + address -= SEGMEXEC_TASK_SIZE;
79074 + vma = vma_m;
79075 + h = hstate_vma(vma);
79076 + } else
79077 + address_m = address + SEGMEXEC_TASK_SIZE;
79078 +
79079 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
79080 + return VM_FAULT_OOM;
79081 + address_m &= HPAGE_MASK;
79082 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
79083 + }
79084 +#endif
79085 +
79086 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
79087 if (!ptep)
79088 return VM_FAULT_OOM;
79089 diff --git a/mm/internal.h b/mm/internal.h
79090 index 9ba2110..eaf0674 100644
79091 --- a/mm/internal.h
79092 +++ b/mm/internal.h
79093 @@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
79094 * in mm/page_alloc.c
79095 */
79096 extern void __free_pages_bootmem(struct page *page, unsigned int order);
79097 +extern void free_compound_page(struct page *page);
79098 extern void prep_compound_page(struct page *page, unsigned long order);
79099 #ifdef CONFIG_MEMORY_FAILURE
79100 extern bool is_free_buddy_page(struct page *page);
79101 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
79102 index 752a705..6c3102e 100644
79103 --- a/mm/kmemleak.c
79104 +++ b/mm/kmemleak.c
79105 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
79106
79107 for (i = 0; i < object->trace_len; i++) {
79108 void *ptr = (void *)object->trace[i];
79109 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
79110 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
79111 }
79112 }
79113
79114 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
79115 return -ENOMEM;
79116 }
79117
79118 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
79119 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
79120 &kmemleak_fops);
79121 if (!dentry)
79122 pr_warning("Failed to create the debugfs kmemleak file\n");
79123 diff --git a/mm/maccess.c b/mm/maccess.c
79124 index d53adf9..03a24bf 100644
79125 --- a/mm/maccess.c
79126 +++ b/mm/maccess.c
79127 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
79128 set_fs(KERNEL_DS);
79129 pagefault_disable();
79130 ret = __copy_from_user_inatomic(dst,
79131 - (__force const void __user *)src, size);
79132 + (const void __force_user *)src, size);
79133 pagefault_enable();
79134 set_fs(old_fs);
79135
79136 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
79137
79138 set_fs(KERNEL_DS);
79139 pagefault_disable();
79140 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
79141 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
79142 pagefault_enable();
79143 set_fs(old_fs);
79144
79145 diff --git a/mm/madvise.c b/mm/madvise.c
79146 index 03dfa5c..b032917 100644
79147 --- a/mm/madvise.c
79148 +++ b/mm/madvise.c
79149 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
79150 pgoff_t pgoff;
79151 unsigned long new_flags = vma->vm_flags;
79152
79153 +#ifdef CONFIG_PAX_SEGMEXEC
79154 + struct vm_area_struct *vma_m;
79155 +#endif
79156 +
79157 switch (behavior) {
79158 case MADV_NORMAL:
79159 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
79160 @@ -123,6 +127,13 @@ success:
79161 /*
79162 * vm_flags is protected by the mmap_sem held in write mode.
79163 */
79164 +
79165 +#ifdef CONFIG_PAX_SEGMEXEC
79166 + vma_m = pax_find_mirror_vma(vma);
79167 + if (vma_m)
79168 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
79169 +#endif
79170 +
79171 vma->vm_flags = new_flags;
79172
79173 out:
79174 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
79175 struct vm_area_struct ** prev,
79176 unsigned long start, unsigned long end)
79177 {
79178 +
79179 +#ifdef CONFIG_PAX_SEGMEXEC
79180 + struct vm_area_struct *vma_m;
79181 +#endif
79182 +
79183 *prev = vma;
79184 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
79185 return -EINVAL;
79186 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
79187 zap_page_range(vma, start, end - start, &details);
79188 } else
79189 zap_page_range(vma, start, end - start, NULL);
79190 +
79191 +#ifdef CONFIG_PAX_SEGMEXEC
79192 + vma_m = pax_find_mirror_vma(vma);
79193 + if (vma_m) {
79194 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
79195 + struct zap_details details = {
79196 + .nonlinear_vma = vma_m,
79197 + .last_index = ULONG_MAX,
79198 + };
79199 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
79200 + } else
79201 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
79202 + }
79203 +#endif
79204 +
79205 return 0;
79206 }
79207
79208 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
79209 if (end < start)
79210 goto out;
79211
79212 +#ifdef CONFIG_PAX_SEGMEXEC
79213 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
79214 + if (end > SEGMEXEC_TASK_SIZE)
79215 + goto out;
79216 + } else
79217 +#endif
79218 +
79219 + if (end > TASK_SIZE)
79220 + goto out;
79221 +
79222 error = 0;
79223 if (end == start)
79224 goto out;
79225 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
79226 index c6e4dd3..1f41988 100644
79227 --- a/mm/memory-failure.c
79228 +++ b/mm/memory-failure.c
79229 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
79230
79231 int sysctl_memory_failure_recovery __read_mostly = 1;
79232
79233 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
79234 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
79235
79236 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
79237
79238 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
79239 pfn, t->comm, t->pid);
79240 si.si_signo = SIGBUS;
79241 si.si_errno = 0;
79242 - si.si_addr = (void *)addr;
79243 + si.si_addr = (void __user *)addr;
79244 #ifdef __ARCH_SI_TRAPNO
79245 si.si_trapno = trapno;
79246 #endif
79247 @@ -760,7 +760,7 @@ static struct page_state {
79248 unsigned long res;
79249 char *msg;
79250 int (*action)(struct page *p, unsigned long pfn);
79251 -} error_states[] = {
79252 +} __do_const error_states[] = {
79253 { reserved, reserved, "reserved kernel", me_kernel },
79254 /*
79255 * free pages are specially detected outside this table:
79256 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79257 }
79258
79259 nr_pages = 1 << compound_trans_order(hpage);
79260 - atomic_long_add(nr_pages, &mce_bad_pages);
79261 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
79262
79263 /*
79264 * We need/can do nothing about count=0 pages.
79265 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79266 if (!PageHWPoison(hpage)
79267 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
79268 || (p != hpage && TestSetPageHWPoison(hpage))) {
79269 - atomic_long_sub(nr_pages, &mce_bad_pages);
79270 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79271 return 0;
79272 }
79273 set_page_hwpoison_huge_page(hpage);
79274 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79275 }
79276 if (hwpoison_filter(p)) {
79277 if (TestClearPageHWPoison(p))
79278 - atomic_long_sub(nr_pages, &mce_bad_pages);
79279 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79280 unlock_page(hpage);
79281 put_page(hpage);
79282 return 0;
79283 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
79284 return 0;
79285 }
79286 if (TestClearPageHWPoison(p))
79287 - atomic_long_sub(nr_pages, &mce_bad_pages);
79288 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79289 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
79290 return 0;
79291 }
79292 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
79293 */
79294 if (TestClearPageHWPoison(page)) {
79295 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
79296 - atomic_long_sub(nr_pages, &mce_bad_pages);
79297 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79298 freeit = 1;
79299 if (PageHuge(page))
79300 clear_page_hwpoison_huge_page(page);
79301 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
79302 }
79303 done:
79304 if (!PageHWPoison(hpage))
79305 - atomic_long_add(1 << compound_trans_order(hpage),
79306 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
79307 &mce_bad_pages);
79308 set_page_hwpoison_huge_page(hpage);
79309 dequeue_hwpoisoned_huge_page(hpage);
79310 @@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
79311 return ret;
79312
79313 done:
79314 - atomic_long_add(1, &mce_bad_pages);
79315 + atomic_long_add_unchecked(1, &mce_bad_pages);
79316 SetPageHWPoison(page);
79317 /* keep elevated page count for bad page */
79318 return ret;
79319 diff --git a/mm/memory.c b/mm/memory.c
79320 index bb1369f..efb96b5 100644
79321 --- a/mm/memory.c
79322 +++ b/mm/memory.c
79323 @@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
79324 free_pte_range(tlb, pmd, addr);
79325 } while (pmd++, addr = next, addr != end);
79326
79327 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
79328 start &= PUD_MASK;
79329 if (start < floor)
79330 return;
79331 @@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
79332 pmd = pmd_offset(pud, start);
79333 pud_clear(pud);
79334 pmd_free_tlb(tlb, pmd, start);
79335 +#endif
79336 +
79337 }
79338
79339 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79340 @@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79341 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
79342 } while (pud++, addr = next, addr != end);
79343
79344 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
79345 start &= PGDIR_MASK;
79346 if (start < floor)
79347 return;
79348 @@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79349 pud = pud_offset(pgd, start);
79350 pgd_clear(pgd);
79351 pud_free_tlb(tlb, pud, start);
79352 +#endif
79353 +
79354 }
79355
79356 /*
79357 @@ -1618,12 +1624,6 @@ no_page_table:
79358 return page;
79359 }
79360
79361 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
79362 -{
79363 - return stack_guard_page_start(vma, addr) ||
79364 - stack_guard_page_end(vma, addr+PAGE_SIZE);
79365 -}
79366 -
79367 /**
79368 * __get_user_pages() - pin user pages in memory
79369 * @tsk: task_struct of target task
79370 @@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79371
79372 i = 0;
79373
79374 - do {
79375 + while (nr_pages) {
79376 struct vm_area_struct *vma;
79377
79378 - vma = find_extend_vma(mm, start);
79379 + vma = find_vma(mm, start);
79380 if (!vma && in_gate_area(mm, start)) {
79381 unsigned long pg = start & PAGE_MASK;
79382 pgd_t *pgd;
79383 @@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79384 goto next_page;
79385 }
79386
79387 - if (!vma ||
79388 + if (!vma || start < vma->vm_start ||
79389 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
79390 !(vm_flags & vma->vm_flags))
79391 return i ? : -EFAULT;
79392 @@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79393 int ret;
79394 unsigned int fault_flags = 0;
79395
79396 - /* For mlock, just skip the stack guard page. */
79397 - if (foll_flags & FOLL_MLOCK) {
79398 - if (stack_guard_page(vma, start))
79399 - goto next_page;
79400 - }
79401 if (foll_flags & FOLL_WRITE)
79402 fault_flags |= FAULT_FLAG_WRITE;
79403 if (nonblocking)
79404 @@ -1865,7 +1860,7 @@ next_page:
79405 start += PAGE_SIZE;
79406 nr_pages--;
79407 } while (nr_pages && start < vma->vm_end);
79408 - } while (nr_pages);
79409 + }
79410 return i;
79411 }
79412 EXPORT_SYMBOL(__get_user_pages);
79413 @@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
79414 page_add_file_rmap(page);
79415 set_pte_at(mm, addr, pte, mk_pte(page, prot));
79416
79417 +#ifdef CONFIG_PAX_SEGMEXEC
79418 + pax_mirror_file_pte(vma, addr, page, ptl);
79419 +#endif
79420 +
79421 retval = 0;
79422 pte_unmap_unlock(pte, ptl);
79423 return retval;
79424 @@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
79425 if (!page_count(page))
79426 return -EINVAL;
79427 if (!(vma->vm_flags & VM_MIXEDMAP)) {
79428 +
79429 +#ifdef CONFIG_PAX_SEGMEXEC
79430 + struct vm_area_struct *vma_m;
79431 +#endif
79432 +
79433 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
79434 BUG_ON(vma->vm_flags & VM_PFNMAP);
79435 vma->vm_flags |= VM_MIXEDMAP;
79436 +
79437 +#ifdef CONFIG_PAX_SEGMEXEC
79438 + vma_m = pax_find_mirror_vma(vma);
79439 + if (vma_m)
79440 + vma_m->vm_flags |= VM_MIXEDMAP;
79441 +#endif
79442 +
79443 }
79444 return insert_page(vma, addr, page, vma->vm_page_prot);
79445 }
79446 @@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
79447 unsigned long pfn)
79448 {
79449 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
79450 + BUG_ON(vma->vm_mirror);
79451
79452 if (addr < vma->vm_start || addr >= vma->vm_end)
79453 return -EFAULT;
79454 @@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
79455
79456 BUG_ON(pud_huge(*pud));
79457
79458 - pmd = pmd_alloc(mm, pud, addr);
79459 + pmd = (mm == &init_mm) ?
79460 + pmd_alloc_kernel(mm, pud, addr) :
79461 + pmd_alloc(mm, pud, addr);
79462 if (!pmd)
79463 return -ENOMEM;
79464 do {
79465 @@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
79466 unsigned long next;
79467 int err;
79468
79469 - pud = pud_alloc(mm, pgd, addr);
79470 + pud = (mm == &init_mm) ?
79471 + pud_alloc_kernel(mm, pgd, addr) :
79472 + pud_alloc(mm, pgd, addr);
79473 if (!pud)
79474 return -ENOMEM;
79475 do {
79476 @@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
79477 copy_user_highpage(dst, src, va, vma);
79478 }
79479
79480 +#ifdef CONFIG_PAX_SEGMEXEC
79481 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
79482 +{
79483 + struct mm_struct *mm = vma->vm_mm;
79484 + spinlock_t *ptl;
79485 + pte_t *pte, entry;
79486 +
79487 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
79488 + entry = *pte;
79489 + if (!pte_present(entry)) {
79490 + if (!pte_none(entry)) {
79491 + BUG_ON(pte_file(entry));
79492 + free_swap_and_cache(pte_to_swp_entry(entry));
79493 + pte_clear_not_present_full(mm, address, pte, 0);
79494 + }
79495 + } else {
79496 + struct page *page;
79497 +
79498 + flush_cache_page(vma, address, pte_pfn(entry));
79499 + entry = ptep_clear_flush(vma, address, pte);
79500 + BUG_ON(pte_dirty(entry));
79501 + page = vm_normal_page(vma, address, entry);
79502 + if (page) {
79503 + update_hiwater_rss(mm);
79504 + if (PageAnon(page))
79505 + dec_mm_counter_fast(mm, MM_ANONPAGES);
79506 + else
79507 + dec_mm_counter_fast(mm, MM_FILEPAGES);
79508 + page_remove_rmap(page);
79509 + page_cache_release(page);
79510 + }
79511 + }
79512 + pte_unmap_unlock(pte, ptl);
79513 +}
79514 +
79515 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
79516 + *
79517 + * the ptl of the lower mapped page is held on entry and is not released on exit
79518 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
79519 + */
79520 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
79521 +{
79522 + struct mm_struct *mm = vma->vm_mm;
79523 + unsigned long address_m;
79524 + spinlock_t *ptl_m;
79525 + struct vm_area_struct *vma_m;
79526 + pmd_t *pmd_m;
79527 + pte_t *pte_m, entry_m;
79528 +
79529 + BUG_ON(!page_m || !PageAnon(page_m));
79530 +
79531 + vma_m = pax_find_mirror_vma(vma);
79532 + if (!vma_m)
79533 + return;
79534 +
79535 + BUG_ON(!PageLocked(page_m));
79536 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79537 + address_m = address + SEGMEXEC_TASK_SIZE;
79538 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79539 + pte_m = pte_offset_map(pmd_m, address_m);
79540 + ptl_m = pte_lockptr(mm, pmd_m);
79541 + if (ptl != ptl_m) {
79542 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79543 + if (!pte_none(*pte_m))
79544 + goto out;
79545 + }
79546 +
79547 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
79548 + page_cache_get(page_m);
79549 + page_add_anon_rmap(page_m, vma_m, address_m);
79550 + inc_mm_counter_fast(mm, MM_ANONPAGES);
79551 + set_pte_at(mm, address_m, pte_m, entry_m);
79552 + update_mmu_cache(vma_m, address_m, entry_m);
79553 +out:
79554 + if (ptl != ptl_m)
79555 + spin_unlock(ptl_m);
79556 + pte_unmap(pte_m);
79557 + unlock_page(page_m);
79558 +}
79559 +
79560 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
79561 +{
79562 + struct mm_struct *mm = vma->vm_mm;
79563 + unsigned long address_m;
79564 + spinlock_t *ptl_m;
79565 + struct vm_area_struct *vma_m;
79566 + pmd_t *pmd_m;
79567 + pte_t *pte_m, entry_m;
79568 +
79569 + BUG_ON(!page_m || PageAnon(page_m));
79570 +
79571 + vma_m = pax_find_mirror_vma(vma);
79572 + if (!vma_m)
79573 + return;
79574 +
79575 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79576 + address_m = address + SEGMEXEC_TASK_SIZE;
79577 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79578 + pte_m = pte_offset_map(pmd_m, address_m);
79579 + ptl_m = pte_lockptr(mm, pmd_m);
79580 + if (ptl != ptl_m) {
79581 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79582 + if (!pte_none(*pte_m))
79583 + goto out;
79584 + }
79585 +
79586 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
79587 + page_cache_get(page_m);
79588 + page_add_file_rmap(page_m);
79589 + inc_mm_counter_fast(mm, MM_FILEPAGES);
79590 + set_pte_at(mm, address_m, pte_m, entry_m);
79591 + update_mmu_cache(vma_m, address_m, entry_m);
79592 +out:
79593 + if (ptl != ptl_m)
79594 + spin_unlock(ptl_m);
79595 + pte_unmap(pte_m);
79596 +}
79597 +
79598 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
79599 +{
79600 + struct mm_struct *mm = vma->vm_mm;
79601 + unsigned long address_m;
79602 + spinlock_t *ptl_m;
79603 + struct vm_area_struct *vma_m;
79604 + pmd_t *pmd_m;
79605 + pte_t *pte_m, entry_m;
79606 +
79607 + vma_m = pax_find_mirror_vma(vma);
79608 + if (!vma_m)
79609 + return;
79610 +
79611 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79612 + address_m = address + SEGMEXEC_TASK_SIZE;
79613 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79614 + pte_m = pte_offset_map(pmd_m, address_m);
79615 + ptl_m = pte_lockptr(mm, pmd_m);
79616 + if (ptl != ptl_m) {
79617 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79618 + if (!pte_none(*pte_m))
79619 + goto out;
79620 + }
79621 +
79622 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
79623 + set_pte_at(mm, address_m, pte_m, entry_m);
79624 +out:
79625 + if (ptl != ptl_m)
79626 + spin_unlock(ptl_m);
79627 + pte_unmap(pte_m);
79628 +}
79629 +
79630 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
79631 +{
79632 + struct page *page_m;
79633 + pte_t entry;
79634 +
79635 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
79636 + goto out;
79637 +
79638 + entry = *pte;
79639 + page_m = vm_normal_page(vma, address, entry);
79640 + if (!page_m)
79641 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
79642 + else if (PageAnon(page_m)) {
79643 + if (pax_find_mirror_vma(vma)) {
79644 + pte_unmap_unlock(pte, ptl);
79645 + lock_page(page_m);
79646 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
79647 + if (pte_same(entry, *pte))
79648 + pax_mirror_anon_pte(vma, address, page_m, ptl);
79649 + else
79650 + unlock_page(page_m);
79651 + }
79652 + } else
79653 + pax_mirror_file_pte(vma, address, page_m, ptl);
79654 +
79655 +out:
79656 + pte_unmap_unlock(pte, ptl);
79657 +}
79658 +#endif
79659 +
79660 /*
79661 * This routine handles present pages, when users try to write
79662 * to a shared page. It is done by copying the page to a new address
79663 @@ -2725,6 +2921,12 @@ gotten:
79664 */
79665 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
79666 if (likely(pte_same(*page_table, orig_pte))) {
79667 +
79668 +#ifdef CONFIG_PAX_SEGMEXEC
79669 + if (pax_find_mirror_vma(vma))
79670 + BUG_ON(!trylock_page(new_page));
79671 +#endif
79672 +
79673 if (old_page) {
79674 if (!PageAnon(old_page)) {
79675 dec_mm_counter_fast(mm, MM_FILEPAGES);
79676 @@ -2776,6 +2978,10 @@ gotten:
79677 page_remove_rmap(old_page);
79678 }
79679
79680 +#ifdef CONFIG_PAX_SEGMEXEC
79681 + pax_mirror_anon_pte(vma, address, new_page, ptl);
79682 +#endif
79683 +
79684 /* Free the old page.. */
79685 new_page = old_page;
79686 ret |= VM_FAULT_WRITE;
79687 @@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
79688 swap_free(entry);
79689 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
79690 try_to_free_swap(page);
79691 +
79692 +#ifdef CONFIG_PAX_SEGMEXEC
79693 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
79694 +#endif
79695 +
79696 unlock_page(page);
79697 if (swapcache) {
79698 /*
79699 @@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
79700
79701 /* No need to invalidate - it was non-present before */
79702 update_mmu_cache(vma, address, page_table);
79703 +
79704 +#ifdef CONFIG_PAX_SEGMEXEC
79705 + pax_mirror_anon_pte(vma, address, page, ptl);
79706 +#endif
79707 +
79708 unlock:
79709 pte_unmap_unlock(page_table, ptl);
79710 out:
79711 @@ -3093,40 +3309,6 @@ out_release:
79712 }
79713
79714 /*
79715 - * This is like a special single-page "expand_{down|up}wards()",
79716 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
79717 - * doesn't hit another vma.
79718 - */
79719 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
79720 -{
79721 - address &= PAGE_MASK;
79722 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
79723 - struct vm_area_struct *prev = vma->vm_prev;
79724 -
79725 - /*
79726 - * Is there a mapping abutting this one below?
79727 - *
79728 - * That's only ok if it's the same stack mapping
79729 - * that has gotten split..
79730 - */
79731 - if (prev && prev->vm_end == address)
79732 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
79733 -
79734 - expand_downwards(vma, address - PAGE_SIZE);
79735 - }
79736 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
79737 - struct vm_area_struct *next = vma->vm_next;
79738 -
79739 - /* As VM_GROWSDOWN but s/below/above/ */
79740 - if (next && next->vm_start == address + PAGE_SIZE)
79741 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
79742 -
79743 - expand_upwards(vma, address + PAGE_SIZE);
79744 - }
79745 - return 0;
79746 -}
79747 -
79748 -/*
79749 * We enter with non-exclusive mmap_sem (to exclude vma changes,
79750 * but allow concurrent faults), and pte mapped but not yet locked.
79751 * We return with mmap_sem still held, but pte unmapped and unlocked.
79752 @@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
79753 unsigned long address, pte_t *page_table, pmd_t *pmd,
79754 unsigned int flags)
79755 {
79756 - struct page *page;
79757 + struct page *page = NULL;
79758 spinlock_t *ptl;
79759 pte_t entry;
79760
79761 - pte_unmap(page_table);
79762 -
79763 - /* Check if we need to add a guard page to the stack */
79764 - if (check_stack_guard_page(vma, address) < 0)
79765 - return VM_FAULT_SIGBUS;
79766 -
79767 - /* Use the zero-page for reads */
79768 if (!(flags & FAULT_FLAG_WRITE)) {
79769 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
79770 vma->vm_page_prot));
79771 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
79772 + ptl = pte_lockptr(mm, pmd);
79773 + spin_lock(ptl);
79774 if (!pte_none(*page_table))
79775 goto unlock;
79776 goto setpte;
79777 }
79778
79779 /* Allocate our own private page. */
79780 + pte_unmap(page_table);
79781 +
79782 if (unlikely(anon_vma_prepare(vma)))
79783 goto oom;
79784 page = alloc_zeroed_user_highpage_movable(vma, address);
79785 @@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
79786 if (!pte_none(*page_table))
79787 goto release;
79788
79789 +#ifdef CONFIG_PAX_SEGMEXEC
79790 + if (pax_find_mirror_vma(vma))
79791 + BUG_ON(!trylock_page(page));
79792 +#endif
79793 +
79794 inc_mm_counter_fast(mm, MM_ANONPAGES);
79795 page_add_new_anon_rmap(page, vma, address);
79796 setpte:
79797 @@ -3181,6 +3364,12 @@ setpte:
79798
79799 /* No need to invalidate - it was non-present before */
79800 update_mmu_cache(vma, address, page_table);
79801 +
79802 +#ifdef CONFIG_PAX_SEGMEXEC
79803 + if (page)
79804 + pax_mirror_anon_pte(vma, address, page, ptl);
79805 +#endif
79806 +
79807 unlock:
79808 pte_unmap_unlock(page_table, ptl);
79809 return 0;
79810 @@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79811 */
79812 /* Only go through if we didn't race with anybody else... */
79813 if (likely(pte_same(*page_table, orig_pte))) {
79814 +
79815 +#ifdef CONFIG_PAX_SEGMEXEC
79816 + if (anon && pax_find_mirror_vma(vma))
79817 + BUG_ON(!trylock_page(page));
79818 +#endif
79819 +
79820 flush_icache_page(vma, page);
79821 entry = mk_pte(page, vma->vm_page_prot);
79822 if (flags & FAULT_FLAG_WRITE)
79823 @@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79824
79825 /* no need to invalidate: a not-present page won't be cached */
79826 update_mmu_cache(vma, address, page_table);
79827 +
79828 +#ifdef CONFIG_PAX_SEGMEXEC
79829 + if (anon)
79830 + pax_mirror_anon_pte(vma, address, page, ptl);
79831 + else
79832 + pax_mirror_file_pte(vma, address, page, ptl);
79833 +#endif
79834 +
79835 } else {
79836 if (cow_page)
79837 mem_cgroup_uncharge_page(cow_page);
79838 @@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
79839 if (flags & FAULT_FLAG_WRITE)
79840 flush_tlb_fix_spurious_fault(vma, address);
79841 }
79842 +
79843 +#ifdef CONFIG_PAX_SEGMEXEC
79844 + pax_mirror_pte(vma, address, pte, pmd, ptl);
79845 + return 0;
79846 +#endif
79847 +
79848 unlock:
79849 pte_unmap_unlock(pte, ptl);
79850 return 0;
79851 @@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79852 pmd_t *pmd;
79853 pte_t *pte;
79854
79855 +#ifdef CONFIG_PAX_SEGMEXEC
79856 + struct vm_area_struct *vma_m;
79857 +#endif
79858 +
79859 __set_current_state(TASK_RUNNING);
79860
79861 count_vm_event(PGFAULT);
79862 @@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79863 if (unlikely(is_vm_hugetlb_page(vma)))
79864 return hugetlb_fault(mm, vma, address, flags);
79865
79866 +#ifdef CONFIG_PAX_SEGMEXEC
79867 + vma_m = pax_find_mirror_vma(vma);
79868 + if (vma_m) {
79869 + unsigned long address_m;
79870 + pgd_t *pgd_m;
79871 + pud_t *pud_m;
79872 + pmd_t *pmd_m;
79873 +
79874 + if (vma->vm_start > vma_m->vm_start) {
79875 + address_m = address;
79876 + address -= SEGMEXEC_TASK_SIZE;
79877 + vma = vma_m;
79878 + } else
79879 + address_m = address + SEGMEXEC_TASK_SIZE;
79880 +
79881 + pgd_m = pgd_offset(mm, address_m);
79882 + pud_m = pud_alloc(mm, pgd_m, address_m);
79883 + if (!pud_m)
79884 + return VM_FAULT_OOM;
79885 + pmd_m = pmd_alloc(mm, pud_m, address_m);
79886 + if (!pmd_m)
79887 + return VM_FAULT_OOM;
79888 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
79889 + return VM_FAULT_OOM;
79890 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
79891 + }
79892 +#endif
79893 +
79894 retry:
79895 pgd = pgd_offset(mm, address);
79896 pud = pud_alloc(mm, pgd, address);
79897 @@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79898 spin_unlock(&mm->page_table_lock);
79899 return 0;
79900 }
79901 +
79902 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79903 +{
79904 + pud_t *new = pud_alloc_one(mm, address);
79905 + if (!new)
79906 + return -ENOMEM;
79907 +
79908 + smp_wmb(); /* See comment in __pte_alloc */
79909 +
79910 + spin_lock(&mm->page_table_lock);
79911 + if (pgd_present(*pgd)) /* Another has populated it */
79912 + pud_free(mm, new);
79913 + else
79914 + pgd_populate_kernel(mm, pgd, new);
79915 + spin_unlock(&mm->page_table_lock);
79916 + return 0;
79917 +}
79918 #endif /* __PAGETABLE_PUD_FOLDED */
79919
79920 #ifndef __PAGETABLE_PMD_FOLDED
79921 @@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
79922 spin_unlock(&mm->page_table_lock);
79923 return 0;
79924 }
79925 +
79926 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
79927 +{
79928 + pmd_t *new = pmd_alloc_one(mm, address);
79929 + if (!new)
79930 + return -ENOMEM;
79931 +
79932 + smp_wmb(); /* See comment in __pte_alloc */
79933 +
79934 + spin_lock(&mm->page_table_lock);
79935 +#ifndef __ARCH_HAS_4LEVEL_HACK
79936 + if (pud_present(*pud)) /* Another has populated it */
79937 + pmd_free(mm, new);
79938 + else
79939 + pud_populate_kernel(mm, pud, new);
79940 +#else
79941 + if (pgd_present(*pud)) /* Another has populated it */
79942 + pmd_free(mm, new);
79943 + else
79944 + pgd_populate_kernel(mm, pud, new);
79945 +#endif /* __ARCH_HAS_4LEVEL_HACK */
79946 + spin_unlock(&mm->page_table_lock);
79947 + return 0;
79948 +}
79949 #endif /* __PAGETABLE_PMD_FOLDED */
79950
79951 int make_pages_present(unsigned long addr, unsigned long end)
79952 @@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
79953 gate_vma.vm_start = FIXADDR_USER_START;
79954 gate_vma.vm_end = FIXADDR_USER_END;
79955 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
79956 - gate_vma.vm_page_prot = __P101;
79957 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
79958
79959 return 0;
79960 }
79961 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
79962 index 3df6d12..a11056a 100644
79963 --- a/mm/mempolicy.c
79964 +++ b/mm/mempolicy.c
79965 @@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
79966 unsigned long vmstart;
79967 unsigned long vmend;
79968
79969 +#ifdef CONFIG_PAX_SEGMEXEC
79970 + struct vm_area_struct *vma_m;
79971 +#endif
79972 +
79973 vma = find_vma(mm, start);
79974 if (!vma || vma->vm_start > start)
79975 return -EFAULT;
79976 @@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
79977 if (err)
79978 goto out;
79979 }
79980 +
79981 err = vma_replace_policy(vma, new_pol);
79982 if (err)
79983 goto out;
79984 +
79985 +#ifdef CONFIG_PAX_SEGMEXEC
79986 + vma_m = pax_find_mirror_vma(vma);
79987 + if (vma_m) {
79988 + err = vma_replace_policy(vma_m, new_pol);
79989 + if (err)
79990 + goto out;
79991 + }
79992 +#endif
79993 +
79994 }
79995
79996 out:
79997 @@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
79998
79999 if (end < start)
80000 return -EINVAL;
80001 +
80002 +#ifdef CONFIG_PAX_SEGMEXEC
80003 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
80004 + if (end > SEGMEXEC_TASK_SIZE)
80005 + return -EINVAL;
80006 + } else
80007 +#endif
80008 +
80009 + if (end > TASK_SIZE)
80010 + return -EINVAL;
80011 +
80012 if (end == start)
80013 return 0;
80014
80015 @@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80016 */
80017 tcred = __task_cred(task);
80018 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80019 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80020 - !capable(CAP_SYS_NICE)) {
80021 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80022 rcu_read_unlock();
80023 err = -EPERM;
80024 goto out_put;
80025 @@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80026 goto out;
80027 }
80028
80029 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80030 + if (mm != current->mm &&
80031 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
80032 + mmput(mm);
80033 + err = -EPERM;
80034 + goto out;
80035 + }
80036 +#endif
80037 +
80038 err = do_migrate_pages(mm, old, new,
80039 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
80040
80041 diff --git a/mm/migrate.c b/mm/migrate.c
80042 index 2fd8b4a..d70358f 100644
80043 --- a/mm/migrate.c
80044 +++ b/mm/migrate.c
80045 @@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
80046 */
80047 tcred = __task_cred(task);
80048 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80049 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80050 - !capable(CAP_SYS_NICE)) {
80051 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80052 rcu_read_unlock();
80053 err = -EPERM;
80054 goto out;
80055 diff --git a/mm/mlock.c b/mm/mlock.c
80056 index c9bd528..da8d069 100644
80057 --- a/mm/mlock.c
80058 +++ b/mm/mlock.c
80059 @@ -13,6 +13,7 @@
80060 #include <linux/pagemap.h>
80061 #include <linux/mempolicy.h>
80062 #include <linux/syscalls.h>
80063 +#include <linux/security.h>
80064 #include <linux/sched.h>
80065 #include <linux/export.h>
80066 #include <linux/rmap.h>
80067 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
80068 {
80069 unsigned long nstart, end, tmp;
80070 struct vm_area_struct * vma, * prev;
80071 - int error;
80072 + int error = 0;
80073
80074 VM_BUG_ON(start & ~PAGE_MASK);
80075 VM_BUG_ON(len != PAGE_ALIGN(len));
80076 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
80077 return -EINVAL;
80078 if (end == start)
80079 return 0;
80080 + if (end > TASK_SIZE)
80081 + return -EINVAL;
80082 +
80083 vma = find_vma(current->mm, start);
80084 if (!vma || vma->vm_start > start)
80085 return -ENOMEM;
80086 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
80087 for (nstart = start ; ; ) {
80088 vm_flags_t newflags;
80089
80090 +#ifdef CONFIG_PAX_SEGMEXEC
80091 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80092 + break;
80093 +#endif
80094 +
80095 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
80096
80097 newflags = vma->vm_flags | VM_LOCKED;
80098 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
80099 lock_limit >>= PAGE_SHIFT;
80100
80101 /* check against resource limits */
80102 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
80103 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
80104 error = do_mlock(start, len, 1);
80105 up_write(&current->mm->mmap_sem);
80106 @@ -528,6 +538,12 @@ static int do_mlockall(int flags)
80107 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
80108 vm_flags_t newflags;
80109
80110 +#ifdef CONFIG_PAX_SEGMEXEC
80111 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80112 + break;
80113 +#endif
80114 +
80115 + BUG_ON(vma->vm_end > TASK_SIZE);
80116 newflags = vma->vm_flags | VM_LOCKED;
80117 if (!(flags & MCL_CURRENT))
80118 newflags &= ~VM_LOCKED;
80119 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
80120 lock_limit >>= PAGE_SHIFT;
80121
80122 ret = -ENOMEM;
80123 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
80124 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
80125 capable(CAP_IPC_LOCK))
80126 ret = do_mlockall(flags);
80127 diff --git a/mm/mmap.c b/mm/mmap.c
80128 index 8832b87..20500c1 100644
80129 --- a/mm/mmap.c
80130 +++ b/mm/mmap.c
80131 @@ -32,6 +32,7 @@
80132 #include <linux/khugepaged.h>
80133 #include <linux/uprobes.h>
80134 #include <linux/rbtree_augmented.h>
80135 +#include <linux/random.h>
80136
80137 #include <asm/uaccess.h>
80138 #include <asm/cacheflush.h>
80139 @@ -48,6 +49,16 @@
80140 #define arch_rebalance_pgtables(addr, len) (addr)
80141 #endif
80142
80143 +static inline void verify_mm_writelocked(struct mm_struct *mm)
80144 +{
80145 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
80146 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
80147 + up_read(&mm->mmap_sem);
80148 + BUG();
80149 + }
80150 +#endif
80151 +}
80152 +
80153 static void unmap_region(struct mm_struct *mm,
80154 struct vm_area_struct *vma, struct vm_area_struct *prev,
80155 unsigned long start, unsigned long end);
80156 @@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
80157 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
80158 *
80159 */
80160 -pgprot_t protection_map[16] = {
80161 +pgprot_t protection_map[16] __read_only = {
80162 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
80163 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
80164 };
80165
80166 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
80167 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80168 {
80169 - return __pgprot(pgprot_val(protection_map[vm_flags &
80170 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
80171 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
80172 pgprot_val(arch_vm_get_page_prot(vm_flags)));
80173 +
80174 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80175 + if (!(__supported_pte_mask & _PAGE_NX) &&
80176 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
80177 + (vm_flags & (VM_READ | VM_WRITE)))
80178 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
80179 +#endif
80180 +
80181 + return prot;
80182 }
80183 EXPORT_SYMBOL(vm_get_page_prot);
80184
80185 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
80186 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
80187 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
80188 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
80189 /*
80190 * Make sure vm_committed_as in one cacheline and not cacheline shared with
80191 * other variables. It can be updated by several CPUs frequently.
80192 @@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
80193 struct vm_area_struct *next = vma->vm_next;
80194
80195 might_sleep();
80196 + BUG_ON(vma->vm_mirror);
80197 if (vma->vm_ops && vma->vm_ops->close)
80198 vma->vm_ops->close(vma);
80199 if (vma->vm_file)
80200 @@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
80201 * not page aligned -Ram Gupta
80202 */
80203 rlim = rlimit(RLIMIT_DATA);
80204 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
80205 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
80206 (mm->end_data - mm->start_data) > rlim)
80207 goto out;
80208 @@ -888,6 +911,12 @@ static int
80209 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
80210 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
80211 {
80212 +
80213 +#ifdef CONFIG_PAX_SEGMEXEC
80214 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
80215 + return 0;
80216 +#endif
80217 +
80218 if (is_mergeable_vma(vma, file, vm_flags) &&
80219 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
80220 if (vma->vm_pgoff == vm_pgoff)
80221 @@ -907,6 +936,12 @@ static int
80222 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
80223 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
80224 {
80225 +
80226 +#ifdef CONFIG_PAX_SEGMEXEC
80227 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
80228 + return 0;
80229 +#endif
80230 +
80231 if (is_mergeable_vma(vma, file, vm_flags) &&
80232 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
80233 pgoff_t vm_pglen;
80234 @@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
80235 struct vm_area_struct *vma_merge(struct mm_struct *mm,
80236 struct vm_area_struct *prev, unsigned long addr,
80237 unsigned long end, unsigned long vm_flags,
80238 - struct anon_vma *anon_vma, struct file *file,
80239 + struct anon_vma *anon_vma, struct file *file,
80240 pgoff_t pgoff, struct mempolicy *policy)
80241 {
80242 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
80243 struct vm_area_struct *area, *next;
80244 int err;
80245
80246 +#ifdef CONFIG_PAX_SEGMEXEC
80247 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
80248 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
80249 +
80250 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
80251 +#endif
80252 +
80253 /*
80254 * We later require that vma->vm_flags == vm_flags,
80255 * so this tests vma->vm_flags & VM_SPECIAL, too.
80256 @@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80257 if (next && next->vm_end == end) /* cases 6, 7, 8 */
80258 next = next->vm_next;
80259
80260 +#ifdef CONFIG_PAX_SEGMEXEC
80261 + if (prev)
80262 + prev_m = pax_find_mirror_vma(prev);
80263 + if (area)
80264 + area_m = pax_find_mirror_vma(area);
80265 + if (next)
80266 + next_m = pax_find_mirror_vma(next);
80267 +#endif
80268 +
80269 /*
80270 * Can it merge with the predecessor?
80271 */
80272 @@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80273 /* cases 1, 6 */
80274 err = vma_adjust(prev, prev->vm_start,
80275 next->vm_end, prev->vm_pgoff, NULL);
80276 - } else /* cases 2, 5, 7 */
80277 +
80278 +#ifdef CONFIG_PAX_SEGMEXEC
80279 + if (!err && prev_m)
80280 + err = vma_adjust(prev_m, prev_m->vm_start,
80281 + next_m->vm_end, prev_m->vm_pgoff, NULL);
80282 +#endif
80283 +
80284 + } else { /* cases 2, 5, 7 */
80285 err = vma_adjust(prev, prev->vm_start,
80286 end, prev->vm_pgoff, NULL);
80287 +
80288 +#ifdef CONFIG_PAX_SEGMEXEC
80289 + if (!err && prev_m)
80290 + err = vma_adjust(prev_m, prev_m->vm_start,
80291 + end_m, prev_m->vm_pgoff, NULL);
80292 +#endif
80293 +
80294 + }
80295 if (err)
80296 return NULL;
80297 khugepaged_enter_vma_merge(prev);
80298 @@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80299 mpol_equal(policy, vma_policy(next)) &&
80300 can_vma_merge_before(next, vm_flags,
80301 anon_vma, file, pgoff+pglen)) {
80302 - if (prev && addr < prev->vm_end) /* case 4 */
80303 + if (prev && addr < prev->vm_end) { /* case 4 */
80304 err = vma_adjust(prev, prev->vm_start,
80305 addr, prev->vm_pgoff, NULL);
80306 - else /* cases 3, 8 */
80307 +
80308 +#ifdef CONFIG_PAX_SEGMEXEC
80309 + if (!err && prev_m)
80310 + err = vma_adjust(prev_m, prev_m->vm_start,
80311 + addr_m, prev_m->vm_pgoff, NULL);
80312 +#endif
80313 +
80314 + } else { /* cases 3, 8 */
80315 err = vma_adjust(area, addr, next->vm_end,
80316 next->vm_pgoff - pglen, NULL);
80317 +
80318 +#ifdef CONFIG_PAX_SEGMEXEC
80319 + if (!err && area_m)
80320 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
80321 + next_m->vm_pgoff - pglen, NULL);
80322 +#endif
80323 +
80324 + }
80325 if (err)
80326 return NULL;
80327 khugepaged_enter_vma_merge(area);
80328 @@ -1120,16 +1201,13 @@ none:
80329 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
80330 struct file *file, long pages)
80331 {
80332 - const unsigned long stack_flags
80333 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
80334 -
80335 mm->total_vm += pages;
80336
80337 if (file) {
80338 mm->shared_vm += pages;
80339 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
80340 mm->exec_vm += pages;
80341 - } else if (flags & stack_flags)
80342 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
80343 mm->stack_vm += pages;
80344 }
80345 #endif /* CONFIG_PROC_FS */
80346 @@ -1165,7 +1243,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80347 * (the exception is when the underlying filesystem is noexec
80348 * mounted, in which case we dont add PROT_EXEC.)
80349 */
80350 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
80351 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
80352 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
80353 prot |= PROT_EXEC;
80354
80355 @@ -1191,7 +1269,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80356 /* Obtain the address to map to. we verify (or select) it and ensure
80357 * that it represents a valid section of the address space.
80358 */
80359 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
80360 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
80361 if (addr & ~PAGE_MASK)
80362 return addr;
80363
80364 @@ -1202,6 +1280,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80365 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
80366 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
80367
80368 +#ifdef CONFIG_PAX_MPROTECT
80369 + if (mm->pax_flags & MF_PAX_MPROTECT) {
80370 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
80371 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
80372 + gr_log_rwxmmap(file);
80373 +
80374 +#ifdef CONFIG_PAX_EMUPLT
80375 + vm_flags &= ~VM_EXEC;
80376 +#else
80377 + return -EPERM;
80378 +#endif
80379 +
80380 + }
80381 +
80382 + if (!(vm_flags & VM_EXEC))
80383 + vm_flags &= ~VM_MAYEXEC;
80384 +#else
80385 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
80386 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
80387 +#endif
80388 + else
80389 + vm_flags &= ~VM_MAYWRITE;
80390 + }
80391 +#endif
80392 +
80393 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80394 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
80395 + vm_flags &= ~VM_PAGEEXEC;
80396 +#endif
80397 +
80398 if (flags & MAP_LOCKED)
80399 if (!can_do_mlock())
80400 return -EPERM;
80401 @@ -1213,6 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80402 locked += mm->locked_vm;
80403 lock_limit = rlimit(RLIMIT_MEMLOCK);
80404 lock_limit >>= PAGE_SHIFT;
80405 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
80406 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
80407 return -EAGAIN;
80408 }
80409 @@ -1279,6 +1388,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80410 }
80411 }
80412
80413 + if (!gr_acl_handle_mmap(file, prot))
80414 + return -EACCES;
80415 +
80416 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
80417 }
80418
80419 @@ -1356,7 +1468,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
80420 vm_flags_t vm_flags = vma->vm_flags;
80421
80422 /* If it was private or non-writable, the write bit is already clear */
80423 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
80424 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
80425 return 0;
80426
80427 /* The backer wishes to know when pages are first written to? */
80428 @@ -1405,13 +1517,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
80429 unsigned long charged = 0;
80430 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
80431
80432 +#ifdef CONFIG_PAX_SEGMEXEC
80433 + struct vm_area_struct *vma_m = NULL;
80434 +#endif
80435 +
80436 + /*
80437 + * mm->mmap_sem is required to protect against another thread
80438 + * changing the mappings in case we sleep.
80439 + */
80440 + verify_mm_writelocked(mm);
80441 +
80442 /* Clear old maps */
80443 error = -ENOMEM;
80444 -munmap_back:
80445 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
80446 if (do_munmap(mm, addr, len))
80447 return -ENOMEM;
80448 - goto munmap_back;
80449 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
80450 }
80451
80452 /* Check against address space limit. */
80453 @@ -1460,6 +1581,16 @@ munmap_back:
80454 goto unacct_error;
80455 }
80456
80457 +#ifdef CONFIG_PAX_SEGMEXEC
80458 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
80459 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
80460 + if (!vma_m) {
80461 + error = -ENOMEM;
80462 + goto free_vma;
80463 + }
80464 + }
80465 +#endif
80466 +
80467 vma->vm_mm = mm;
80468 vma->vm_start = addr;
80469 vma->vm_end = addr + len;
80470 @@ -1484,6 +1615,13 @@ munmap_back:
80471 if (error)
80472 goto unmap_and_free_vma;
80473
80474 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80475 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
80476 + vma->vm_flags |= VM_PAGEEXEC;
80477 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
80478 + }
80479 +#endif
80480 +
80481 /* Can addr have changed??
80482 *
80483 * Answer: Yes, several device drivers can do it in their
80484 @@ -1522,6 +1660,11 @@ munmap_back:
80485 vma_link(mm, vma, prev, rb_link, rb_parent);
80486 file = vma->vm_file;
80487
80488 +#ifdef CONFIG_PAX_SEGMEXEC
80489 + if (vma_m)
80490 + BUG_ON(pax_mirror_vma(vma_m, vma));
80491 +#endif
80492 +
80493 /* Once vma denies write, undo our temporary denial count */
80494 if (correct_wcount)
80495 atomic_inc(&inode->i_writecount);
80496 @@ -1529,6 +1672,7 @@ out:
80497 perf_event_mmap(vma);
80498
80499 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
80500 + track_exec_limit(mm, addr, addr + len, vm_flags);
80501 if (vm_flags & VM_LOCKED) {
80502 if (!mlock_vma_pages_range(vma, addr, addr + len))
80503 mm->locked_vm += (len >> PAGE_SHIFT);
80504 @@ -1550,6 +1694,12 @@ unmap_and_free_vma:
80505 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
80506 charged = 0;
80507 free_vma:
80508 +
80509 +#ifdef CONFIG_PAX_SEGMEXEC
80510 + if (vma_m)
80511 + kmem_cache_free(vm_area_cachep, vma_m);
80512 +#endif
80513 +
80514 kmem_cache_free(vm_area_cachep, vma);
80515 unacct_error:
80516 if (charged)
80517 @@ -1557,6 +1707,62 @@ unacct_error:
80518 return error;
80519 }
80520
80521 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
80522 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
80523 +{
80524 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
80525 + return (random32() & 0xFF) << PAGE_SHIFT;
80526 +
80527 + return 0;
80528 +}
80529 +#endif
80530 +
80531 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
80532 +{
80533 + if (!vma) {
80534 +#ifdef CONFIG_STACK_GROWSUP
80535 + if (addr > sysctl_heap_stack_gap)
80536 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
80537 + else
80538 + vma = find_vma(current->mm, 0);
80539 + if (vma && (vma->vm_flags & VM_GROWSUP))
80540 + return false;
80541 +#endif
80542 + return true;
80543 + }
80544 +
80545 + if (addr + len > vma->vm_start)
80546 + return false;
80547 +
80548 + if (vma->vm_flags & VM_GROWSDOWN)
80549 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
80550 +#ifdef CONFIG_STACK_GROWSUP
80551 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
80552 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
80553 +#endif
80554 + else if (offset)
80555 + return offset <= vma->vm_start - addr - len;
80556 +
80557 + return true;
80558 +}
80559 +
80560 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
80561 +{
80562 + if (vma->vm_start < len)
80563 + return -ENOMEM;
80564 +
80565 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
80566 + if (offset <= vma->vm_start - len)
80567 + return vma->vm_start - len - offset;
80568 + else
80569 + return -ENOMEM;
80570 + }
80571 +
80572 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
80573 + return vma->vm_start - len - sysctl_heap_stack_gap;
80574 + return -ENOMEM;
80575 +}
80576 +
80577 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
80578 {
80579 /*
80580 @@ -1776,6 +1982,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80581 struct mm_struct *mm = current->mm;
80582 struct vm_area_struct *vma;
80583 struct vm_unmapped_area_info info;
80584 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
80585
80586 if (len > TASK_SIZE)
80587 return -ENOMEM;
80588 @@ -1783,17 +1990,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80589 if (flags & MAP_FIXED)
80590 return addr;
80591
80592 +#ifdef CONFIG_PAX_RANDMMAP
80593 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
80594 +#endif
80595 +
80596 if (addr) {
80597 addr = PAGE_ALIGN(addr);
80598 vma = find_vma(mm, addr);
80599 - if (TASK_SIZE - len >= addr &&
80600 - (!vma || addr + len <= vma->vm_start))
80601 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
80602 return addr;
80603 }
80604
80605 info.flags = 0;
80606 info.length = len;
80607 info.low_limit = TASK_UNMAPPED_BASE;
80608 +
80609 +#ifdef CONFIG_PAX_RANDMMAP
80610 + if (mm->pax_flags & MF_PAX_RANDMMAP)
80611 + info.low_limit += mm->delta_mmap;
80612 +#endif
80613 +
80614 info.high_limit = TASK_SIZE;
80615 info.align_mask = 0;
80616 return vm_unmapped_area(&info);
80617 @@ -1802,10 +2018,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80618
80619 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
80620 {
80621 +
80622 +#ifdef CONFIG_PAX_SEGMEXEC
80623 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
80624 + return;
80625 +#endif
80626 +
80627 /*
80628 * Is this a new hole at the lowest possible address?
80629 */
80630 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
80631 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
80632 mm->free_area_cache = addr;
80633 }
80634
80635 @@ -1823,6 +2045,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80636 struct mm_struct *mm = current->mm;
80637 unsigned long addr = addr0;
80638 struct vm_unmapped_area_info info;
80639 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
80640
80641 /* requested length too big for entire address space */
80642 if (len > TASK_SIZE)
80643 @@ -1831,12 +2054,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80644 if (flags & MAP_FIXED)
80645 return addr;
80646
80647 +#ifdef CONFIG_PAX_RANDMMAP
80648 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
80649 +#endif
80650 +
80651 /* requesting a specific address */
80652 if (addr) {
80653 addr = PAGE_ALIGN(addr);
80654 vma = find_vma(mm, addr);
80655 - if (TASK_SIZE - len >= addr &&
80656 - (!vma || addr + len <= vma->vm_start))
80657 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
80658 return addr;
80659 }
80660
80661 @@ -1857,6 +2083,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80662 VM_BUG_ON(addr != -ENOMEM);
80663 info.flags = 0;
80664 info.low_limit = TASK_UNMAPPED_BASE;
80665 +
80666 +#ifdef CONFIG_PAX_RANDMMAP
80667 + if (mm->pax_flags & MF_PAX_RANDMMAP)
80668 + info.low_limit += mm->delta_mmap;
80669 +#endif
80670 +
80671 info.high_limit = TASK_SIZE;
80672 addr = vm_unmapped_area(&info);
80673 }
80674 @@ -1867,6 +2099,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80675
80676 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
80677 {
80678 +
80679 +#ifdef CONFIG_PAX_SEGMEXEC
80680 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
80681 + return;
80682 +#endif
80683 +
80684 /*
80685 * Is this a new hole at the highest possible address?
80686 */
80687 @@ -1874,8 +2112,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
80688 mm->free_area_cache = addr;
80689
80690 /* dont allow allocations above current base */
80691 - if (mm->free_area_cache > mm->mmap_base)
80692 + if (mm->free_area_cache > mm->mmap_base) {
80693 mm->free_area_cache = mm->mmap_base;
80694 + mm->cached_hole_size = ~0UL;
80695 + }
80696 }
80697
80698 unsigned long
80699 @@ -1974,6 +2214,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
80700 return vma;
80701 }
80702
80703 +#ifdef CONFIG_PAX_SEGMEXEC
80704 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
80705 +{
80706 + struct vm_area_struct *vma_m;
80707 +
80708 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
80709 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
80710 + BUG_ON(vma->vm_mirror);
80711 + return NULL;
80712 + }
80713 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
80714 + vma_m = vma->vm_mirror;
80715 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
80716 + BUG_ON(vma->vm_file != vma_m->vm_file);
80717 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
80718 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
80719 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
80720 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
80721 + return vma_m;
80722 +}
80723 +#endif
80724 +
80725 /*
80726 * Verify that the stack growth is acceptable and
80727 * update accounting. This is shared with both the
80728 @@ -1990,6 +2252,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80729 return -ENOMEM;
80730
80731 /* Stack limit test */
80732 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
80733 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
80734 return -ENOMEM;
80735
80736 @@ -2000,6 +2263,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80737 locked = mm->locked_vm + grow;
80738 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
80739 limit >>= PAGE_SHIFT;
80740 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
80741 if (locked > limit && !capable(CAP_IPC_LOCK))
80742 return -ENOMEM;
80743 }
80744 @@ -2029,37 +2293,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80745 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
80746 * vma is the last one with address > vma->vm_end. Have to extend vma.
80747 */
80748 +#ifndef CONFIG_IA64
80749 +static
80750 +#endif
80751 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
80752 {
80753 int error;
80754 + bool locknext;
80755
80756 if (!(vma->vm_flags & VM_GROWSUP))
80757 return -EFAULT;
80758
80759 + /* Also guard against wrapping around to address 0. */
80760 + if (address < PAGE_ALIGN(address+1))
80761 + address = PAGE_ALIGN(address+1);
80762 + else
80763 + return -ENOMEM;
80764 +
80765 /*
80766 * We must make sure the anon_vma is allocated
80767 * so that the anon_vma locking is not a noop.
80768 */
80769 if (unlikely(anon_vma_prepare(vma)))
80770 return -ENOMEM;
80771 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
80772 + if (locknext && anon_vma_prepare(vma->vm_next))
80773 + return -ENOMEM;
80774 vma_lock_anon_vma(vma);
80775 + if (locknext)
80776 + vma_lock_anon_vma(vma->vm_next);
80777
80778 /*
80779 * vma->vm_start/vm_end cannot change under us because the caller
80780 * is required to hold the mmap_sem in read mode. We need the
80781 - * anon_vma lock to serialize against concurrent expand_stacks.
80782 - * Also guard against wrapping around to address 0.
80783 + * anon_vma locks to serialize against concurrent expand_stacks
80784 + * and expand_upwards.
80785 */
80786 - if (address < PAGE_ALIGN(address+4))
80787 - address = PAGE_ALIGN(address+4);
80788 - else {
80789 - vma_unlock_anon_vma(vma);
80790 - return -ENOMEM;
80791 - }
80792 error = 0;
80793
80794 /* Somebody else might have raced and expanded it already */
80795 - if (address > vma->vm_end) {
80796 + 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)
80797 + error = -ENOMEM;
80798 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
80799 unsigned long size, grow;
80800
80801 size = address - vma->vm_start;
80802 @@ -2094,6 +2369,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
80803 }
80804 }
80805 }
80806 + if (locknext)
80807 + vma_unlock_anon_vma(vma->vm_next);
80808 vma_unlock_anon_vma(vma);
80809 khugepaged_enter_vma_merge(vma);
80810 validate_mm(vma->vm_mm);
80811 @@ -2108,6 +2385,8 @@ int expand_downwards(struct vm_area_struct *vma,
80812 unsigned long address)
80813 {
80814 int error;
80815 + bool lockprev = false;
80816 + struct vm_area_struct *prev;
80817
80818 /*
80819 * We must make sure the anon_vma is allocated
80820 @@ -2121,6 +2400,15 @@ int expand_downwards(struct vm_area_struct *vma,
80821 if (error)
80822 return error;
80823
80824 + prev = vma->vm_prev;
80825 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
80826 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
80827 +#endif
80828 + if (lockprev && anon_vma_prepare(prev))
80829 + return -ENOMEM;
80830 + if (lockprev)
80831 + vma_lock_anon_vma(prev);
80832 +
80833 vma_lock_anon_vma(vma);
80834
80835 /*
80836 @@ -2130,9 +2418,17 @@ int expand_downwards(struct vm_area_struct *vma,
80837 */
80838
80839 /* Somebody else might have raced and expanded it already */
80840 - if (address < vma->vm_start) {
80841 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
80842 + error = -ENOMEM;
80843 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
80844 unsigned long size, grow;
80845
80846 +#ifdef CONFIG_PAX_SEGMEXEC
80847 + struct vm_area_struct *vma_m;
80848 +
80849 + vma_m = pax_find_mirror_vma(vma);
80850 +#endif
80851 +
80852 size = vma->vm_end - address;
80853 grow = (vma->vm_start - address) >> PAGE_SHIFT;
80854
80855 @@ -2157,6 +2453,18 @@ int expand_downwards(struct vm_area_struct *vma,
80856 vma->vm_pgoff -= grow;
80857 anon_vma_interval_tree_post_update_vma(vma);
80858 vma_gap_update(vma);
80859 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
80860 +
80861 +#ifdef CONFIG_PAX_SEGMEXEC
80862 + if (vma_m) {
80863 + anon_vma_interval_tree_pre_update_vma(vma_m);
80864 + vma_m->vm_start -= grow << PAGE_SHIFT;
80865 + vma_m->vm_pgoff -= grow;
80866 + anon_vma_interval_tree_post_update_vma(vma_m);
80867 + vma_gap_update(vma_m);
80868 + }
80869 +#endif
80870 +
80871 spin_unlock(&vma->vm_mm->page_table_lock);
80872
80873 perf_event_mmap(vma);
80874 @@ -2263,6 +2571,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
80875 do {
80876 long nrpages = vma_pages(vma);
80877
80878 +#ifdef CONFIG_PAX_SEGMEXEC
80879 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
80880 + vma = remove_vma(vma);
80881 + continue;
80882 + }
80883 +#endif
80884 +
80885 if (vma->vm_flags & VM_ACCOUNT)
80886 nr_accounted += nrpages;
80887 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
80888 @@ -2308,6 +2623,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
80889 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
80890 vma->vm_prev = NULL;
80891 do {
80892 +
80893 +#ifdef CONFIG_PAX_SEGMEXEC
80894 + if (vma->vm_mirror) {
80895 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
80896 + vma->vm_mirror->vm_mirror = NULL;
80897 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
80898 + vma->vm_mirror = NULL;
80899 + }
80900 +#endif
80901 +
80902 vma_rb_erase(vma, &mm->mm_rb);
80903 mm->map_count--;
80904 tail_vma = vma;
80905 @@ -2339,14 +2664,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
80906 struct vm_area_struct *new;
80907 int err = -ENOMEM;
80908
80909 +#ifdef CONFIG_PAX_SEGMEXEC
80910 + struct vm_area_struct *vma_m, *new_m = NULL;
80911 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
80912 +#endif
80913 +
80914 if (is_vm_hugetlb_page(vma) && (addr &
80915 ~(huge_page_mask(hstate_vma(vma)))))
80916 return -EINVAL;
80917
80918 +#ifdef CONFIG_PAX_SEGMEXEC
80919 + vma_m = pax_find_mirror_vma(vma);
80920 +#endif
80921 +
80922 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80923 if (!new)
80924 goto out_err;
80925
80926 +#ifdef CONFIG_PAX_SEGMEXEC
80927 + if (vma_m) {
80928 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80929 + if (!new_m) {
80930 + kmem_cache_free(vm_area_cachep, new);
80931 + goto out_err;
80932 + }
80933 + }
80934 +#endif
80935 +
80936 /* most fields are the same, copy all, and then fixup */
80937 *new = *vma;
80938
80939 @@ -2359,6 +2703,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
80940 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
80941 }
80942
80943 +#ifdef CONFIG_PAX_SEGMEXEC
80944 + if (vma_m) {
80945 + *new_m = *vma_m;
80946 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
80947 + new_m->vm_mirror = new;
80948 + new->vm_mirror = new_m;
80949 +
80950 + if (new_below)
80951 + new_m->vm_end = addr_m;
80952 + else {
80953 + new_m->vm_start = addr_m;
80954 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
80955 + }
80956 + }
80957 +#endif
80958 +
80959 pol = mpol_dup(vma_policy(vma));
80960 if (IS_ERR(pol)) {
80961 err = PTR_ERR(pol);
80962 @@ -2381,6 +2741,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
80963 else
80964 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
80965
80966 +#ifdef CONFIG_PAX_SEGMEXEC
80967 + if (!err && vma_m) {
80968 + if (anon_vma_clone(new_m, vma_m))
80969 + goto out_free_mpol;
80970 +
80971 + mpol_get(pol);
80972 + vma_set_policy(new_m, pol);
80973 +
80974 + if (new_m->vm_file)
80975 + get_file(new_m->vm_file);
80976 +
80977 + if (new_m->vm_ops && new_m->vm_ops->open)
80978 + new_m->vm_ops->open(new_m);
80979 +
80980 + if (new_below)
80981 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
80982 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
80983 + else
80984 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
80985 +
80986 + if (err) {
80987 + if (new_m->vm_ops && new_m->vm_ops->close)
80988 + new_m->vm_ops->close(new_m);
80989 + if (new_m->vm_file)
80990 + fput(new_m->vm_file);
80991 + mpol_put(pol);
80992 + }
80993 + }
80994 +#endif
80995 +
80996 /* Success. */
80997 if (!err)
80998 return 0;
80999 @@ -2390,10 +2780,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81000 new->vm_ops->close(new);
81001 if (new->vm_file)
81002 fput(new->vm_file);
81003 - unlink_anon_vmas(new);
81004 out_free_mpol:
81005 mpol_put(pol);
81006 out_free_vma:
81007 +
81008 +#ifdef CONFIG_PAX_SEGMEXEC
81009 + if (new_m) {
81010 + unlink_anon_vmas(new_m);
81011 + kmem_cache_free(vm_area_cachep, new_m);
81012 + }
81013 +#endif
81014 +
81015 + unlink_anon_vmas(new);
81016 kmem_cache_free(vm_area_cachep, new);
81017 out_err:
81018 return err;
81019 @@ -2406,6 +2804,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81020 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81021 unsigned long addr, int new_below)
81022 {
81023 +
81024 +#ifdef CONFIG_PAX_SEGMEXEC
81025 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
81026 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
81027 + if (mm->map_count >= sysctl_max_map_count-1)
81028 + return -ENOMEM;
81029 + } else
81030 +#endif
81031 +
81032 if (mm->map_count >= sysctl_max_map_count)
81033 return -ENOMEM;
81034
81035 @@ -2417,11 +2824,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81036 * work. This now handles partial unmappings.
81037 * Jeremy Fitzhardinge <jeremy@goop.org>
81038 */
81039 +#ifdef CONFIG_PAX_SEGMEXEC
81040 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81041 {
81042 + int ret = __do_munmap(mm, start, len);
81043 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
81044 + return ret;
81045 +
81046 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
81047 +}
81048 +
81049 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81050 +#else
81051 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81052 +#endif
81053 +{
81054 unsigned long end;
81055 struct vm_area_struct *vma, *prev, *last;
81056
81057 + /*
81058 + * mm->mmap_sem is required to protect against another thread
81059 + * changing the mappings in case we sleep.
81060 + */
81061 + verify_mm_writelocked(mm);
81062 +
81063 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
81064 return -EINVAL;
81065
81066 @@ -2496,6 +2922,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81067 /* Fix up all other VM information */
81068 remove_vma_list(mm, vma);
81069
81070 + track_exec_limit(mm, start, end, 0UL);
81071 +
81072 return 0;
81073 }
81074
81075 @@ -2504,6 +2932,13 @@ int vm_munmap(unsigned long start, size_t len)
81076 int ret;
81077 struct mm_struct *mm = current->mm;
81078
81079 +
81080 +#ifdef CONFIG_PAX_SEGMEXEC
81081 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
81082 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
81083 + return -EINVAL;
81084 +#endif
81085 +
81086 down_write(&mm->mmap_sem);
81087 ret = do_munmap(mm, start, len);
81088 up_write(&mm->mmap_sem);
81089 @@ -2517,16 +2952,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
81090 return vm_munmap(addr, len);
81091 }
81092
81093 -static inline void verify_mm_writelocked(struct mm_struct *mm)
81094 -{
81095 -#ifdef CONFIG_DEBUG_VM
81096 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
81097 - WARN_ON(1);
81098 - up_read(&mm->mmap_sem);
81099 - }
81100 -#endif
81101 -}
81102 -
81103 /*
81104 * this is really a simplified "do_mmap". it only handles
81105 * anonymous maps. eventually we may be able to do some
81106 @@ -2540,6 +2965,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81107 struct rb_node ** rb_link, * rb_parent;
81108 pgoff_t pgoff = addr >> PAGE_SHIFT;
81109 int error;
81110 + unsigned long charged;
81111
81112 len = PAGE_ALIGN(len);
81113 if (!len)
81114 @@ -2547,16 +2973,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81115
81116 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
81117
81118 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
81119 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
81120 + flags &= ~VM_EXEC;
81121 +
81122 +#ifdef CONFIG_PAX_MPROTECT
81123 + if (mm->pax_flags & MF_PAX_MPROTECT)
81124 + flags &= ~VM_MAYEXEC;
81125 +#endif
81126 +
81127 + }
81128 +#endif
81129 +
81130 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
81131 if (error & ~PAGE_MASK)
81132 return error;
81133
81134 + charged = len >> PAGE_SHIFT;
81135 +
81136 /*
81137 * mlock MCL_FUTURE?
81138 */
81139 if (mm->def_flags & VM_LOCKED) {
81140 unsigned long locked, lock_limit;
81141 - locked = len >> PAGE_SHIFT;
81142 + locked = charged;
81143 locked += mm->locked_vm;
81144 lock_limit = rlimit(RLIMIT_MEMLOCK);
81145 lock_limit >>= PAGE_SHIFT;
81146 @@ -2573,21 +3013,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81147 /*
81148 * Clear old maps. this also does some error checking for us
81149 */
81150 - munmap_back:
81151 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
81152 if (do_munmap(mm, addr, len))
81153 return -ENOMEM;
81154 - goto munmap_back;
81155 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
81156 }
81157
81158 /* Check against address space limits *after* clearing old maps... */
81159 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
81160 + if (!may_expand_vm(mm, charged))
81161 return -ENOMEM;
81162
81163 if (mm->map_count > sysctl_max_map_count)
81164 return -ENOMEM;
81165
81166 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
81167 + if (security_vm_enough_memory_mm(mm, charged))
81168 return -ENOMEM;
81169
81170 /* Can we just expand an old private anonymous mapping? */
81171 @@ -2601,7 +3040,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81172 */
81173 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81174 if (!vma) {
81175 - vm_unacct_memory(len >> PAGE_SHIFT);
81176 + vm_unacct_memory(charged);
81177 return -ENOMEM;
81178 }
81179
81180 @@ -2615,11 +3054,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81181 vma_link(mm, vma, prev, rb_link, rb_parent);
81182 out:
81183 perf_event_mmap(vma);
81184 - mm->total_vm += len >> PAGE_SHIFT;
81185 + mm->total_vm += charged;
81186 if (flags & VM_LOCKED) {
81187 if (!mlock_vma_pages_range(vma, addr, addr + len))
81188 - mm->locked_vm += (len >> PAGE_SHIFT);
81189 + mm->locked_vm += charged;
81190 }
81191 + track_exec_limit(mm, addr, addr + len, flags);
81192 return addr;
81193 }
81194
81195 @@ -2677,6 +3117,7 @@ void exit_mmap(struct mm_struct *mm)
81196 while (vma) {
81197 if (vma->vm_flags & VM_ACCOUNT)
81198 nr_accounted += vma_pages(vma);
81199 + vma->vm_mirror = NULL;
81200 vma = remove_vma(vma);
81201 }
81202 vm_unacct_memory(nr_accounted);
81203 @@ -2693,6 +3134,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
81204 struct vm_area_struct *prev;
81205 struct rb_node **rb_link, *rb_parent;
81206
81207 +#ifdef CONFIG_PAX_SEGMEXEC
81208 + struct vm_area_struct *vma_m = NULL;
81209 +#endif
81210 +
81211 + if (security_mmap_addr(vma->vm_start))
81212 + return -EPERM;
81213 +
81214 /*
81215 * The vm_pgoff of a purely anonymous vma should be irrelevant
81216 * until its first write fault, when page's anon_vma and index
81217 @@ -2716,7 +3164,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
81218 security_vm_enough_memory_mm(mm, vma_pages(vma)))
81219 return -ENOMEM;
81220
81221 +#ifdef CONFIG_PAX_SEGMEXEC
81222 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
81223 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81224 + if (!vma_m)
81225 + return -ENOMEM;
81226 + }
81227 +#endif
81228 +
81229 vma_link(mm, vma, prev, rb_link, rb_parent);
81230 +
81231 +#ifdef CONFIG_PAX_SEGMEXEC
81232 + if (vma_m)
81233 + BUG_ON(pax_mirror_vma(vma_m, vma));
81234 +#endif
81235 +
81236 return 0;
81237 }
81238
81239 @@ -2736,6 +3198,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
81240 struct mempolicy *pol;
81241 bool faulted_in_anon_vma = true;
81242
81243 + BUG_ON(vma->vm_mirror);
81244 +
81245 /*
81246 * If anonymous vma has not yet been faulted, update new pgoff
81247 * to match new location, to increase its chance of merging.
81248 @@ -2802,6 +3266,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
81249 return NULL;
81250 }
81251
81252 +#ifdef CONFIG_PAX_SEGMEXEC
81253 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
81254 +{
81255 + struct vm_area_struct *prev_m;
81256 + struct rb_node **rb_link_m, *rb_parent_m;
81257 + struct mempolicy *pol_m;
81258 +
81259 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
81260 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
81261 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
81262 + *vma_m = *vma;
81263 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
81264 + if (anon_vma_clone(vma_m, vma))
81265 + return -ENOMEM;
81266 + pol_m = vma_policy(vma_m);
81267 + mpol_get(pol_m);
81268 + vma_set_policy(vma_m, pol_m);
81269 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
81270 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
81271 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
81272 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
81273 + if (vma_m->vm_file)
81274 + get_file(vma_m->vm_file);
81275 + if (vma_m->vm_ops && vma_m->vm_ops->open)
81276 + vma_m->vm_ops->open(vma_m);
81277 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
81278 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
81279 + vma_m->vm_mirror = vma;
81280 + vma->vm_mirror = vma_m;
81281 + return 0;
81282 +}
81283 +#endif
81284 +
81285 /*
81286 * Return true if the calling process may expand its vm space by the passed
81287 * number of pages
81288 @@ -2813,6 +3310,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
81289
81290 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
81291
81292 +#ifdef CONFIG_PAX_RANDMMAP
81293 + if (mm->pax_flags & MF_PAX_RANDMMAP)
81294 + cur -= mm->aslr_gap;
81295 +#endif
81296 +
81297 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
81298 if (cur + npages > lim)
81299 return 0;
81300 return 1;
81301 @@ -2883,6 +3386,22 @@ int install_special_mapping(struct mm_struct *mm,
81302 vma->vm_start = addr;
81303 vma->vm_end = addr + len;
81304
81305 +#ifdef CONFIG_PAX_MPROTECT
81306 + if (mm->pax_flags & MF_PAX_MPROTECT) {
81307 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
81308 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
81309 + return -EPERM;
81310 + if (!(vm_flags & VM_EXEC))
81311 + vm_flags &= ~VM_MAYEXEC;
81312 +#else
81313 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
81314 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
81315 +#endif
81316 + else
81317 + vm_flags &= ~VM_MAYWRITE;
81318 + }
81319 +#endif
81320 +
81321 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
81322 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
81323
81324 diff --git a/mm/mprotect.c b/mm/mprotect.c
81325 index 94722a4..9837984 100644
81326 --- a/mm/mprotect.c
81327 +++ b/mm/mprotect.c
81328 @@ -23,10 +23,17 @@
81329 #include <linux/mmu_notifier.h>
81330 #include <linux/migrate.h>
81331 #include <linux/perf_event.h>
81332 +
81333 +#ifdef CONFIG_PAX_MPROTECT
81334 +#include <linux/elf.h>
81335 +#include <linux/binfmts.h>
81336 +#endif
81337 +
81338 #include <asm/uaccess.h>
81339 #include <asm/pgtable.h>
81340 #include <asm/cacheflush.h>
81341 #include <asm/tlbflush.h>
81342 +#include <asm/mmu_context.h>
81343
81344 #ifndef pgprot_modify
81345 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
81346 @@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
81347 return pages;
81348 }
81349
81350 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81351 +/* called while holding the mmap semaphor for writing except stack expansion */
81352 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
81353 +{
81354 + unsigned long oldlimit, newlimit = 0UL;
81355 +
81356 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
81357 + return;
81358 +
81359 + spin_lock(&mm->page_table_lock);
81360 + oldlimit = mm->context.user_cs_limit;
81361 + if ((prot & VM_EXEC) && oldlimit < end)
81362 + /* USER_CS limit moved up */
81363 + newlimit = end;
81364 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
81365 + /* USER_CS limit moved down */
81366 + newlimit = start;
81367 +
81368 + if (newlimit) {
81369 + mm->context.user_cs_limit = newlimit;
81370 +
81371 +#ifdef CONFIG_SMP
81372 + wmb();
81373 + cpus_clear(mm->context.cpu_user_cs_mask);
81374 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
81375 +#endif
81376 +
81377 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
81378 + }
81379 + spin_unlock(&mm->page_table_lock);
81380 + if (newlimit == end) {
81381 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
81382 +
81383 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
81384 + if (is_vm_hugetlb_page(vma))
81385 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
81386 + else
81387 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
81388 + }
81389 +}
81390 +#endif
81391 +
81392 int
81393 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81394 unsigned long start, unsigned long end, unsigned long newflags)
81395 @@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81396 int error;
81397 int dirty_accountable = 0;
81398
81399 +#ifdef CONFIG_PAX_SEGMEXEC
81400 + struct vm_area_struct *vma_m = NULL;
81401 + unsigned long start_m, end_m;
81402 +
81403 + start_m = start + SEGMEXEC_TASK_SIZE;
81404 + end_m = end + SEGMEXEC_TASK_SIZE;
81405 +#endif
81406 +
81407 if (newflags == oldflags) {
81408 *pprev = vma;
81409 return 0;
81410 }
81411
81412 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
81413 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
81414 +
81415 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
81416 + return -ENOMEM;
81417 +
81418 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
81419 + return -ENOMEM;
81420 + }
81421 +
81422 /*
81423 * If we make a private mapping writable we increase our commit;
81424 * but (without finer accounting) cannot reduce our commit if we
81425 @@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81426 }
81427 }
81428
81429 +#ifdef CONFIG_PAX_SEGMEXEC
81430 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
81431 + if (start != vma->vm_start) {
81432 + error = split_vma(mm, vma, start, 1);
81433 + if (error)
81434 + goto fail;
81435 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
81436 + *pprev = (*pprev)->vm_next;
81437 + }
81438 +
81439 + if (end != vma->vm_end) {
81440 + error = split_vma(mm, vma, end, 0);
81441 + if (error)
81442 + goto fail;
81443 + }
81444 +
81445 + if (pax_find_mirror_vma(vma)) {
81446 + error = __do_munmap(mm, start_m, end_m - start_m);
81447 + if (error)
81448 + goto fail;
81449 + } else {
81450 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81451 + if (!vma_m) {
81452 + error = -ENOMEM;
81453 + goto fail;
81454 + }
81455 + vma->vm_flags = newflags;
81456 + error = pax_mirror_vma(vma_m, vma);
81457 + if (error) {
81458 + vma->vm_flags = oldflags;
81459 + goto fail;
81460 + }
81461 + }
81462 + }
81463 +#endif
81464 +
81465 /*
81466 * First try to merge with previous and/or next vma.
81467 */
81468 @@ -296,9 +399,21 @@ success:
81469 * vm_flags and vm_page_prot are protected by the mmap_sem
81470 * held in write mode.
81471 */
81472 +
81473 +#ifdef CONFIG_PAX_SEGMEXEC
81474 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
81475 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
81476 +#endif
81477 +
81478 vma->vm_flags = newflags;
81479 +
81480 +#ifdef CONFIG_PAX_MPROTECT
81481 + if (mm->binfmt && mm->binfmt->handle_mprotect)
81482 + mm->binfmt->handle_mprotect(vma, newflags);
81483 +#endif
81484 +
81485 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
81486 - vm_get_page_prot(newflags));
81487 + vm_get_page_prot(vma->vm_flags));
81488
81489 if (vma_wants_writenotify(vma)) {
81490 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
81491 @@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81492 end = start + len;
81493 if (end <= start)
81494 return -ENOMEM;
81495 +
81496 +#ifdef CONFIG_PAX_SEGMEXEC
81497 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81498 + if (end > SEGMEXEC_TASK_SIZE)
81499 + return -EINVAL;
81500 + } else
81501 +#endif
81502 +
81503 + if (end > TASK_SIZE)
81504 + return -EINVAL;
81505 +
81506 if (!arch_validate_prot(prot))
81507 return -EINVAL;
81508
81509 @@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81510 /*
81511 * Does the application expect PROT_READ to imply PROT_EXEC:
81512 */
81513 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
81514 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
81515 prot |= PROT_EXEC;
81516
81517 vm_flags = calc_vm_prot_bits(prot);
81518 @@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81519 if (start > vma->vm_start)
81520 prev = vma;
81521
81522 +#ifdef CONFIG_PAX_MPROTECT
81523 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
81524 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
81525 +#endif
81526 +
81527 for (nstart = start ; ; ) {
81528 unsigned long newflags;
81529
81530 @@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81531
81532 /* newflags >> 4 shift VM_MAY% in place of VM_% */
81533 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
81534 + if (prot & (PROT_WRITE | PROT_EXEC))
81535 + gr_log_rwxmprotect(vma->vm_file);
81536 +
81537 + error = -EACCES;
81538 + goto out;
81539 + }
81540 +
81541 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
81542 error = -EACCES;
81543 goto out;
81544 }
81545 @@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81546 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
81547 if (error)
81548 goto out;
81549 +
81550 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
81551 +
81552 nstart = tmp;
81553
81554 if (nstart < prev->vm_end)
81555 diff --git a/mm/mremap.c b/mm/mremap.c
81556 index e1031e1..1f2a0a1 100644
81557 --- a/mm/mremap.c
81558 +++ b/mm/mremap.c
81559 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
81560 continue;
81561 pte = ptep_get_and_clear(mm, old_addr, old_pte);
81562 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
81563 +
81564 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81565 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
81566 + pte = pte_exprotect(pte);
81567 +#endif
81568 +
81569 set_pte_at(mm, new_addr, new_pte, pte);
81570 }
81571
81572 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
81573 if (is_vm_hugetlb_page(vma))
81574 goto Einval;
81575
81576 +#ifdef CONFIG_PAX_SEGMEXEC
81577 + if (pax_find_mirror_vma(vma))
81578 + goto Einval;
81579 +#endif
81580 +
81581 /* We can't remap across vm area boundaries */
81582 if (old_len > vma->vm_end - addr)
81583 goto Efault;
81584 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
81585 unsigned long ret = -EINVAL;
81586 unsigned long charged = 0;
81587 unsigned long map_flags;
81588 + unsigned long pax_task_size = TASK_SIZE;
81589
81590 if (new_addr & ~PAGE_MASK)
81591 goto out;
81592
81593 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
81594 +#ifdef CONFIG_PAX_SEGMEXEC
81595 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
81596 + pax_task_size = SEGMEXEC_TASK_SIZE;
81597 +#endif
81598 +
81599 + pax_task_size -= PAGE_SIZE;
81600 +
81601 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
81602 goto out;
81603
81604 /* Check if the location we're moving into overlaps the
81605 * old location at all, and fail if it does.
81606 */
81607 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
81608 - goto out;
81609 -
81610 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
81611 + if (addr + old_len > new_addr && new_addr + new_len > addr)
81612 goto out;
81613
81614 ret = do_munmap(mm, new_addr, new_len);
81615 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81616 struct vm_area_struct *vma;
81617 unsigned long ret = -EINVAL;
81618 unsigned long charged = 0;
81619 + unsigned long pax_task_size = TASK_SIZE;
81620
81621 down_write(&current->mm->mmap_sem);
81622
81623 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81624 if (!new_len)
81625 goto out;
81626
81627 +#ifdef CONFIG_PAX_SEGMEXEC
81628 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
81629 + pax_task_size = SEGMEXEC_TASK_SIZE;
81630 +#endif
81631 +
81632 + pax_task_size -= PAGE_SIZE;
81633 +
81634 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
81635 + old_len > pax_task_size || addr > pax_task_size-old_len)
81636 + goto out;
81637 +
81638 if (flags & MREMAP_FIXED) {
81639 if (flags & MREMAP_MAYMOVE)
81640 ret = mremap_to(addr, old_len, new_addr, new_len);
81641 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81642 addr + new_len);
81643 }
81644 ret = addr;
81645 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
81646 goto out;
81647 }
81648 }
81649 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81650 goto out;
81651 }
81652
81653 + map_flags = vma->vm_flags;
81654 ret = move_vma(vma, addr, old_len, new_len, new_addr);
81655 + if (!(ret & ~PAGE_MASK)) {
81656 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
81657 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
81658 + }
81659 }
81660 out:
81661 if (ret & ~PAGE_MASK)
81662 diff --git a/mm/nommu.c b/mm/nommu.c
81663 index 79c3cac..4d357e0 100644
81664 --- a/mm/nommu.c
81665 +++ b/mm/nommu.c
81666 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
81667 int sysctl_overcommit_ratio = 50; /* default is 50% */
81668 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
81669 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
81670 -int heap_stack_gap = 0;
81671
81672 atomic_long_t mmap_pages_allocated;
81673
81674 @@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
81675 EXPORT_SYMBOL(find_vma);
81676
81677 /*
81678 - * find a VMA
81679 - * - we don't extend stack VMAs under NOMMU conditions
81680 - */
81681 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
81682 -{
81683 - return find_vma(mm, addr);
81684 -}
81685 -
81686 -/*
81687 * expand a stack to a given address
81688 * - not supported under NOMMU conditions
81689 */
81690 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81691
81692 /* most fields are the same, copy all, and then fixup */
81693 *new = *vma;
81694 + INIT_LIST_HEAD(&new->anon_vma_chain);
81695 *region = *vma->vm_region;
81696 new->vm_region = region;
81697
81698 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
81699 index 0713bfb..e3774e0 100644
81700 --- a/mm/page-writeback.c
81701 +++ b/mm/page-writeback.c
81702 @@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
81703 }
81704 }
81705
81706 -static struct notifier_block __cpuinitdata ratelimit_nb = {
81707 +static struct notifier_block ratelimit_nb = {
81708 .notifier_call = ratelimit_handler,
81709 .next = NULL,
81710 };
81711 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
81712 index 6a83cd3..3ab04ef 100644
81713 --- a/mm/page_alloc.c
81714 +++ b/mm/page_alloc.c
81715 @@ -58,6 +58,7 @@
81716 #include <linux/prefetch.h>
81717 #include <linux/migrate.h>
81718 #include <linux/page-debug-flags.h>
81719 +#include <linux/random.h>
81720
81721 #include <asm/tlbflush.h>
81722 #include <asm/div64.h>
81723 @@ -338,7 +339,7 @@ out:
81724 * This usage means that zero-order pages may not be compound.
81725 */
81726
81727 -static void free_compound_page(struct page *page)
81728 +void free_compound_page(struct page *page)
81729 {
81730 __free_pages_ok(page, compound_order(page));
81731 }
81732 @@ -693,6 +694,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
81733 int i;
81734 int bad = 0;
81735
81736 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81737 + unsigned long index = 1UL << order;
81738 +#endif
81739 +
81740 trace_mm_page_free(page, order);
81741 kmemcheck_free_shadow(page, order);
81742
81743 @@ -708,6 +713,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
81744 debug_check_no_obj_freed(page_address(page),
81745 PAGE_SIZE << order);
81746 }
81747 +
81748 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81749 + for (; index; --index)
81750 + sanitize_highpage(page + index - 1);
81751 +#endif
81752 +
81753 arch_free_page(page, order);
81754 kernel_map_pages(page, 1 << order, 0);
81755
81756 @@ -730,6 +741,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
81757 local_irq_restore(flags);
81758 }
81759
81760 +#ifdef CONFIG_PAX_LATENT_ENTROPY
81761 +bool __meminitdata extra_latent_entropy;
81762 +
81763 +static int __init setup_pax_extra_latent_entropy(char *str)
81764 +{
81765 + extra_latent_entropy = true;
81766 + return 0;
81767 +}
81768 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
81769 +
81770 +volatile u64 latent_entropy;
81771 +#endif
81772 +
81773 /*
81774 * Read access to zone->managed_pages is safe because it's unsigned long,
81775 * but we still need to serialize writers. Currently all callers of
81776 @@ -752,6 +776,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
81777 set_page_count(p, 0);
81778 }
81779
81780 +#ifdef CONFIG_PAX_LATENT_ENTROPY
81781 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
81782 + u64 hash = 0;
81783 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
81784 + const u64 *data = lowmem_page_address(page);
81785 +
81786 + for (index = 0; index < end; index++)
81787 + hash ^= hash + data[index];
81788 + latent_entropy ^= hash;
81789 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81790 + }
81791 +#endif
81792 +
81793 page_zone(page)->managed_pages += 1 << order;
81794 set_page_refcounted(page);
81795 __free_pages(page, order);
81796 @@ -861,8 +898,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
81797 arch_alloc_page(page, order);
81798 kernel_map_pages(page, 1 << order, 1);
81799
81800 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
81801 if (gfp_flags & __GFP_ZERO)
81802 prep_zero_page(page, order, gfp_flags);
81803 +#endif
81804
81805 if (order && (gfp_flags & __GFP_COMP))
81806 prep_compound_page(page, order);
81807 @@ -3752,7 +3791,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
81808 unsigned long pfn;
81809
81810 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
81811 +#ifdef CONFIG_X86_32
81812 + /* boot failures in VMware 8 on 32bit vanilla since
81813 + this change */
81814 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
81815 +#else
81816 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
81817 +#endif
81818 return 1;
81819 }
81820 return 0;
81821 diff --git a/mm/percpu.c b/mm/percpu.c
81822 index 8c8e08f..73a5cda 100644
81823 --- a/mm/percpu.c
81824 +++ b/mm/percpu.c
81825 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
81826 static unsigned int pcpu_high_unit_cpu __read_mostly;
81827
81828 /* the address of the first chunk which starts with the kernel static area */
81829 -void *pcpu_base_addr __read_mostly;
81830 +void *pcpu_base_addr __read_only;
81831 EXPORT_SYMBOL_GPL(pcpu_base_addr);
81832
81833 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
81834 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
81835 index fd26d04..0cea1b0 100644
81836 --- a/mm/process_vm_access.c
81837 +++ b/mm/process_vm_access.c
81838 @@ -13,6 +13,7 @@
81839 #include <linux/uio.h>
81840 #include <linux/sched.h>
81841 #include <linux/highmem.h>
81842 +#include <linux/security.h>
81843 #include <linux/ptrace.h>
81844 #include <linux/slab.h>
81845 #include <linux/syscalls.h>
81846 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
81847 size_t iov_l_curr_offset = 0;
81848 ssize_t iov_len;
81849
81850 + return -ENOSYS; // PaX: until properly audited
81851 +
81852 /*
81853 * Work out how many pages of struct pages we're going to need
81854 * when eventually calling get_user_pages
81855 */
81856 for (i = 0; i < riovcnt; i++) {
81857 iov_len = rvec[i].iov_len;
81858 - if (iov_len > 0) {
81859 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
81860 - + iov_len)
81861 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
81862 - / PAGE_SIZE + 1;
81863 - nr_pages = max(nr_pages, nr_pages_iov);
81864 - }
81865 + if (iov_len <= 0)
81866 + continue;
81867 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
81868 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
81869 + nr_pages = max(nr_pages, nr_pages_iov);
81870 }
81871
81872 if (nr_pages == 0)
81873 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
81874 goto free_proc_pages;
81875 }
81876
81877 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
81878 + rc = -EPERM;
81879 + goto put_task_struct;
81880 + }
81881 +
81882 mm = mm_access(task, PTRACE_MODE_ATTACH);
81883 if (!mm || IS_ERR(mm)) {
81884 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
81885 diff --git a/mm/rmap.c b/mm/rmap.c
81886 index 2c78f8c..9e9c624 100644
81887 --- a/mm/rmap.c
81888 +++ b/mm/rmap.c
81889 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81890 struct anon_vma *anon_vma = vma->anon_vma;
81891 struct anon_vma_chain *avc;
81892
81893 +#ifdef CONFIG_PAX_SEGMEXEC
81894 + struct anon_vma_chain *avc_m = NULL;
81895 +#endif
81896 +
81897 might_sleep();
81898 if (unlikely(!anon_vma)) {
81899 struct mm_struct *mm = vma->vm_mm;
81900 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81901 if (!avc)
81902 goto out_enomem;
81903
81904 +#ifdef CONFIG_PAX_SEGMEXEC
81905 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
81906 + if (!avc_m)
81907 + goto out_enomem_free_avc;
81908 +#endif
81909 +
81910 anon_vma = find_mergeable_anon_vma(vma);
81911 allocated = NULL;
81912 if (!anon_vma) {
81913 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81914 /* page_table_lock to protect against threads */
81915 spin_lock(&mm->page_table_lock);
81916 if (likely(!vma->anon_vma)) {
81917 +
81918 +#ifdef CONFIG_PAX_SEGMEXEC
81919 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
81920 +
81921 + if (vma_m) {
81922 + BUG_ON(vma_m->anon_vma);
81923 + vma_m->anon_vma = anon_vma;
81924 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
81925 + avc_m = NULL;
81926 + }
81927 +#endif
81928 +
81929 vma->anon_vma = anon_vma;
81930 anon_vma_chain_link(vma, avc, anon_vma);
81931 allocated = NULL;
81932 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81933
81934 if (unlikely(allocated))
81935 put_anon_vma(allocated);
81936 +
81937 +#ifdef CONFIG_PAX_SEGMEXEC
81938 + if (unlikely(avc_m))
81939 + anon_vma_chain_free(avc_m);
81940 +#endif
81941 +
81942 if (unlikely(avc))
81943 anon_vma_chain_free(avc);
81944 }
81945 return 0;
81946
81947 out_enomem_free_avc:
81948 +
81949 +#ifdef CONFIG_PAX_SEGMEXEC
81950 + if (avc_m)
81951 + anon_vma_chain_free(avc_m);
81952 +#endif
81953 +
81954 anon_vma_chain_free(avc);
81955 out_enomem:
81956 return -ENOMEM;
81957 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
81958 * Attach the anon_vmas from src to dst.
81959 * Returns 0 on success, -ENOMEM on failure.
81960 */
81961 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
81962 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
81963 {
81964 struct anon_vma_chain *avc, *pavc;
81965 struct anon_vma *root = NULL;
81966 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
81967 * the corresponding VMA in the parent process is attached to.
81968 * Returns 0 on success, non-zero on failure.
81969 */
81970 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
81971 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
81972 {
81973 struct anon_vma_chain *avc;
81974 struct anon_vma *anon_vma;
81975 diff --git a/mm/shmem.c b/mm/shmem.c
81976 index efd0b3a..994b702 100644
81977 --- a/mm/shmem.c
81978 +++ b/mm/shmem.c
81979 @@ -31,7 +31,7 @@
81980 #include <linux/export.h>
81981 #include <linux/swap.h>
81982
81983 -static struct vfsmount *shm_mnt;
81984 +struct vfsmount *shm_mnt;
81985
81986 #ifdef CONFIG_SHMEM
81987 /*
81988 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
81989 #define BOGO_DIRENT_SIZE 20
81990
81991 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
81992 -#define SHORT_SYMLINK_LEN 128
81993 +#define SHORT_SYMLINK_LEN 64
81994
81995 /*
81996 * shmem_fallocate and shmem_writepage communicate via inode->i_private
81997 @@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
81998 static int shmem_xattr_validate(const char *name)
81999 {
82000 struct { const char *prefix; size_t len; } arr[] = {
82001 +
82002 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82003 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
82004 +#endif
82005 +
82006 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
82007 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
82008 };
82009 @@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
82010 if (err)
82011 return err;
82012
82013 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82014 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
82015 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
82016 + return -EOPNOTSUPP;
82017 + if (size > 8)
82018 + return -EINVAL;
82019 + }
82020 +#endif
82021 +
82022 return simple_xattr_set(&info->xattrs, name, value, size, flags);
82023 }
82024
82025 @@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
82026 int err = -ENOMEM;
82027
82028 /* Round up to L1_CACHE_BYTES to resist false sharing */
82029 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
82030 - L1_CACHE_BYTES), GFP_KERNEL);
82031 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
82032 if (!sbinfo)
82033 return -ENOMEM;
82034
82035 diff --git a/mm/slab.c b/mm/slab.c
82036 index e7667a3..b62c169 100644
82037 --- a/mm/slab.c
82038 +++ b/mm/slab.c
82039 @@ -306,7 +306,7 @@ struct kmem_list3 {
82040 * Need this for bootstrapping a per node allocator.
82041 */
82042 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
82043 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
82044 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
82045 #define CACHE_CACHE 0
82046 #define SIZE_AC MAX_NUMNODES
82047 #define SIZE_L3 (2 * MAX_NUMNODES)
82048 @@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
82049 if ((x)->max_freeable < i) \
82050 (x)->max_freeable = i; \
82051 } while (0)
82052 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
82053 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
82054 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
82055 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
82056 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
82057 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
82058 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
82059 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
82060 #else
82061 #define STATS_INC_ACTIVE(x) do { } while (0)
82062 #define STATS_DEC_ACTIVE(x) do { } while (0)
82063 @@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
82064 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
82065 */
82066 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
82067 - const struct slab *slab, void *obj)
82068 + const struct slab *slab, const void *obj)
82069 {
82070 u32 offset = (obj - slab->s_mem);
82071 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
82072 @@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
82073 struct cache_names {
82074 char *name;
82075 char *name_dma;
82076 + char *name_usercopy;
82077 };
82078
82079 static struct cache_names __initdata cache_names[] = {
82080 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
82081 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
82082 #include <linux/kmalloc_sizes.h>
82083 - {NULL,}
82084 + {NULL}
82085 #undef CACHE
82086 };
82087
82088 @@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
82089 if (unlikely(gfpflags & GFP_DMA))
82090 return csizep->cs_dmacachep;
82091 #endif
82092 +
82093 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82094 + if (unlikely(gfpflags & GFP_USERCOPY))
82095 + return csizep->cs_usercopycachep;
82096 +#endif
82097 +
82098 return csizep->cs_cachep;
82099 }
82100
82101 @@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
82102 return notifier_from_errno(err);
82103 }
82104
82105 -static struct notifier_block __cpuinitdata cpucache_notifier = {
82106 +static struct notifier_block cpucache_notifier = {
82107 &cpuup_callback, NULL, 0
82108 };
82109
82110 @@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
82111 */
82112
82113 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
82114 - sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
82115 + sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82116
82117 if (INDEX_AC != INDEX_L3)
82118 sizes[INDEX_L3].cs_cachep =
82119 create_kmalloc_cache(names[INDEX_L3].name,
82120 - sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
82121 + sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82122
82123 slab_early_init = 0;
82124
82125 @@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
82126 */
82127 if (!sizes->cs_cachep)
82128 sizes->cs_cachep = create_kmalloc_cache(names->name,
82129 - sizes->cs_size, ARCH_KMALLOC_FLAGS);
82130 + sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82131
82132 #ifdef CONFIG_ZONE_DMA
82133 sizes->cs_dmacachep = create_kmalloc_cache(
82134 names->name_dma, sizes->cs_size,
82135 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
82136 #endif
82137 +
82138 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82139 + sizes->cs_usercopycachep = create_kmalloc_cache(
82140 + names->name_usercopy, sizes->cs_size,
82141 + ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82142 +#endif
82143 +
82144 sizes++;
82145 names++;
82146 }
82147 @@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
82148 }
82149 /* cpu stats */
82150 {
82151 - unsigned long allochit = atomic_read(&cachep->allochit);
82152 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
82153 - unsigned long freehit = atomic_read(&cachep->freehit);
82154 - unsigned long freemiss = atomic_read(&cachep->freemiss);
82155 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
82156 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
82157 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
82158 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
82159
82160 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
82161 allochit, allocmiss, freehit, freemiss);
82162 @@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
82163 static int __init slab_proc_init(void)
82164 {
82165 #ifdef CONFIG_DEBUG_SLAB_LEAK
82166 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
82167 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
82168 #endif
82169 return 0;
82170 }
82171 module_init(slab_proc_init);
82172 #endif
82173
82174 +bool is_usercopy_object(const void *ptr)
82175 +{
82176 + struct page *page;
82177 + struct kmem_cache *cachep;
82178 +
82179 + if (ZERO_OR_NULL_PTR(ptr))
82180 + return false;
82181 +
82182 + if (!slab_is_available())
82183 + return false;
82184 +
82185 + if (!virt_addr_valid(ptr))
82186 + return false;
82187 +
82188 + page = virt_to_head_page(ptr);
82189 +
82190 + if (!PageSlab(page))
82191 + return false;
82192 +
82193 + cachep = page->slab_cache;
82194 + return cachep->flags & SLAB_USERCOPY;
82195 +}
82196 +
82197 +#ifdef CONFIG_PAX_USERCOPY
82198 +const char *check_heap_object(const void *ptr, unsigned long n)
82199 +{
82200 + struct page *page;
82201 + struct kmem_cache *cachep;
82202 + struct slab *slabp;
82203 + unsigned int objnr;
82204 + unsigned long offset;
82205 +
82206 + if (ZERO_OR_NULL_PTR(ptr))
82207 + return "<null>";
82208 +
82209 + if (!virt_addr_valid(ptr))
82210 + return NULL;
82211 +
82212 + page = virt_to_head_page(ptr);
82213 +
82214 + if (!PageSlab(page))
82215 + return NULL;
82216 +
82217 + cachep = page->slab_cache;
82218 + if (!(cachep->flags & SLAB_USERCOPY))
82219 + return cachep->name;
82220 +
82221 + slabp = page->slab_page;
82222 + objnr = obj_to_index(cachep, slabp, ptr);
82223 + BUG_ON(objnr >= cachep->num);
82224 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
82225 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
82226 + return NULL;
82227 +
82228 + return cachep->name;
82229 +}
82230 +#endif
82231 +
82232 /**
82233 * ksize - get the actual amount of memory allocated for a given object
82234 * @objp: Pointer to the object
82235 diff --git a/mm/slab.h b/mm/slab.h
82236 index 34a98d6..73633d1 100644
82237 --- a/mm/slab.h
82238 +++ b/mm/slab.h
82239 @@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82240
82241 /* Legal flag mask for kmem_cache_create(), for various configurations */
82242 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
82243 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
82244 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
82245
82246 #if defined(CONFIG_DEBUG_SLAB)
82247 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
82248 @@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
82249 return s;
82250
82251 page = virt_to_head_page(x);
82252 +
82253 + BUG_ON(!PageSlab(page));
82254 +
82255 cachep = page->slab_cache;
82256 if (slab_equal_or_root(cachep, s))
82257 return cachep;
82258 diff --git a/mm/slab_common.c b/mm/slab_common.c
82259 index 3f3cd97..93b0236 100644
82260 --- a/mm/slab_common.c
82261 +++ b/mm/slab_common.c
82262 @@ -22,7 +22,7 @@
82263
82264 #include "slab.h"
82265
82266 -enum slab_state slab_state;
82267 +enum slab_state slab_state __read_only;
82268 LIST_HEAD(slab_caches);
82269 DEFINE_MUTEX(slab_mutex);
82270 struct kmem_cache *kmem_cache;
82271 @@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
82272
82273 err = __kmem_cache_create(s, flags);
82274 if (!err) {
82275 - s->refcount = 1;
82276 + atomic_set(&s->refcount, 1);
82277 list_add(&s->list, &slab_caches);
82278 memcg_cache_list_add(memcg, s);
82279 } else {
82280 @@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
82281
82282 get_online_cpus();
82283 mutex_lock(&slab_mutex);
82284 - s->refcount--;
82285 - if (!s->refcount) {
82286 + if (atomic_dec_and_test(&s->refcount)) {
82287 list_del(&s->list);
82288
82289 if (!__kmem_cache_shutdown(s)) {
82290 @@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
82291 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
82292 name, size, err);
82293
82294 - s->refcount = -1; /* Exempt from merging for now */
82295 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
82296 }
82297
82298 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
82299 @@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
82300
82301 create_boot_cache(s, name, size, flags);
82302 list_add(&s->list, &slab_caches);
82303 - s->refcount = 1;
82304 + atomic_set(&s->refcount, 1);
82305 return s;
82306 }
82307
82308 diff --git a/mm/slob.c b/mm/slob.c
82309 index a99fdf7..f5b6577 100644
82310 --- a/mm/slob.c
82311 +++ b/mm/slob.c
82312 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
82313 /*
82314 * Return the size of a slob block.
82315 */
82316 -static slobidx_t slob_units(slob_t *s)
82317 +static slobidx_t slob_units(const slob_t *s)
82318 {
82319 if (s->units > 0)
82320 return s->units;
82321 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
82322 /*
82323 * Return the next free slob block pointer after this one.
82324 */
82325 -static slob_t *slob_next(slob_t *s)
82326 +static slob_t *slob_next(const slob_t *s)
82327 {
82328 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
82329 slobidx_t next;
82330 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
82331 /*
82332 * Returns true if s is the last free block in its page.
82333 */
82334 -static int slob_last(slob_t *s)
82335 +static int slob_last(const slob_t *s)
82336 {
82337 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
82338 }
82339
82340 -static void *slob_new_pages(gfp_t gfp, int order, int node)
82341 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
82342 {
82343 - void *page;
82344 + struct page *page;
82345
82346 #ifdef CONFIG_NUMA
82347 if (node != NUMA_NO_NODE)
82348 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
82349 if (!page)
82350 return NULL;
82351
82352 - return page_address(page);
82353 + __SetPageSlab(page);
82354 + return page;
82355 }
82356
82357 -static void slob_free_pages(void *b, int order)
82358 +static void slob_free_pages(struct page *sp, int order)
82359 {
82360 if (current->reclaim_state)
82361 current->reclaim_state->reclaimed_slab += 1 << order;
82362 - free_pages((unsigned long)b, order);
82363 + __ClearPageSlab(sp);
82364 + reset_page_mapcount(sp);
82365 + sp->private = 0;
82366 + __free_pages(sp, order);
82367 }
82368
82369 /*
82370 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
82371
82372 /* Not enough space: must allocate a new page */
82373 if (!b) {
82374 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
82375 - if (!b)
82376 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
82377 + if (!sp)
82378 return NULL;
82379 - sp = virt_to_page(b);
82380 - __SetPageSlab(sp);
82381 + b = page_address(sp);
82382
82383 spin_lock_irqsave(&slob_lock, flags);
82384 sp->units = SLOB_UNITS(PAGE_SIZE);
82385 sp->freelist = b;
82386 + sp->private = 0;
82387 INIT_LIST_HEAD(&sp->list);
82388 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
82389 set_slob_page_free(sp, slob_list);
82390 @@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
82391 if (slob_page_free(sp))
82392 clear_slob_page_free(sp);
82393 spin_unlock_irqrestore(&slob_lock, flags);
82394 - __ClearPageSlab(sp);
82395 - reset_page_mapcount(sp);
82396 - slob_free_pages(b, 0);
82397 + slob_free_pages(sp, 0);
82398 return;
82399 }
82400
82401 @@ -424,11 +426,10 @@ out:
82402 */
82403
82404 static __always_inline void *
82405 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82406 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
82407 {
82408 - unsigned int *m;
82409 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82410 - void *ret;
82411 + slob_t *m;
82412 + void *ret = NULL;
82413
82414 gfp &= gfp_allowed_mask;
82415
82416 @@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82417
82418 if (!m)
82419 return NULL;
82420 - *m = size;
82421 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
82422 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
82423 + m[0].units = size;
82424 + m[1].units = align;
82425 ret = (void *)m + align;
82426
82427 trace_kmalloc_node(caller, ret,
82428 size, size + align, gfp, node);
82429 } else {
82430 unsigned int order = get_order(size);
82431 + struct page *page;
82432
82433 if (likely(order))
82434 gfp |= __GFP_COMP;
82435 - ret = slob_new_pages(gfp, order, node);
82436 + page = slob_new_pages(gfp, order, node);
82437 + if (page) {
82438 + ret = page_address(page);
82439 + page->private = size;
82440 + }
82441
82442 trace_kmalloc_node(caller, ret,
82443 size, PAGE_SIZE << order, gfp, node);
82444 }
82445
82446 - kmemleak_alloc(ret, size, 1, gfp);
82447 + return ret;
82448 +}
82449 +
82450 +static __always_inline void *
82451 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82452 +{
82453 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82454 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
82455 +
82456 + if (!ZERO_OR_NULL_PTR(ret))
82457 + kmemleak_alloc(ret, size, 1, gfp);
82458 return ret;
82459 }
82460
82461 @@ -494,33 +513,110 @@ void kfree(const void *block)
82462 kmemleak_free(block);
82463
82464 sp = virt_to_page(block);
82465 - if (PageSlab(sp)) {
82466 + VM_BUG_ON(!PageSlab(sp));
82467 + if (!sp->private) {
82468 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82469 - unsigned int *m = (unsigned int *)(block - align);
82470 - slob_free(m, *m + align);
82471 - } else
82472 + slob_t *m = (slob_t *)(block - align);
82473 + slob_free(m, m[0].units + align);
82474 + } else {
82475 + __ClearPageSlab(sp);
82476 + reset_page_mapcount(sp);
82477 + sp->private = 0;
82478 __free_pages(sp, compound_order(sp));
82479 + }
82480 }
82481 EXPORT_SYMBOL(kfree);
82482
82483 +bool is_usercopy_object(const void *ptr)
82484 +{
82485 + if (!slab_is_available())
82486 + return false;
82487 +
82488 + // PAX: TODO
82489 +
82490 + return false;
82491 +}
82492 +
82493 +#ifdef CONFIG_PAX_USERCOPY
82494 +const char *check_heap_object(const void *ptr, unsigned long n)
82495 +{
82496 + struct page *page;
82497 + const slob_t *free;
82498 + const void *base;
82499 + unsigned long flags;
82500 +
82501 + if (ZERO_OR_NULL_PTR(ptr))
82502 + return "<null>";
82503 +
82504 + if (!virt_addr_valid(ptr))
82505 + return NULL;
82506 +
82507 + page = virt_to_head_page(ptr);
82508 + if (!PageSlab(page))
82509 + return NULL;
82510 +
82511 + if (page->private) {
82512 + base = page;
82513 + if (base <= ptr && n <= page->private - (ptr - base))
82514 + return NULL;
82515 + return "<slob>";
82516 + }
82517 +
82518 + /* some tricky double walking to find the chunk */
82519 + spin_lock_irqsave(&slob_lock, flags);
82520 + base = (void *)((unsigned long)ptr & PAGE_MASK);
82521 + free = page->freelist;
82522 +
82523 + while (!slob_last(free) && (void *)free <= ptr) {
82524 + base = free + slob_units(free);
82525 + free = slob_next(free);
82526 + }
82527 +
82528 + while (base < (void *)free) {
82529 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
82530 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
82531 + int offset;
82532 +
82533 + if (ptr < base + align)
82534 + break;
82535 +
82536 + offset = ptr - base - align;
82537 + if (offset >= m) {
82538 + base += size;
82539 + continue;
82540 + }
82541 +
82542 + if (n > m - offset)
82543 + break;
82544 +
82545 + spin_unlock_irqrestore(&slob_lock, flags);
82546 + return NULL;
82547 + }
82548 +
82549 + spin_unlock_irqrestore(&slob_lock, flags);
82550 + return "<slob>";
82551 +}
82552 +#endif
82553 +
82554 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
82555 size_t ksize(const void *block)
82556 {
82557 struct page *sp;
82558 int align;
82559 - unsigned int *m;
82560 + slob_t *m;
82561
82562 BUG_ON(!block);
82563 if (unlikely(block == ZERO_SIZE_PTR))
82564 return 0;
82565
82566 sp = virt_to_page(block);
82567 - if (unlikely(!PageSlab(sp)))
82568 - return PAGE_SIZE << compound_order(sp);
82569 + VM_BUG_ON(!PageSlab(sp));
82570 + if (sp->private)
82571 + return sp->private;
82572
82573 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82574 - m = (unsigned int *)(block - align);
82575 - return SLOB_UNITS(*m) * SLOB_UNIT;
82576 + m = (slob_t *)(block - align);
82577 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
82578 }
82579 EXPORT_SYMBOL(ksize);
82580
82581 @@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
82582
82583 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
82584 {
82585 - void *b;
82586 + void *b = NULL;
82587
82588 flags &= gfp_allowed_mask;
82589
82590 lockdep_trace_alloc(flags);
82591
82592 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82593 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
82594 +#else
82595 if (c->size < PAGE_SIZE) {
82596 b = slob_alloc(c->size, flags, c->align, node);
82597 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
82598 SLOB_UNITS(c->size) * SLOB_UNIT,
82599 flags, node);
82600 } else {
82601 - b = slob_new_pages(flags, get_order(c->size), node);
82602 + struct page *sp;
82603 +
82604 + sp = slob_new_pages(flags, get_order(c->size), node);
82605 + if (sp) {
82606 + b = page_address(sp);
82607 + sp->private = c->size;
82608 + }
82609 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
82610 PAGE_SIZE << get_order(c->size),
82611 flags, node);
82612 }
82613 +#endif
82614
82615 if (c->ctor)
82616 c->ctor(b);
82617 @@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
82618
82619 static void __kmem_cache_free(void *b, int size)
82620 {
82621 - if (size < PAGE_SIZE)
82622 + struct page *sp;
82623 +
82624 + sp = virt_to_page(b);
82625 + BUG_ON(!PageSlab(sp));
82626 + if (!sp->private)
82627 slob_free(b, size);
82628 else
82629 - slob_free_pages(b, get_order(size));
82630 + slob_free_pages(sp, get_order(size));
82631 }
82632
82633 static void kmem_rcu_free(struct rcu_head *head)
82634 @@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
82635
82636 void kmem_cache_free(struct kmem_cache *c, void *b)
82637 {
82638 + int size = c->size;
82639 +
82640 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82641 + if (size + c->align < PAGE_SIZE) {
82642 + size += c->align;
82643 + b -= c->align;
82644 + }
82645 +#endif
82646 +
82647 kmemleak_free_recursive(b, c->flags);
82648 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
82649 struct slob_rcu *slob_rcu;
82650 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
82651 - slob_rcu->size = c->size;
82652 + slob_rcu = b + (size - sizeof(struct slob_rcu));
82653 + slob_rcu->size = size;
82654 call_rcu(&slob_rcu->head, kmem_rcu_free);
82655 } else {
82656 - __kmem_cache_free(b, c->size);
82657 + __kmem_cache_free(b, size);
82658 }
82659
82660 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82661 + trace_kfree(_RET_IP_, b);
82662 +#else
82663 trace_kmem_cache_free(_RET_IP_, b);
82664 +#endif
82665 +
82666 }
82667 EXPORT_SYMBOL(kmem_cache_free);
82668
82669 diff --git a/mm/slub.c b/mm/slub.c
82670 index ba2ca53..00b1f4e 100644
82671 --- a/mm/slub.c
82672 +++ b/mm/slub.c
82673 @@ -197,7 +197,7 @@ struct track {
82674
82675 enum track_item { TRACK_ALLOC, TRACK_FREE };
82676
82677 -#ifdef CONFIG_SYSFS
82678 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82679 static int sysfs_slab_add(struct kmem_cache *);
82680 static int sysfs_slab_alias(struct kmem_cache *, const char *);
82681 static void sysfs_slab_remove(struct kmem_cache *);
82682 @@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
82683 if (!t->addr)
82684 return;
82685
82686 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
82687 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
82688 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
82689 #ifdef CONFIG_STACKTRACE
82690 {
82691 @@ -2653,7 +2653,7 @@ static int slub_min_objects;
82692 * Merge control. If this is set then no merging of slab caches will occur.
82693 * (Could be removed. This was introduced to pacify the merge skeptics.)
82694 */
82695 -static int slub_nomerge;
82696 +static int slub_nomerge = 1;
82697
82698 /*
82699 * Calculate the order of allocation given an slab object size.
82700 @@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
82701 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
82702 #endif
82703
82704 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82705 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
82706 +#endif
82707 +
82708 static int __init setup_slub_min_order(char *str)
82709 {
82710 get_option(&str, &slub_min_order);
82711 @@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
82712 return kmalloc_dma_caches[index];
82713
82714 #endif
82715 +
82716 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82717 + if (flags & SLAB_USERCOPY)
82718 + return kmalloc_usercopy_caches[index];
82719 +
82720 +#endif
82721 +
82722 return kmalloc_caches[index];
82723 }
82724
82725 @@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
82726 EXPORT_SYMBOL(__kmalloc_node);
82727 #endif
82728
82729 +bool is_usercopy_object(const void *ptr)
82730 +{
82731 + struct page *page;
82732 + struct kmem_cache *s;
82733 +
82734 + if (ZERO_OR_NULL_PTR(ptr))
82735 + return false;
82736 +
82737 + if (!slab_is_available())
82738 + return false;
82739 +
82740 + if (!virt_addr_valid(ptr))
82741 + return false;
82742 +
82743 + page = virt_to_head_page(ptr);
82744 +
82745 + if (!PageSlab(page))
82746 + return false;
82747 +
82748 + s = page->slab_cache;
82749 + return s->flags & SLAB_USERCOPY;
82750 +}
82751 +
82752 +#ifdef CONFIG_PAX_USERCOPY
82753 +const char *check_heap_object(const void *ptr, unsigned long n)
82754 +{
82755 + struct page *page;
82756 + struct kmem_cache *s;
82757 + unsigned long offset;
82758 +
82759 + if (ZERO_OR_NULL_PTR(ptr))
82760 + return "<null>";
82761 +
82762 + if (!virt_addr_valid(ptr))
82763 + return NULL;
82764 +
82765 + page = virt_to_head_page(ptr);
82766 +
82767 + if (!PageSlab(page))
82768 + return NULL;
82769 +
82770 + s = page->slab_cache;
82771 + if (!(s->flags & SLAB_USERCOPY))
82772 + return s->name;
82773 +
82774 + offset = (ptr - page_address(page)) % s->size;
82775 + if (offset <= s->object_size && n <= s->object_size - offset)
82776 + return NULL;
82777 +
82778 + return s->name;
82779 +}
82780 +#endif
82781 +
82782 size_t ksize(const void *object)
82783 {
82784 struct page *page;
82785 @@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
82786
82787 /* Caches that are not of the two-to-the-power-of size */
82788 if (KMALLOC_MIN_SIZE <= 32) {
82789 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
82790 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
82791 caches++;
82792 }
82793
82794 if (KMALLOC_MIN_SIZE <= 64) {
82795 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
82796 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
82797 caches++;
82798 }
82799
82800 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
82801 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
82802 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
82803 caches++;
82804 }
82805
82806 @@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
82807 }
82808 }
82809 #endif
82810 +
82811 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82812 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
82813 + struct kmem_cache *s = kmalloc_caches[i];
82814 +
82815 + if (s && s->size) {
82816 + char *name = kasprintf(GFP_NOWAIT,
82817 + "usercopy-kmalloc-%d", s->object_size);
82818 +
82819 + BUG_ON(!name);
82820 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
82821 + s->object_size, SLAB_USERCOPY);
82822 + }
82823 + }
82824 +#endif
82825 +
82826 printk(KERN_INFO
82827 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
82828 " CPUs=%d, Nodes=%d\n",
82829 @@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
82830 /*
82831 * We may have set a slab to be unmergeable during bootstrap.
82832 */
82833 - if (s->refcount < 0)
82834 + if (atomic_read(&s->refcount) < 0)
82835 return 1;
82836
82837 return 0;
82838 @@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82839
82840 s = find_mergeable(memcg, size, align, flags, name, ctor);
82841 if (s) {
82842 - s->refcount++;
82843 + atomic_inc(&s->refcount);
82844 /*
82845 * Adjust the object sizes so that we clear
82846 * the complete object on kzalloc.
82847 @@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82848 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
82849
82850 if (sysfs_slab_alias(s, name)) {
82851 - s->refcount--;
82852 + atomic_dec(&s->refcount);
82853 s = NULL;
82854 }
82855 }
82856 @@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
82857 return NOTIFY_OK;
82858 }
82859
82860 -static struct notifier_block __cpuinitdata slab_notifier = {
82861 +static struct notifier_block slab_notifier = {
82862 .notifier_call = slab_cpuup_callback
82863 };
82864
82865 @@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
82866 }
82867 #endif
82868
82869 -#ifdef CONFIG_SYSFS
82870 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82871 static int count_inuse(struct page *page)
82872 {
82873 return page->inuse;
82874 @@ -4364,12 +4444,12 @@ static void resiliency_test(void)
82875 validate_slab_cache(kmalloc_caches[9]);
82876 }
82877 #else
82878 -#ifdef CONFIG_SYSFS
82879 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82880 static void resiliency_test(void) {};
82881 #endif
82882 #endif
82883
82884 -#ifdef CONFIG_SYSFS
82885 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82886 enum slab_stat_type {
82887 SL_ALL, /* All slabs */
82888 SL_PARTIAL, /* Only partially allocated slabs */
82889 @@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
82890
82891 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
82892 {
82893 - return sprintf(buf, "%d\n", s->refcount - 1);
82894 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
82895 }
82896 SLAB_ATTR_RO(aliases);
82897
82898 @@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
82899 return name;
82900 }
82901
82902 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82903 static int sysfs_slab_add(struct kmem_cache *s)
82904 {
82905 int err;
82906 @@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
82907 kobject_del(&s->kobj);
82908 kobject_put(&s->kobj);
82909 }
82910 +#endif
82911
82912 /*
82913 * Need to buffer aliases during bootup until sysfs becomes
82914 @@ -5336,6 +5418,7 @@ struct saved_alias {
82915
82916 static struct saved_alias *alias_list;
82917
82918 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82919 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
82920 {
82921 struct saved_alias *al;
82922 @@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
82923 alias_list = al;
82924 return 0;
82925 }
82926 +#endif
82927
82928 static int __init slab_sysfs_init(void)
82929 {
82930 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
82931 index 1b7e22a..3fcd4f3 100644
82932 --- a/mm/sparse-vmemmap.c
82933 +++ b/mm/sparse-vmemmap.c
82934 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
82935 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
82936 if (!p)
82937 return NULL;
82938 - pud_populate(&init_mm, pud, p);
82939 + pud_populate_kernel(&init_mm, pud, p);
82940 }
82941 return pud;
82942 }
82943 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
82944 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
82945 if (!p)
82946 return NULL;
82947 - pgd_populate(&init_mm, pgd, p);
82948 + pgd_populate_kernel(&init_mm, pgd, p);
82949 }
82950 return pgd;
82951 }
82952 diff --git a/mm/sparse.c b/mm/sparse.c
82953 index 6b5fb76..db0c190 100644
82954 --- a/mm/sparse.c
82955 +++ b/mm/sparse.c
82956 @@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
82957
82958 for (i = 0; i < PAGES_PER_SECTION; i++) {
82959 if (PageHWPoison(&memmap[i])) {
82960 - atomic_long_sub(1, &mce_bad_pages);
82961 + atomic_long_sub_unchecked(1, &mce_bad_pages);
82962 ClearPageHWPoison(&memmap[i]);
82963 }
82964 }
82965 diff --git a/mm/swap.c b/mm/swap.c
82966 index 6310dc2..3662b3f 100644
82967 --- a/mm/swap.c
82968 +++ b/mm/swap.c
82969 @@ -30,6 +30,7 @@
82970 #include <linux/backing-dev.h>
82971 #include <linux/memcontrol.h>
82972 #include <linux/gfp.h>
82973 +#include <linux/hugetlb.h>
82974
82975 #include "internal.h"
82976
82977 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
82978
82979 __page_cache_release(page);
82980 dtor = get_compound_page_dtor(page);
82981 + if (!PageHuge(page))
82982 + BUG_ON(dtor != free_compound_page);
82983 (*dtor)(page);
82984 }
82985
82986 diff --git a/mm/swapfile.c b/mm/swapfile.c
82987 index e97a0e5..b50e796 100644
82988 --- a/mm/swapfile.c
82989 +++ b/mm/swapfile.c
82990 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
82991
82992 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
82993 /* Activity counter to indicate that a swapon or swapoff has occurred */
82994 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
82995 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
82996
82997 static inline unsigned char swap_count(unsigned char ent)
82998 {
82999 @@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
83000 }
83001 filp_close(swap_file, NULL);
83002 err = 0;
83003 - atomic_inc(&proc_poll_event);
83004 + atomic_inc_unchecked(&proc_poll_event);
83005 wake_up_interruptible(&proc_poll_wait);
83006
83007 out_dput:
83008 @@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
83009
83010 poll_wait(file, &proc_poll_wait, wait);
83011
83012 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
83013 - seq->poll_event = atomic_read(&proc_poll_event);
83014 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
83015 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83016 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
83017 }
83018
83019 @@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
83020 return ret;
83021
83022 seq = file->private_data;
83023 - seq->poll_event = atomic_read(&proc_poll_event);
83024 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83025 return 0;
83026 }
83027
83028 @@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
83029 (frontswap_map) ? "FS" : "");
83030
83031 mutex_unlock(&swapon_mutex);
83032 - atomic_inc(&proc_poll_event);
83033 + atomic_inc_unchecked(&proc_poll_event);
83034 wake_up_interruptible(&proc_poll_wait);
83035
83036 if (S_ISREG(inode->i_mode))
83037 diff --git a/mm/util.c b/mm/util.c
83038 index c55e26b..3f913a9 100644
83039 --- a/mm/util.c
83040 +++ b/mm/util.c
83041 @@ -292,6 +292,12 @@ done:
83042 void arch_pick_mmap_layout(struct mm_struct *mm)
83043 {
83044 mm->mmap_base = TASK_UNMAPPED_BASE;
83045 +
83046 +#ifdef CONFIG_PAX_RANDMMAP
83047 + if (mm->pax_flags & MF_PAX_RANDMMAP)
83048 + mm->mmap_base += mm->delta_mmap;
83049 +#endif
83050 +
83051 mm->get_unmapped_area = arch_get_unmapped_area;
83052 mm->unmap_area = arch_unmap_area;
83053 }
83054 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
83055 index 5123a16..f234a48 100644
83056 --- a/mm/vmalloc.c
83057 +++ b/mm/vmalloc.c
83058 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
83059
83060 pte = pte_offset_kernel(pmd, addr);
83061 do {
83062 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83063 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83064 +
83065 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83066 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
83067 + BUG_ON(!pte_exec(*pte));
83068 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
83069 + continue;
83070 + }
83071 +#endif
83072 +
83073 + {
83074 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83075 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83076 + }
83077 } while (pte++, addr += PAGE_SIZE, addr != end);
83078 }
83079
83080 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
83081 pte = pte_alloc_kernel(pmd, addr);
83082 if (!pte)
83083 return -ENOMEM;
83084 +
83085 + pax_open_kernel();
83086 do {
83087 struct page *page = pages[*nr];
83088
83089 - if (WARN_ON(!pte_none(*pte)))
83090 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83091 + if (pgprot_val(prot) & _PAGE_NX)
83092 +#endif
83093 +
83094 + if (!pte_none(*pte)) {
83095 + pax_close_kernel();
83096 + WARN_ON(1);
83097 return -EBUSY;
83098 - if (WARN_ON(!page))
83099 + }
83100 + if (!page) {
83101 + pax_close_kernel();
83102 + WARN_ON(1);
83103 return -ENOMEM;
83104 + }
83105 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
83106 (*nr)++;
83107 } while (pte++, addr += PAGE_SIZE, addr != end);
83108 + pax_close_kernel();
83109 return 0;
83110 }
83111
83112 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
83113 pmd_t *pmd;
83114 unsigned long next;
83115
83116 - pmd = pmd_alloc(&init_mm, pud, addr);
83117 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
83118 if (!pmd)
83119 return -ENOMEM;
83120 do {
83121 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
83122 pud_t *pud;
83123 unsigned long next;
83124
83125 - pud = pud_alloc(&init_mm, pgd, addr);
83126 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
83127 if (!pud)
83128 return -ENOMEM;
83129 do {
83130 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
83131 * and fall back on vmalloc() if that fails. Others
83132 * just put it in the vmalloc space.
83133 */
83134 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
83135 +#ifdef CONFIG_MODULES
83136 +#ifdef MODULES_VADDR
83137 unsigned long addr = (unsigned long)x;
83138 if (addr >= MODULES_VADDR && addr < MODULES_END)
83139 return 1;
83140 #endif
83141 +
83142 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83143 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
83144 + return 1;
83145 +#endif
83146 +
83147 +#endif
83148 +
83149 return is_vmalloc_addr(x);
83150 }
83151
83152 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
83153
83154 if (!pgd_none(*pgd)) {
83155 pud_t *pud = pud_offset(pgd, addr);
83156 +#ifdef CONFIG_X86
83157 + if (!pud_large(*pud))
83158 +#endif
83159 if (!pud_none(*pud)) {
83160 pmd_t *pmd = pmd_offset(pud, addr);
83161 +#ifdef CONFIG_X86
83162 + if (!pmd_large(*pmd))
83163 +#endif
83164 if (!pmd_none(*pmd)) {
83165 pte_t *ptep, pte;
83166
83167 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
83168 * Allocate a region of KVA of the specified size and alignment, within the
83169 * vstart and vend.
83170 */
83171 -static struct vmap_area *alloc_vmap_area(unsigned long size,
83172 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
83173 unsigned long align,
83174 unsigned long vstart, unsigned long vend,
83175 int node, gfp_t gfp_mask)
83176 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
83177 struct vm_struct *area;
83178
83179 BUG_ON(in_interrupt());
83180 +
83181 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83182 + if (flags & VM_KERNEXEC) {
83183 + if (start != VMALLOC_START || end != VMALLOC_END)
83184 + return NULL;
83185 + start = (unsigned long)MODULES_EXEC_VADDR;
83186 + end = (unsigned long)MODULES_EXEC_END;
83187 + }
83188 +#endif
83189 +
83190 if (flags & VM_IOREMAP) {
83191 int bit = fls(size);
83192
83193 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
83194 if (count > totalram_pages)
83195 return NULL;
83196
83197 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83198 + if (!(pgprot_val(prot) & _PAGE_NX))
83199 + flags |= VM_KERNEXEC;
83200 +#endif
83201 +
83202 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
83203 __builtin_return_address(0));
83204 if (!area)
83205 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
83206 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
83207 goto fail;
83208
83209 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83210 + if (!(pgprot_val(prot) & _PAGE_NX))
83211 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
83212 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
83213 + else
83214 +#endif
83215 +
83216 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
83217 start, end, node, gfp_mask, caller);
83218 if (!area)
83219 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
83220 * For tight control over page level allocator and protection flags
83221 * use __vmalloc() instead.
83222 */
83223 -
83224 void *vmalloc_exec(unsigned long size)
83225 {
83226 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
83227 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
83228 -1, __builtin_return_address(0));
83229 }
83230
83231 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
83232 unsigned long uaddr = vma->vm_start;
83233 unsigned long usize = vma->vm_end - vma->vm_start;
83234
83235 + BUG_ON(vma->vm_mirror);
83236 +
83237 if ((PAGE_SIZE-1) & (unsigned long)addr)
83238 return -EINVAL;
83239
83240 @@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
83241 v->addr, v->addr + v->size, v->size);
83242
83243 if (v->caller)
83244 +#ifdef CONFIG_GRKERNSEC_HIDESYM
83245 + seq_printf(m, " %pK", v->caller);
83246 +#else
83247 seq_printf(m, " %pS", v->caller);
83248 +#endif
83249
83250 if (v->nr_pages)
83251 seq_printf(m, " pages=%d", v->nr_pages);
83252 diff --git a/mm/vmstat.c b/mm/vmstat.c
83253 index 9800306..76b4b27 100644
83254 --- a/mm/vmstat.c
83255 +++ b/mm/vmstat.c
83256 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
83257 *
83258 * vm_stat contains the global counters
83259 */
83260 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
83261 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
83262 EXPORT_SYMBOL(vm_stat);
83263
83264 #ifdef CONFIG_SMP
83265 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
83266 v = p->vm_stat_diff[i];
83267 p->vm_stat_diff[i] = 0;
83268 local_irq_restore(flags);
83269 - atomic_long_add(v, &zone->vm_stat[i]);
83270 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
83271 global_diff[i] += v;
83272 #ifdef CONFIG_NUMA
83273 /* 3 seconds idle till flush */
83274 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
83275
83276 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
83277 if (global_diff[i])
83278 - atomic_long_add(global_diff[i], &vm_stat[i]);
83279 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
83280 }
83281
83282 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
83283 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
83284 if (pset->vm_stat_diff[i]) {
83285 int v = pset->vm_stat_diff[i];
83286 pset->vm_stat_diff[i] = 0;
83287 - atomic_long_add(v, &zone->vm_stat[i]);
83288 - atomic_long_add(v, &vm_stat[i]);
83289 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
83290 + atomic_long_add_unchecked(v, &vm_stat[i]);
83291 }
83292 }
83293 #endif
83294 @@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
83295 return NOTIFY_OK;
83296 }
83297
83298 -static struct notifier_block __cpuinitdata vmstat_notifier =
83299 +static struct notifier_block vmstat_notifier =
83300 { &vmstat_cpuup_callback, NULL, 0 };
83301 #endif
83302
83303 @@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
83304 start_cpu_timer(cpu);
83305 #endif
83306 #ifdef CONFIG_PROC_FS
83307 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
83308 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
83309 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
83310 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
83311 + {
83312 + mode_t gr_mode = S_IRUGO;
83313 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
83314 + gr_mode = S_IRUSR;
83315 +#endif
83316 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
83317 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
83318 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83319 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
83320 +#else
83321 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
83322 +#endif
83323 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
83324 + }
83325 #endif
83326 return 0;
83327 }
83328 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
83329 index a292e80..785ee68 100644
83330 --- a/net/8021q/vlan.c
83331 +++ b/net/8021q/vlan.c
83332 @@ -485,7 +485,7 @@ out:
83333 return NOTIFY_DONE;
83334 }
83335
83336 -static struct notifier_block vlan_notifier_block __read_mostly = {
83337 +static struct notifier_block vlan_notifier_block = {
83338 .notifier_call = vlan_device_event,
83339 };
83340
83341 @@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
83342 err = -EPERM;
83343 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
83344 break;
83345 - if ((args.u.name_type >= 0) &&
83346 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
83347 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
83348 struct vlan_net *vn;
83349
83350 vn = net_generic(net, vlan_net_id);
83351 diff --git a/net/9p/mod.c b/net/9p/mod.c
83352 index 6ab36ae..6f1841b 100644
83353 --- a/net/9p/mod.c
83354 +++ b/net/9p/mod.c
83355 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
83356 void v9fs_register_trans(struct p9_trans_module *m)
83357 {
83358 spin_lock(&v9fs_trans_lock);
83359 - list_add_tail(&m->list, &v9fs_trans_list);
83360 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
83361 spin_unlock(&v9fs_trans_lock);
83362 }
83363 EXPORT_SYMBOL(v9fs_register_trans);
83364 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
83365 void v9fs_unregister_trans(struct p9_trans_module *m)
83366 {
83367 spin_lock(&v9fs_trans_lock);
83368 - list_del_init(&m->list);
83369 + pax_list_del_init((struct list_head *)&m->list);
83370 spin_unlock(&v9fs_trans_lock);
83371 }
83372 EXPORT_SYMBOL(v9fs_unregister_trans);
83373 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
83374 index 02efb25..41541a9 100644
83375 --- a/net/9p/trans_fd.c
83376 +++ b/net/9p/trans_fd.c
83377 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
83378 oldfs = get_fs();
83379 set_fs(get_ds());
83380 /* The cast to a user pointer is valid due to the set_fs() */
83381 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
83382 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
83383 set_fs(oldfs);
83384
83385 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
83386 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
83387 index 876fbe8..8bbea9f 100644
83388 --- a/net/atm/atm_misc.c
83389 +++ b/net/atm/atm_misc.c
83390 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
83391 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
83392 return 1;
83393 atm_return(vcc, truesize);
83394 - atomic_inc(&vcc->stats->rx_drop);
83395 + atomic_inc_unchecked(&vcc->stats->rx_drop);
83396 return 0;
83397 }
83398 EXPORT_SYMBOL(atm_charge);
83399 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
83400 }
83401 }
83402 atm_return(vcc, guess);
83403 - atomic_inc(&vcc->stats->rx_drop);
83404 + atomic_inc_unchecked(&vcc->stats->rx_drop);
83405 return NULL;
83406 }
83407 EXPORT_SYMBOL(atm_alloc_charge);
83408 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
83409
83410 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
83411 {
83412 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
83413 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
83414 __SONET_ITEMS
83415 #undef __HANDLE_ITEM
83416 }
83417 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
83418
83419 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
83420 {
83421 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
83422 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
83423 __SONET_ITEMS
83424 #undef __HANDLE_ITEM
83425 }
83426 diff --git a/net/atm/lec.h b/net/atm/lec.h
83427 index a86aff9..3a0d6f6 100644
83428 --- a/net/atm/lec.h
83429 +++ b/net/atm/lec.h
83430 @@ -48,7 +48,7 @@ struct lane2_ops {
83431 const u8 *tlvs, u32 sizeoftlvs);
83432 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
83433 const u8 *tlvs, u32 sizeoftlvs);
83434 -};
83435 +} __no_const;
83436
83437 /*
83438 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
83439 diff --git a/net/atm/proc.c b/net/atm/proc.c
83440 index 0d020de..011c7bb 100644
83441 --- a/net/atm/proc.c
83442 +++ b/net/atm/proc.c
83443 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
83444 const struct k_atm_aal_stats *stats)
83445 {
83446 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
83447 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
83448 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
83449 - atomic_read(&stats->rx_drop));
83450 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
83451 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
83452 + atomic_read_unchecked(&stats->rx_drop));
83453 }
83454
83455 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
83456 diff --git a/net/atm/resources.c b/net/atm/resources.c
83457 index 0447d5d..3cf4728 100644
83458 --- a/net/atm/resources.c
83459 +++ b/net/atm/resources.c
83460 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
83461 static void copy_aal_stats(struct k_atm_aal_stats *from,
83462 struct atm_aal_stats *to)
83463 {
83464 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
83465 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
83466 __AAL_STAT_ITEMS
83467 #undef __HANDLE_ITEM
83468 }
83469 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
83470 static void subtract_aal_stats(struct k_atm_aal_stats *from,
83471 struct atm_aal_stats *to)
83472 {
83473 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
83474 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
83475 __AAL_STAT_ITEMS
83476 #undef __HANDLE_ITEM
83477 }
83478 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
83479 index d5744b7..506bae3 100644
83480 --- a/net/ax25/sysctl_net_ax25.c
83481 +++ b/net/ax25/sysctl_net_ax25.c
83482 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
83483 {
83484 char path[sizeof("net/ax25/") + IFNAMSIZ];
83485 int k;
83486 - struct ctl_table *table;
83487 + ctl_table_no_const *table;
83488
83489 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
83490 if (!table)
83491 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
83492 index 7d02ebd..4d4cc01 100644
83493 --- a/net/batman-adv/bat_iv_ogm.c
83494 +++ b/net/batman-adv/bat_iv_ogm.c
83495 @@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
83496
83497 /* randomize initial seqno to avoid collision */
83498 get_random_bytes(&random_seqno, sizeof(random_seqno));
83499 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
83500 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
83501
83502 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
83503 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
83504 @@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
83505 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
83506
83507 /* change sequence number to network order */
83508 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
83509 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
83510 batadv_ogm_packet->seqno = htonl(seqno);
83511 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
83512 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
83513
83514 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
83515 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
83516 @@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
83517 return;
83518
83519 /* could be changed by schedule_own_packet() */
83520 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
83521 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
83522
83523 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
83524 has_directlink_flag = 1;
83525 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
83526 index f1d37cd..4190879 100644
83527 --- a/net/batman-adv/hard-interface.c
83528 +++ b/net/batman-adv/hard-interface.c
83529 @@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
83530 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
83531 dev_add_pack(&hard_iface->batman_adv_ptype);
83532
83533 - atomic_set(&hard_iface->frag_seqno, 1);
83534 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
83535 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
83536 hard_iface->net_dev->name);
83537
83538 @@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
83539 /* This can't be called via a bat_priv callback because
83540 * we have no bat_priv yet.
83541 */
83542 - atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
83543 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
83544 hard_iface->bat_iv.ogm_buff = NULL;
83545
83546 return hard_iface;
83547 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
83548 index 6b548fd..fc32c8d 100644
83549 --- a/net/batman-adv/soft-interface.c
83550 +++ b/net/batman-adv/soft-interface.c
83551 @@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
83552 primary_if->net_dev->dev_addr, ETH_ALEN);
83553
83554 /* set broadcast sequence number */
83555 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
83556 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
83557 bcast_packet->seqno = htonl(seqno);
83558
83559 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
83560 @@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
83561 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
83562
83563 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
83564 - atomic_set(&bat_priv->bcast_seqno, 1);
83565 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
83566 atomic_set(&bat_priv->tt.vn, 0);
83567 atomic_set(&bat_priv->tt.local_changes, 0);
83568 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
83569 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
83570 index ae9ac9a..11e0fe7 100644
83571 --- a/net/batman-adv/types.h
83572 +++ b/net/batman-adv/types.h
83573 @@ -48,7 +48,7 @@
83574 struct batadv_hard_iface_bat_iv {
83575 unsigned char *ogm_buff;
83576 int ogm_buff_len;
83577 - atomic_t ogm_seqno;
83578 + atomic_unchecked_t ogm_seqno;
83579 };
83580
83581 struct batadv_hard_iface {
83582 @@ -56,7 +56,7 @@ struct batadv_hard_iface {
83583 int16_t if_num;
83584 char if_status;
83585 struct net_device *net_dev;
83586 - atomic_t frag_seqno;
83587 + atomic_unchecked_t frag_seqno;
83588 struct kobject *hardif_obj;
83589 atomic_t refcount;
83590 struct packet_type batman_adv_ptype;
83591 @@ -284,7 +284,7 @@ struct batadv_priv {
83592 atomic_t orig_interval; /* uint */
83593 atomic_t hop_penalty; /* uint */
83594 atomic_t log_level; /* uint */
83595 - atomic_t bcast_seqno;
83596 + atomic_unchecked_t bcast_seqno;
83597 atomic_t bcast_queue_left;
83598 atomic_t batman_queue_left;
83599 char num_ifaces;
83600 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
83601 index 10aff49..ea8e021 100644
83602 --- a/net/batman-adv/unicast.c
83603 +++ b/net/batman-adv/unicast.c
83604 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
83605 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
83606 frag2->flags = large_tail;
83607
83608 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
83609 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
83610 frag1->seqno = htons(seqno - 1);
83611 frag2->seqno = htons(seqno);
83612
83613 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
83614 index 07f0739..3c42e34 100644
83615 --- a/net/bluetooth/hci_sock.c
83616 +++ b/net/bluetooth/hci_sock.c
83617 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
83618 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
83619 }
83620
83621 - len = min_t(unsigned int, len, sizeof(uf));
83622 + len = min((size_t)len, sizeof(uf));
83623 if (copy_from_user(&uf, optval, len)) {
83624 err = -EFAULT;
83625 break;
83626 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
83627 index 22e6583..426e2f3 100644
83628 --- a/net/bluetooth/l2cap_core.c
83629 +++ b/net/bluetooth/l2cap_core.c
83630 @@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
83631 break;
83632
83633 case L2CAP_CONF_RFC:
83634 - if (olen == sizeof(rfc))
83635 - memcpy(&rfc, (void *)val, olen);
83636 + if (olen != sizeof(rfc))
83637 + break;
83638 +
83639 + memcpy(&rfc, (void *)val, olen);
83640
83641 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
83642 rfc.mode != chan->mode)
83643 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
83644 index 1bcfb84..dad9f98 100644
83645 --- a/net/bluetooth/l2cap_sock.c
83646 +++ b/net/bluetooth/l2cap_sock.c
83647 @@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
83648 struct sock *sk = sock->sk;
83649 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
83650 struct l2cap_options opts;
83651 - int len, err = 0;
83652 + int err = 0;
83653 + size_t len = optlen;
83654 u32 opt;
83655
83656 BT_DBG("sk %p", sk);
83657 @@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
83658 opts.max_tx = chan->max_tx;
83659 opts.txwin_size = chan->tx_win;
83660
83661 - len = min_t(unsigned int, sizeof(opts), optlen);
83662 + len = min(sizeof(opts), len);
83663 if (copy_from_user((char *) &opts, optval, len)) {
83664 err = -EFAULT;
83665 break;
83666 @@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83667 struct bt_security sec;
83668 struct bt_power pwr;
83669 struct l2cap_conn *conn;
83670 - int len, err = 0;
83671 + int err = 0;
83672 + size_t len = optlen;
83673 u32 opt;
83674
83675 BT_DBG("sk %p", sk);
83676 @@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83677
83678 sec.level = BT_SECURITY_LOW;
83679
83680 - len = min_t(unsigned int, sizeof(sec), optlen);
83681 + len = min(sizeof(sec), len);
83682 if (copy_from_user((char *) &sec, optval, len)) {
83683 err = -EFAULT;
83684 break;
83685 @@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83686
83687 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
83688
83689 - len = min_t(unsigned int, sizeof(pwr), optlen);
83690 + len = min(sizeof(pwr), len);
83691 if (copy_from_user((char *) &pwr, optval, len)) {
83692 err = -EFAULT;
83693 break;
83694 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
83695 index ce3f665..2c7d08f 100644
83696 --- a/net/bluetooth/rfcomm/sock.c
83697 +++ b/net/bluetooth/rfcomm/sock.c
83698 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
83699 struct sock *sk = sock->sk;
83700 struct bt_security sec;
83701 int err = 0;
83702 - size_t len;
83703 + size_t len = optlen;
83704 u32 opt;
83705
83706 BT_DBG("sk %p", sk);
83707 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
83708
83709 sec.level = BT_SECURITY_LOW;
83710
83711 - len = min_t(unsigned int, sizeof(sec), optlen);
83712 + len = min(sizeof(sec), len);
83713 if (copy_from_user((char *) &sec, optval, len)) {
83714 err = -EFAULT;
83715 break;
83716 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
83717 index bd6fd0f..6492cba 100644
83718 --- a/net/bluetooth/rfcomm/tty.c
83719 +++ b/net/bluetooth/rfcomm/tty.c
83720 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
83721 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
83722
83723 spin_lock_irqsave(&dev->port.lock, flags);
83724 - if (dev->port.count > 0) {
83725 + if (atomic_read(&dev->port.count) > 0) {
83726 spin_unlock_irqrestore(&dev->port.lock, flags);
83727 return;
83728 }
83729 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
83730 return -ENODEV;
83731
83732 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
83733 - dev->channel, dev->port.count);
83734 + dev->channel, atomic_read(&dev->port.count));
83735
83736 spin_lock_irqsave(&dev->port.lock, flags);
83737 - if (++dev->port.count > 1) {
83738 + if (atomic_inc_return(&dev->port.count) > 1) {
83739 spin_unlock_irqrestore(&dev->port.lock, flags);
83740 return 0;
83741 }
83742 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
83743 return;
83744
83745 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
83746 - dev->port.count);
83747 + atomic_read(&dev->port.count));
83748
83749 spin_lock_irqsave(&dev->port.lock, flags);
83750 - if (!--dev->port.count) {
83751 + if (!atomic_dec_return(&dev->port.count)) {
83752 spin_unlock_irqrestore(&dev->port.lock, flags);
83753 if (dev->tty_dev->parent)
83754 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
83755 diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c
83756 index acc9f4c..2897e40 100644
83757 --- a/net/bridge/br_mdb.c
83758 +++ b/net/bridge/br_mdb.c
83759 @@ -82,6 +82,7 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
83760 port = p->port;
83761 if (port) {
83762 struct br_mdb_entry e;
83763 + memset(&e, 0, sizeof(e));
83764 e.ifindex = port->dev->ifindex;
83765 e.state = p->state;
83766 if (p->addr.proto == htons(ETH_P_IP))
83767 @@ -138,6 +139,7 @@ static int br_mdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
83768 break;
83769
83770 bpm = nlmsg_data(nlh);
83771 + memset(bpm, 0, sizeof(*bpm));
83772 bpm->ifindex = dev->ifindex;
83773 if (br_mdb_fill_info(skb, cb, dev) < 0)
83774 goto out;
83775 @@ -173,6 +175,7 @@ static int nlmsg_populate_mdb_fill(struct sk_buff *skb,
83776 return -EMSGSIZE;
83777
83778 bpm = nlmsg_data(nlh);
83779 + memset(bpm, 0, sizeof(*bpm));
83780 bpm->family = AF_BRIDGE;
83781 bpm->ifindex = dev->ifindex;
83782 nest = nla_nest_start(skb, MDBA_MDB);
83783 @@ -230,6 +233,7 @@ void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
83784 {
83785 struct br_mdb_entry entry;
83786
83787 + memset(&entry, 0, sizeof(entry));
83788 entry.ifindex = port->dev->ifindex;
83789 entry.addr.proto = group->proto;
83790 entry.addr.u.ip4 = group->u.ip4;
83791 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
83792 index 5fe2ff3..121d696 100644
83793 --- a/net/bridge/netfilter/ebtables.c
83794 +++ b/net/bridge/netfilter/ebtables.c
83795 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
83796 tmp.valid_hooks = t->table->valid_hooks;
83797 }
83798 mutex_unlock(&ebt_mutex);
83799 - if (copy_to_user(user, &tmp, *len) != 0){
83800 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
83801 BUGPRINT("c2u Didn't work\n");
83802 ret = -EFAULT;
83803 break;
83804 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
83805 goto out;
83806 tmp.valid_hooks = t->valid_hooks;
83807
83808 - if (copy_to_user(user, &tmp, *len) != 0) {
83809 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
83810 ret = -EFAULT;
83811 break;
83812 }
83813 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
83814 tmp.entries_size = t->table->entries_size;
83815 tmp.valid_hooks = t->table->valid_hooks;
83816
83817 - if (copy_to_user(user, &tmp, *len) != 0) {
83818 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
83819 ret = -EFAULT;
83820 break;
83821 }
83822 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
83823 index a376ec1..1fbd6be 100644
83824 --- a/net/caif/cfctrl.c
83825 +++ b/net/caif/cfctrl.c
83826 @@ -10,6 +10,7 @@
83827 #include <linux/spinlock.h>
83828 #include <linux/slab.h>
83829 #include <linux/pkt_sched.h>
83830 +#include <linux/sched.h>
83831 #include <net/caif/caif_layer.h>
83832 #include <net/caif/cfpkt.h>
83833 #include <net/caif/cfctrl.h>
83834 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
83835 memset(&dev_info, 0, sizeof(dev_info));
83836 dev_info.id = 0xff;
83837 cfsrvl_init(&this->serv, 0, &dev_info, false);
83838 - atomic_set(&this->req_seq_no, 1);
83839 - atomic_set(&this->rsp_seq_no, 1);
83840 + atomic_set_unchecked(&this->req_seq_no, 1);
83841 + atomic_set_unchecked(&this->rsp_seq_no, 1);
83842 this->serv.layer.receive = cfctrl_recv;
83843 sprintf(this->serv.layer.name, "ctrl");
83844 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
83845 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
83846 struct cfctrl_request_info *req)
83847 {
83848 spin_lock_bh(&ctrl->info_list_lock);
83849 - atomic_inc(&ctrl->req_seq_no);
83850 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
83851 + atomic_inc_unchecked(&ctrl->req_seq_no);
83852 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
83853 list_add_tail(&req->list, &ctrl->list);
83854 spin_unlock_bh(&ctrl->info_list_lock);
83855 }
83856 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
83857 if (p != first)
83858 pr_warn("Requests are not received in order\n");
83859
83860 - atomic_set(&ctrl->rsp_seq_no,
83861 + atomic_set_unchecked(&ctrl->rsp_seq_no,
83862 p->sequence_no);
83863 list_del(&p->list);
83864 goto out;
83865 diff --git a/net/can/af_can.c b/net/can/af_can.c
83866 index ddac1ee..3ee0a78 100644
83867 --- a/net/can/af_can.c
83868 +++ b/net/can/af_can.c
83869 @@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
83870 };
83871
83872 /* notifier block for netdevice event */
83873 -static struct notifier_block can_netdev_notifier __read_mostly = {
83874 +static struct notifier_block can_netdev_notifier = {
83875 .notifier_call = can_notifier,
83876 };
83877
83878 diff --git a/net/can/gw.c b/net/can/gw.c
83879 index 574dda78e..3d2b3da 100644
83880 --- a/net/can/gw.c
83881 +++ b/net/can/gw.c
83882 @@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
83883 MODULE_ALIAS("can-gw");
83884
83885 static HLIST_HEAD(cgw_list);
83886 -static struct notifier_block notifier;
83887
83888 static struct kmem_cache *cgw_cache __read_mostly;
83889
83890 @@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
83891 return err;
83892 }
83893
83894 +static struct notifier_block notifier = {
83895 + .notifier_call = cgw_notifier
83896 +};
83897 +
83898 static __init int cgw_module_init(void)
83899 {
83900 printk(banner);
83901 @@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
83902 return -ENOMEM;
83903
83904 /* set notifier */
83905 - notifier.notifier_call = cgw_notifier;
83906 register_netdevice_notifier(&notifier);
83907
83908 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
83909 diff --git a/net/compat.c b/net/compat.c
83910 index 79ae884..17c5c09 100644
83911 --- a/net/compat.c
83912 +++ b/net/compat.c
83913 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
83914 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
83915 __get_user(kmsg->msg_flags, &umsg->msg_flags))
83916 return -EFAULT;
83917 - kmsg->msg_name = compat_ptr(tmp1);
83918 - kmsg->msg_iov = compat_ptr(tmp2);
83919 - kmsg->msg_control = compat_ptr(tmp3);
83920 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
83921 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
83922 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
83923 return 0;
83924 }
83925
83926 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
83927
83928 if (kern_msg->msg_namelen) {
83929 if (mode == VERIFY_READ) {
83930 - int err = move_addr_to_kernel(kern_msg->msg_name,
83931 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
83932 kern_msg->msg_namelen,
83933 kern_address);
83934 if (err < 0)
83935 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
83936 kern_msg->msg_name = NULL;
83937
83938 tot_len = iov_from_user_compat_to_kern(kern_iov,
83939 - (struct compat_iovec __user *)kern_msg->msg_iov,
83940 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
83941 kern_msg->msg_iovlen);
83942 if (tot_len >= 0)
83943 kern_msg->msg_iov = kern_iov;
83944 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
83945
83946 #define CMSG_COMPAT_FIRSTHDR(msg) \
83947 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
83948 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
83949 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
83950 (struct compat_cmsghdr __user *)NULL)
83951
83952 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
83953 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
83954 (ucmlen) <= (unsigned long) \
83955 ((mhdr)->msg_controllen - \
83956 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
83957 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
83958
83959 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
83960 struct compat_cmsghdr __user *cmsg, int cmsg_len)
83961 {
83962 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
83963 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
83964 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
83965 msg->msg_controllen)
83966 return NULL;
83967 return (struct compat_cmsghdr __user *)ptr;
83968 @@ -219,7 +219,7 @@ Efault:
83969
83970 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
83971 {
83972 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
83973 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
83974 struct compat_cmsghdr cmhdr;
83975 struct compat_timeval ctv;
83976 struct compat_timespec cts[3];
83977 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
83978
83979 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
83980 {
83981 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
83982 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
83983 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
83984 int fdnum = scm->fp->count;
83985 struct file **fp = scm->fp->fp;
83986 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
83987 return -EFAULT;
83988 old_fs = get_fs();
83989 set_fs(KERNEL_DS);
83990 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
83991 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
83992 set_fs(old_fs);
83993
83994 return err;
83995 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
83996 len = sizeof(ktime);
83997 old_fs = get_fs();
83998 set_fs(KERNEL_DS);
83999 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
84000 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
84001 set_fs(old_fs);
84002
84003 if (!err) {
84004 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84005 case MCAST_JOIN_GROUP:
84006 case MCAST_LEAVE_GROUP:
84007 {
84008 - struct compat_group_req __user *gr32 = (void *)optval;
84009 + struct compat_group_req __user *gr32 = (void __user *)optval;
84010 struct group_req __user *kgr =
84011 compat_alloc_user_space(sizeof(struct group_req));
84012 u32 interface;
84013 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84014 case MCAST_BLOCK_SOURCE:
84015 case MCAST_UNBLOCK_SOURCE:
84016 {
84017 - struct compat_group_source_req __user *gsr32 = (void *)optval;
84018 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
84019 struct group_source_req __user *kgsr = compat_alloc_user_space(
84020 sizeof(struct group_source_req));
84021 u32 interface;
84022 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84023 }
84024 case MCAST_MSFILTER:
84025 {
84026 - struct compat_group_filter __user *gf32 = (void *)optval;
84027 + struct compat_group_filter __user *gf32 = (void __user *)optval;
84028 struct group_filter __user *kgf;
84029 u32 interface, fmode, numsrc;
84030
84031 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
84032 char __user *optval, int __user *optlen,
84033 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
84034 {
84035 - struct compat_group_filter __user *gf32 = (void *)optval;
84036 + struct compat_group_filter __user *gf32 = (void __user *)optval;
84037 struct group_filter __user *kgf;
84038 int __user *koptlen;
84039 u32 interface, fmode, numsrc;
84040 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
84041
84042 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
84043 return -EINVAL;
84044 - if (copy_from_user(a, args, nas[call]))
84045 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
84046 return -EFAULT;
84047 a0 = a[0];
84048 a1 = a[1];
84049 diff --git a/net/core/datagram.c b/net/core/datagram.c
84050 index 368f9c3..f82d4a3 100644
84051 --- a/net/core/datagram.c
84052 +++ b/net/core/datagram.c
84053 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
84054 }
84055
84056 kfree_skb(skb);
84057 - atomic_inc(&sk->sk_drops);
84058 + atomic_inc_unchecked(&sk->sk_drops);
84059 sk_mem_reclaim_partial(sk);
84060
84061 return err;
84062 diff --git a/net/core/dev.c b/net/core/dev.c
84063 index f64e439..8f959e6 100644
84064 --- a/net/core/dev.c
84065 +++ b/net/core/dev.c
84066 @@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
84067 if (no_module && capable(CAP_NET_ADMIN))
84068 no_module = request_module("netdev-%s", name);
84069 if (no_module && capable(CAP_SYS_MODULE)) {
84070 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
84071 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
84072 +#else
84073 if (!request_module("%s", name))
84074 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
84075 name);
84076 +#endif
84077 }
84078 }
84079 EXPORT_SYMBOL(dev_load);
84080 @@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84081 {
84082 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
84083 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
84084 - atomic_long_inc(&dev->rx_dropped);
84085 + atomic_long_inc_unchecked(&dev->rx_dropped);
84086 kfree_skb(skb);
84087 return NET_RX_DROP;
84088 }
84089 @@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84090 nf_reset(skb);
84091
84092 if (unlikely(!is_skb_forwardable(dev, skb))) {
84093 - atomic_long_inc(&dev->rx_dropped);
84094 + atomic_long_inc_unchecked(&dev->rx_dropped);
84095 kfree_skb(skb);
84096 return NET_RX_DROP;
84097 }
84098 @@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
84099
84100 struct dev_gso_cb {
84101 void (*destructor)(struct sk_buff *skb);
84102 -};
84103 +} __no_const;
84104
84105 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
84106
84107 @@ -3053,7 +3057,7 @@ enqueue:
84108
84109 local_irq_restore(flags);
84110
84111 - atomic_long_inc(&skb->dev->rx_dropped);
84112 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84113 kfree_skb(skb);
84114 return NET_RX_DROP;
84115 }
84116 @@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
84117 }
84118 EXPORT_SYMBOL(netif_rx_ni);
84119
84120 -static void net_tx_action(struct softirq_action *h)
84121 +static void net_tx_action(void)
84122 {
84123 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84124
84125 @@ -3456,7 +3460,7 @@ ncls:
84126 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
84127 } else {
84128 drop:
84129 - atomic_long_inc(&skb->dev->rx_dropped);
84130 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84131 kfree_skb(skb);
84132 /* Jamal, now you will not able to escape explaining
84133 * me how you were going to use this. :-)
84134 @@ -4039,7 +4043,7 @@ void netif_napi_del(struct napi_struct *napi)
84135 }
84136 EXPORT_SYMBOL(netif_napi_del);
84137
84138 -static void net_rx_action(struct softirq_action *h)
84139 +static void net_rx_action(void)
84140 {
84141 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84142 unsigned long time_limit = jiffies + 2;
84143 @@ -4523,8 +4527,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
84144 else
84145 seq_printf(seq, "%04x", ntohs(pt->type));
84146
84147 +#ifdef CONFIG_GRKERNSEC_HIDESYM
84148 + seq_printf(seq, " %-8s %p\n",
84149 + pt->dev ? pt->dev->name : "", NULL);
84150 +#else
84151 seq_printf(seq, " %-8s %pF\n",
84152 pt->dev ? pt->dev->name : "", pt->func);
84153 +#endif
84154 }
84155
84156 return 0;
84157 @@ -6096,7 +6105,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
84158 } else {
84159 netdev_stats_to_stats64(storage, &dev->stats);
84160 }
84161 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
84162 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
84163 return storage;
84164 }
84165 EXPORT_SYMBOL(dev_get_stats);
84166 diff --git a/net/core/flow.c b/net/core/flow.c
84167 index b0901ee..7d3c2ca 100644
84168 --- a/net/core/flow.c
84169 +++ b/net/core/flow.c
84170 @@ -61,7 +61,7 @@ struct flow_cache {
84171 struct timer_list rnd_timer;
84172 };
84173
84174 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
84175 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
84176 EXPORT_SYMBOL(flow_cache_genid);
84177 static struct flow_cache flow_cache_global;
84178 static struct kmem_cache *flow_cachep __read_mostly;
84179 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
84180
84181 static int flow_entry_valid(struct flow_cache_entry *fle)
84182 {
84183 - if (atomic_read(&flow_cache_genid) != fle->genid)
84184 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
84185 return 0;
84186 if (fle->object && !fle->object->ops->check(fle->object))
84187 return 0;
84188 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
84189 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
84190 fcp->hash_count++;
84191 }
84192 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
84193 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
84194 flo = fle->object;
84195 if (!flo)
84196 goto ret_object;
84197 @@ -280,7 +280,7 @@ nocache:
84198 }
84199 flo = resolver(net, key, family, dir, flo, ctx);
84200 if (fle) {
84201 - fle->genid = atomic_read(&flow_cache_genid);
84202 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
84203 if (!IS_ERR(flo))
84204 fle->object = flo;
84205 else
84206 diff --git a/net/core/iovec.c b/net/core/iovec.c
84207 index 7e7aeb0..2a998cb 100644
84208 --- a/net/core/iovec.c
84209 +++ b/net/core/iovec.c
84210 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
84211 if (m->msg_namelen) {
84212 if (mode == VERIFY_READ) {
84213 void __user *namep;
84214 - namep = (void __user __force *) m->msg_name;
84215 + namep = (void __force_user *) m->msg_name;
84216 err = move_addr_to_kernel(namep, m->msg_namelen,
84217 address);
84218 if (err < 0)
84219 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
84220 }
84221
84222 size = m->msg_iovlen * sizeof(struct iovec);
84223 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
84224 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
84225 return -EFAULT;
84226
84227 m->msg_iov = iov;
84228 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
84229 index c815f28..e6403f2 100644
84230 --- a/net/core/neighbour.c
84231 +++ b/net/core/neighbour.c
84232 @@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
84233 size_t *lenp, loff_t *ppos)
84234 {
84235 int size, ret;
84236 - ctl_table tmp = *ctl;
84237 + ctl_table_no_const tmp = *ctl;
84238
84239 tmp.extra1 = &zero;
84240 tmp.extra2 = &unres_qlen_max;
84241 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
84242 index 28c5f5a..7edf2e2 100644
84243 --- a/net/core/net-sysfs.c
84244 +++ b/net/core/net-sysfs.c
84245 @@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
84246 }
84247 EXPORT_SYMBOL(netdev_class_remove_file);
84248
84249 -int netdev_kobject_init(void)
84250 +int __init netdev_kobject_init(void)
84251 {
84252 kobj_ns_type_register(&net_ns_type_operations);
84253 return class_register(&net_class);
84254 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
84255 index 8acce01..2e306bb 100644
84256 --- a/net/core/net_namespace.c
84257 +++ b/net/core/net_namespace.c
84258 @@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
84259 int error;
84260 LIST_HEAD(net_exit_list);
84261
84262 - list_add_tail(&ops->list, list);
84263 + pax_list_add_tail((struct list_head *)&ops->list, list);
84264 if (ops->init || (ops->id && ops->size)) {
84265 for_each_net(net) {
84266 error = ops_init(ops, net);
84267 @@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
84268
84269 out_undo:
84270 /* If I have an error cleanup all namespaces I initialized */
84271 - list_del(&ops->list);
84272 + pax_list_del((struct list_head *)&ops->list);
84273 ops_exit_list(ops, &net_exit_list);
84274 ops_free_list(ops, &net_exit_list);
84275 return error;
84276 @@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
84277 struct net *net;
84278 LIST_HEAD(net_exit_list);
84279
84280 - list_del(&ops->list);
84281 + pax_list_del((struct list_head *)&ops->list);
84282 for_each_net(net)
84283 list_add_tail(&net->exit_list, &net_exit_list);
84284 ops_exit_list(ops, &net_exit_list);
84285 @@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
84286 mutex_lock(&net_mutex);
84287 error = register_pernet_operations(&pernet_list, ops);
84288 if (!error && (first_device == &pernet_list))
84289 - first_device = &ops->list;
84290 + first_device = (struct list_head *)&ops->list;
84291 mutex_unlock(&net_mutex);
84292 return error;
84293 }
84294 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
84295 index 1868625..e2261f5 100644
84296 --- a/net/core/rtnetlink.c
84297 +++ b/net/core/rtnetlink.c
84298 @@ -58,7 +58,7 @@ struct rtnl_link {
84299 rtnl_doit_func doit;
84300 rtnl_dumpit_func dumpit;
84301 rtnl_calcit_func calcit;
84302 -};
84303 +} __no_const;
84304
84305 static DEFINE_MUTEX(rtnl_mutex);
84306
84307 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
84308 if (rtnl_link_ops_get(ops->kind))
84309 return -EEXIST;
84310
84311 - if (!ops->dellink)
84312 - ops->dellink = unregister_netdevice_queue;
84313 + if (!ops->dellink) {
84314 + pax_open_kernel();
84315 + *(void **)&ops->dellink = unregister_netdevice_queue;
84316 + pax_close_kernel();
84317 + }
84318
84319 - list_add_tail(&ops->list, &link_ops);
84320 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
84321 return 0;
84322 }
84323 EXPORT_SYMBOL_GPL(__rtnl_link_register);
84324 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
84325 for_each_net(net) {
84326 __rtnl_kill_links(net, ops);
84327 }
84328 - list_del(&ops->list);
84329 + pax_list_del((struct list_head *)&ops->list);
84330 }
84331 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
84332
84333 @@ -976,6 +979,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
84334 * report anything.
84335 */
84336 ivi.spoofchk = -1;
84337 + memset(ivi.mac, 0, sizeof(ivi.mac));
84338 if (dev->netdev_ops->ndo_get_vf_config(dev, i, &ivi))
84339 break;
84340 vf_mac.vf =
84341 diff --git a/net/core/scm.c b/net/core/scm.c
84342 index 905dcc6..14ee2d6 100644
84343 --- a/net/core/scm.c
84344 +++ b/net/core/scm.c
84345 @@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
84346 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
84347 {
84348 struct cmsghdr __user *cm
84349 - = (__force struct cmsghdr __user *)msg->msg_control;
84350 + = (struct cmsghdr __force_user *)msg->msg_control;
84351 struct cmsghdr cmhdr;
84352 int cmlen = CMSG_LEN(len);
84353 int err;
84354 @@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
84355 err = -EFAULT;
84356 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
84357 goto out;
84358 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
84359 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
84360 goto out;
84361 cmlen = CMSG_SPACE(len);
84362 if (msg->msg_controllen < cmlen)
84363 @@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
84364 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
84365 {
84366 struct cmsghdr __user *cm
84367 - = (__force struct cmsghdr __user*)msg->msg_control;
84368 + = (struct cmsghdr __force_user *)msg->msg_control;
84369
84370 int fdmax = 0;
84371 int fdnum = scm->fp->count;
84372 @@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
84373 if (fdnum < fdmax)
84374 fdmax = fdnum;
84375
84376 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
84377 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
84378 i++, cmfptr++)
84379 {
84380 struct socket *sock;
84381 diff --git a/net/core/sock.c b/net/core/sock.c
84382 index bc131d4..029e378 100644
84383 --- a/net/core/sock.c
84384 +++ b/net/core/sock.c
84385 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84386 struct sk_buff_head *list = &sk->sk_receive_queue;
84387
84388 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
84389 - atomic_inc(&sk->sk_drops);
84390 + atomic_inc_unchecked(&sk->sk_drops);
84391 trace_sock_rcvqueue_full(sk, skb);
84392 return -ENOMEM;
84393 }
84394 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84395 return err;
84396
84397 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
84398 - atomic_inc(&sk->sk_drops);
84399 + atomic_inc_unchecked(&sk->sk_drops);
84400 return -ENOBUFS;
84401 }
84402
84403 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84404 skb_dst_force(skb);
84405
84406 spin_lock_irqsave(&list->lock, flags);
84407 - skb->dropcount = atomic_read(&sk->sk_drops);
84408 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
84409 __skb_queue_tail(list, skb);
84410 spin_unlock_irqrestore(&list->lock, flags);
84411
84412 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
84413 skb->dev = NULL;
84414
84415 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
84416 - atomic_inc(&sk->sk_drops);
84417 + atomic_inc_unchecked(&sk->sk_drops);
84418 goto discard_and_relse;
84419 }
84420 if (nested)
84421 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
84422 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
84423 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
84424 bh_unlock_sock(sk);
84425 - atomic_inc(&sk->sk_drops);
84426 + atomic_inc_unchecked(&sk->sk_drops);
84427 goto discard_and_relse;
84428 }
84429
84430 @@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84431 struct timeval tm;
84432 } v;
84433
84434 - int lv = sizeof(int);
84435 - int len;
84436 + unsigned int lv = sizeof(int);
84437 + unsigned int len;
84438
84439 if (get_user(len, optlen))
84440 return -EFAULT;
84441 - if (len < 0)
84442 + if (len > INT_MAX)
84443 return -EINVAL;
84444
84445 memset(&v, 0, sizeof(v));
84446 @@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84447
84448 case SO_PEERNAME:
84449 {
84450 - char address[128];
84451 + char address[_K_SS_MAXSIZE];
84452
84453 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
84454 return -ENOTCONN;
84455 - if (lv < len)
84456 + if (lv < len || sizeof address < len)
84457 return -EINVAL;
84458 if (copy_to_user(optval, address, len))
84459 return -EFAULT;
84460 @@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84461
84462 if (len > lv)
84463 len = lv;
84464 - if (copy_to_user(optval, &v, len))
84465 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
84466 return -EFAULT;
84467 lenout:
84468 if (put_user(len, optlen))
84469 @@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
84470 */
84471 smp_wmb();
84472 atomic_set(&sk->sk_refcnt, 1);
84473 - atomic_set(&sk->sk_drops, 0);
84474 + atomic_set_unchecked(&sk->sk_drops, 0);
84475 }
84476 EXPORT_SYMBOL(sock_init_data);
84477
84478 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
84479 index 750f44f..922399c 100644
84480 --- a/net/core/sock_diag.c
84481 +++ b/net/core/sock_diag.c
84482 @@ -9,26 +9,33 @@
84483 #include <linux/inet_diag.h>
84484 #include <linux/sock_diag.h>
84485
84486 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
84487 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
84488 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
84489 static DEFINE_MUTEX(sock_diag_table_mutex);
84490
84491 int sock_diag_check_cookie(void *sk, __u32 *cookie)
84492 {
84493 +#ifndef CONFIG_GRKERNSEC_HIDESYM
84494 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
84495 cookie[1] != INET_DIAG_NOCOOKIE) &&
84496 ((u32)(unsigned long)sk != cookie[0] ||
84497 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
84498 return -ESTALE;
84499 else
84500 +#endif
84501 return 0;
84502 }
84503 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
84504
84505 void sock_diag_save_cookie(void *sk, __u32 *cookie)
84506 {
84507 +#ifdef CONFIG_GRKERNSEC_HIDESYM
84508 + cookie[0] = 0;
84509 + cookie[1] = 0;
84510 +#else
84511 cookie[0] = (u32)(unsigned long)sk;
84512 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
84513 +#endif
84514 }
84515 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
84516
84517 @@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
84518 mutex_lock(&sock_diag_table_mutex);
84519 if (sock_diag_handlers[hndl->family])
84520 err = -EBUSY;
84521 - else
84522 + else {
84523 + pax_open_kernel();
84524 sock_diag_handlers[hndl->family] = hndl;
84525 + pax_close_kernel();
84526 + }
84527 mutex_unlock(&sock_diag_table_mutex);
84528
84529 return err;
84530 @@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
84531
84532 mutex_lock(&sock_diag_table_mutex);
84533 BUG_ON(sock_diag_handlers[family] != hnld);
84534 + pax_open_kernel();
84535 sock_diag_handlers[family] = NULL;
84536 + pax_close_kernel();
84537 mutex_unlock(&sock_diag_table_mutex);
84538 }
84539 EXPORT_SYMBOL_GPL(sock_diag_unregister);
84540
84541 -static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
84542 -{
84543 - if (sock_diag_handlers[family] == NULL)
84544 - request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
84545 - NETLINK_SOCK_DIAG, family);
84546 -
84547 - mutex_lock(&sock_diag_table_mutex);
84548 - return sock_diag_handlers[family];
84549 -}
84550 -
84551 -static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
84552 -{
84553 - mutex_unlock(&sock_diag_table_mutex);
84554 -}
84555 -
84556 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84557 {
84558 int err;
84559 @@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84560 if (req->sdiag_family >= AF_MAX)
84561 return -EINVAL;
84562
84563 - hndl = sock_diag_lock_handler(req->sdiag_family);
84564 + if (sock_diag_handlers[req->sdiag_family] == NULL)
84565 + request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
84566 + NETLINK_SOCK_DIAG, req->sdiag_family);
84567 +
84568 + mutex_lock(&sock_diag_table_mutex);
84569 + hndl = sock_diag_handlers[req->sdiag_family];
84570 if (hndl == NULL)
84571 err = -ENOENT;
84572 else
84573 err = hndl->dump(skb, nlh);
84574 - sock_diag_unlock_handler(hndl);
84575 + mutex_unlock(&sock_diag_table_mutex);
84576
84577 return err;
84578 }
84579 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
84580 index d1b0804..4aed0a5 100644
84581 --- a/net/core/sysctl_net_core.c
84582 +++ b/net/core/sysctl_net_core.c
84583 @@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
84584 {
84585 unsigned int orig_size, size;
84586 int ret, i;
84587 - ctl_table tmp = {
84588 + ctl_table_no_const tmp = {
84589 .data = &size,
84590 .maxlen = sizeof(size),
84591 .mode = table->mode
84592 @@ -205,13 +205,12 @@ static struct ctl_table netns_core_table[] = {
84593
84594 static __net_init int sysctl_core_net_init(struct net *net)
84595 {
84596 - struct ctl_table *tbl;
84597 + ctl_table_no_const *tbl = NULL;
84598
84599 net->core.sysctl_somaxconn = SOMAXCONN;
84600
84601 - tbl = netns_core_table;
84602 if (!net_eq(net, &init_net)) {
84603 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
84604 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
84605 if (tbl == NULL)
84606 goto err_dup;
84607
84608 @@ -221,16 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
84609 if (net->user_ns != &init_user_ns) {
84610 tbl[0].procname = NULL;
84611 }
84612 - }
84613 -
84614 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
84615 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
84616 + } else
84617 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
84618 if (net->core.sysctl_hdr == NULL)
84619 goto err_reg;
84620
84621 return 0;
84622
84623 err_reg:
84624 - if (tbl != netns_core_table)
84625 + if (tbl)
84626 kfree(tbl);
84627 err_dup:
84628 return -ENOMEM;
84629 @@ -246,7 +245,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
84630 kfree(tbl);
84631 }
84632
84633 -static __net_initdata struct pernet_operations sysctl_core_ops = {
84634 +static __net_initconst struct pernet_operations sysctl_core_ops = {
84635 .init = sysctl_core_net_init,
84636 .exit = sysctl_core_net_exit,
84637 };
84638 diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
84639 index 1b588e2..21291f1 100644
84640 --- a/net/dcb/dcbnl.c
84641 +++ b/net/dcb/dcbnl.c
84642 @@ -284,6 +284,7 @@ static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlmsghdr *nlh,
84643 if (!netdev->dcbnl_ops->getpermhwaddr)
84644 return -EOPNOTSUPP;
84645
84646 + memset(perm_addr, 0, sizeof(perm_addr));
84647 netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
84648
84649 return nla_put(skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr), perm_addr);
84650 @@ -1042,6 +1043,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84651
84652 if (ops->ieee_getets) {
84653 struct ieee_ets ets;
84654 + memset(&ets, 0, sizeof(ets));
84655 err = ops->ieee_getets(netdev, &ets);
84656 if (!err &&
84657 nla_put(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets))
84658 @@ -1050,6 +1052,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84659
84660 if (ops->ieee_getmaxrate) {
84661 struct ieee_maxrate maxrate;
84662 + memset(&maxrate, 0, sizeof(maxrate));
84663 err = ops->ieee_getmaxrate(netdev, &maxrate);
84664 if (!err) {
84665 err = nla_put(skb, DCB_ATTR_IEEE_MAXRATE,
84666 @@ -1061,6 +1064,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84667
84668 if (ops->ieee_getpfc) {
84669 struct ieee_pfc pfc;
84670 + memset(&pfc, 0, sizeof(pfc));
84671 err = ops->ieee_getpfc(netdev, &pfc);
84672 if (!err &&
84673 nla_put(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc))
84674 @@ -1094,6 +1098,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84675 /* get peer info if available */
84676 if (ops->ieee_peer_getets) {
84677 struct ieee_ets ets;
84678 + memset(&ets, 0, sizeof(ets));
84679 err = ops->ieee_peer_getets(netdev, &ets);
84680 if (!err &&
84681 nla_put(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets))
84682 @@ -1102,6 +1107,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84683
84684 if (ops->ieee_peer_getpfc) {
84685 struct ieee_pfc pfc;
84686 + memset(&pfc, 0, sizeof(pfc));
84687 err = ops->ieee_peer_getpfc(netdev, &pfc);
84688 if (!err &&
84689 nla_put(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc))
84690 @@ -1280,6 +1286,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
84691 /* peer info if available */
84692 if (ops->cee_peer_getpg) {
84693 struct cee_pg pg;
84694 + memset(&pg, 0, sizeof(pg));
84695 err = ops->cee_peer_getpg(netdev, &pg);
84696 if (!err &&
84697 nla_put(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg))
84698 @@ -1288,6 +1295,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
84699
84700 if (ops->cee_peer_getpfc) {
84701 struct cee_pfc pfc;
84702 + memset(&pfc, 0, sizeof(pfc));
84703 err = ops->cee_peer_getpfc(netdev, &pfc);
84704 if (!err &&
84705 nla_put(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc))
84706 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
84707 index 307c322..78a4c6f 100644
84708 --- a/net/decnet/af_decnet.c
84709 +++ b/net/decnet/af_decnet.c
84710 @@ -468,6 +468,7 @@ static struct proto dn_proto = {
84711 .sysctl_rmem = sysctl_decnet_rmem,
84712 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
84713 .obj_size = sizeof(struct dn_sock),
84714 + .slab_flags = SLAB_USERCOPY,
84715 };
84716
84717 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
84718 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
84719 index a55eecc..dd8428c 100644
84720 --- a/net/decnet/sysctl_net_decnet.c
84721 +++ b/net/decnet/sysctl_net_decnet.c
84722 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
84723
84724 if (len > *lenp) len = *lenp;
84725
84726 - if (copy_to_user(buffer, addr, len))
84727 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
84728 return -EFAULT;
84729
84730 *lenp = len;
84731 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
84732
84733 if (len > *lenp) len = *lenp;
84734
84735 - if (copy_to_user(buffer, devname, len))
84736 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
84737 return -EFAULT;
84738
84739 *lenp = len;
84740 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
84741 index fcf104e..95552d4 100644
84742 --- a/net/ipv4/af_inet.c
84743 +++ b/net/ipv4/af_inet.c
84744 @@ -1717,13 +1717,9 @@ static int __init inet_init(void)
84745
84746 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
84747
84748 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
84749 - if (!sysctl_local_reserved_ports)
84750 - goto out;
84751 -
84752 rc = proto_register(&tcp_prot, 1);
84753 if (rc)
84754 - goto out_free_reserved_ports;
84755 + goto out;
84756
84757 rc = proto_register(&udp_prot, 1);
84758 if (rc)
84759 @@ -1832,8 +1828,6 @@ out_unregister_udp_proto:
84760 proto_unregister(&udp_prot);
84761 out_unregister_tcp_proto:
84762 proto_unregister(&tcp_prot);
84763 -out_free_reserved_ports:
84764 - kfree(sysctl_local_reserved_ports);
84765 goto out;
84766 }
84767
84768 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
84769 index a69b4e4..dbccba5 100644
84770 --- a/net/ipv4/ah4.c
84771 +++ b/net/ipv4/ah4.c
84772 @@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
84773 return;
84774
84775 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
84776 - atomic_inc(&flow_cache_genid);
84777 + atomic_inc_unchecked(&flow_cache_genid);
84778 rt_genid_bump(net);
84779
84780 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
84781 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
84782 index a8e4f26..25e5f40 100644
84783 --- a/net/ipv4/devinet.c
84784 +++ b/net/ipv4/devinet.c
84785 @@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
84786 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
84787 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
84788
84789 -static struct devinet_sysctl_table {
84790 +static const struct devinet_sysctl_table {
84791 struct ctl_table_header *sysctl_header;
84792 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
84793 } devinet_sysctl = {
84794 @@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
84795 int err;
84796 struct ipv4_devconf *all, *dflt;
84797 #ifdef CONFIG_SYSCTL
84798 - struct ctl_table *tbl = ctl_forward_entry;
84799 + ctl_table_no_const *tbl = NULL;
84800 struct ctl_table_header *forw_hdr;
84801 #endif
84802
84803 @@ -1899,7 +1899,7 @@ static __net_init int devinet_init_net(struct net *net)
84804 goto err_alloc_dflt;
84805
84806 #ifdef CONFIG_SYSCTL
84807 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
84808 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
84809 if (tbl == NULL)
84810 goto err_alloc_ctl;
84811
84812 @@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
84813 goto err_reg_dflt;
84814
84815 err = -ENOMEM;
84816 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
84817 + if (!net_eq(net, &init_net))
84818 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
84819 + else
84820 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
84821 if (forw_hdr == NULL)
84822 goto err_reg_ctl;
84823 net->ipv4.forw_hdr = forw_hdr;
84824 @@ -1935,8 +1938,7 @@ err_reg_ctl:
84825 err_reg_dflt:
84826 __devinet_sysctl_unregister(all);
84827 err_reg_all:
84828 - if (tbl != ctl_forward_entry)
84829 - kfree(tbl);
84830 + kfree(tbl);
84831 err_alloc_ctl:
84832 #endif
84833 if (dflt != &ipv4_devconf_dflt)
84834 diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
84835 index 3b4f0cd..8cb864c 100644
84836 --- a/net/ipv4/esp4.c
84837 +++ b/net/ipv4/esp4.c
84838 @@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
84839 return;
84840
84841 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
84842 - atomic_inc(&flow_cache_genid);
84843 + atomic_inc_unchecked(&flow_cache_genid);
84844 rt_genid_bump(net);
84845
84846 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
84847 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
84848 index 5cd75e2..f57ef39 100644
84849 --- a/net/ipv4/fib_frontend.c
84850 +++ b/net/ipv4/fib_frontend.c
84851 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
84852 #ifdef CONFIG_IP_ROUTE_MULTIPATH
84853 fib_sync_up(dev);
84854 #endif
84855 - atomic_inc(&net->ipv4.dev_addr_genid);
84856 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84857 rt_cache_flush(dev_net(dev));
84858 break;
84859 case NETDEV_DOWN:
84860 fib_del_ifaddr(ifa, NULL);
84861 - atomic_inc(&net->ipv4.dev_addr_genid);
84862 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84863 if (ifa->ifa_dev->ifa_list == NULL) {
84864 /* Last address was deleted from this interface.
84865 * Disable IP.
84866 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
84867 #ifdef CONFIG_IP_ROUTE_MULTIPATH
84868 fib_sync_up(dev);
84869 #endif
84870 - atomic_inc(&net->ipv4.dev_addr_genid);
84871 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84872 rt_cache_flush(net);
84873 break;
84874 case NETDEV_DOWN:
84875 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
84876 index 4797a80..2bd54e9 100644
84877 --- a/net/ipv4/fib_semantics.c
84878 +++ b/net/ipv4/fib_semantics.c
84879 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
84880 nh->nh_saddr = inet_select_addr(nh->nh_dev,
84881 nh->nh_gw,
84882 nh->nh_parent->fib_scope);
84883 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
84884 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
84885
84886 return nh->nh_saddr;
84887 }
84888 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
84889 index d0670f0..744ac80 100644
84890 --- a/net/ipv4/inet_connection_sock.c
84891 +++ b/net/ipv4/inet_connection_sock.c
84892 @@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
84893 .range = { 32768, 61000 },
84894 };
84895
84896 -unsigned long *sysctl_local_reserved_ports;
84897 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
84898 EXPORT_SYMBOL(sysctl_local_reserved_ports);
84899
84900 void inet_get_local_port_range(int *low, int *high)
84901 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
84902 index fa3ae81..0dbe6b8 100644
84903 --- a/net/ipv4/inet_hashtables.c
84904 +++ b/net/ipv4/inet_hashtables.c
84905 @@ -18,12 +18,15 @@
84906 #include <linux/sched.h>
84907 #include <linux/slab.h>
84908 #include <linux/wait.h>
84909 +#include <linux/security.h>
84910
84911 #include <net/inet_connection_sock.h>
84912 #include <net/inet_hashtables.h>
84913 #include <net/secure_seq.h>
84914 #include <net/ip.h>
84915
84916 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
84917 +
84918 /*
84919 * Allocate and initialize a new local port bind bucket.
84920 * The bindhash mutex for snum's hash chain must be held here.
84921 @@ -540,6 +543,8 @@ ok:
84922 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
84923 spin_unlock(&head->lock);
84924
84925 + gr_update_task_in_ip_table(current, inet_sk(sk));
84926 +
84927 if (tw) {
84928 inet_twsk_deschedule(tw, death_row);
84929 while (twrefcnt) {
84930 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
84931 index 000e3d2..5472da3 100644
84932 --- a/net/ipv4/inetpeer.c
84933 +++ b/net/ipv4/inetpeer.c
84934 @@ -503,8 +503,8 @@ relookup:
84935 if (p) {
84936 p->daddr = *daddr;
84937 atomic_set(&p->refcnt, 1);
84938 - atomic_set(&p->rid, 0);
84939 - atomic_set(&p->ip_id_count,
84940 + atomic_set_unchecked(&p->rid, 0);
84941 + atomic_set_unchecked(&p->ip_id_count,
84942 (daddr->family == AF_INET) ?
84943 secure_ip_id(daddr->addr.a4) :
84944 secure_ipv6_id(daddr->addr.a6));
84945 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
84946 index eb9d63a..31c5372 100644
84947 --- a/net/ipv4/ip_fragment.c
84948 +++ b/net/ipv4/ip_fragment.c
84949 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
84950 return 0;
84951
84952 start = qp->rid;
84953 - end = atomic_inc_return(&peer->rid);
84954 + end = atomic_inc_return_unchecked(&peer->rid);
84955 qp->rid = end;
84956
84957 rc = qp->q.fragments && (end - start) > max;
84958 @@ -789,12 +789,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
84959
84960 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
84961 {
84962 - struct ctl_table *table;
84963 + ctl_table_no_const *table = NULL;
84964 struct ctl_table_header *hdr;
84965
84966 - table = ip4_frags_ns_ctl_table;
84967 if (!net_eq(net, &init_net)) {
84968 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
84969 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
84970 if (table == NULL)
84971 goto err_alloc;
84972
84973 @@ -805,9 +804,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
84974 /* Don't export sysctls to unprivileged users */
84975 if (net->user_ns != &init_user_ns)
84976 table[0].procname = NULL;
84977 - }
84978 + hdr = register_net_sysctl(net, "net/ipv4", table);
84979 + } else
84980 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
84981
84982 - hdr = register_net_sysctl(net, "net/ipv4", table);
84983 if (hdr == NULL)
84984 goto err_reg;
84985
84986 @@ -815,8 +815,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
84987 return 0;
84988
84989 err_reg:
84990 - if (!net_eq(net, &init_net))
84991 - kfree(table);
84992 + kfree(table);
84993 err_alloc:
84994 return -ENOMEM;
84995 }
84996 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
84997 index e81b1ca..6f3b5b9 100644
84998 --- a/net/ipv4/ip_gre.c
84999 +++ b/net/ipv4/ip_gre.c
85000 @@ -124,7 +124,7 @@ static bool log_ecn_error = true;
85001 module_param(log_ecn_error, bool, 0644);
85002 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
85003
85004 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
85005 +static struct rtnl_link_ops ipgre_link_ops;
85006 static int ipgre_tunnel_init(struct net_device *dev);
85007 static void ipgre_tunnel_setup(struct net_device *dev);
85008 static int ipgre_tunnel_bind_dev(struct net_device *dev);
85009 @@ -1756,7 +1756,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
85010 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
85011 };
85012
85013 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85014 +static struct rtnl_link_ops ipgre_link_ops = {
85015 .kind = "gre",
85016 .maxtype = IFLA_GRE_MAX,
85017 .policy = ipgre_policy,
85018 @@ -1769,7 +1769,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85019 .fill_info = ipgre_fill_info,
85020 };
85021
85022 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
85023 +static struct rtnl_link_ops ipgre_tap_ops = {
85024 .kind = "gretap",
85025 .maxtype = IFLA_GRE_MAX,
85026 .policy = ipgre_policy,
85027 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
85028 index d9c4f11..02b82db 100644
85029 --- a/net/ipv4/ip_sockglue.c
85030 +++ b/net/ipv4/ip_sockglue.c
85031 @@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85032 len = min_t(unsigned int, len, opt->optlen);
85033 if (put_user(len, optlen))
85034 return -EFAULT;
85035 - if (copy_to_user(optval, opt->__data, len))
85036 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
85037 + copy_to_user(optval, opt->__data, len))
85038 return -EFAULT;
85039 return 0;
85040 }
85041 @@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85042 if (sk->sk_type != SOCK_STREAM)
85043 return -ENOPROTOOPT;
85044
85045 - msg.msg_control = optval;
85046 + msg.msg_control = (void __force_kernel *)optval;
85047 msg.msg_controllen = len;
85048 msg.msg_flags = flags;
85049
85050 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
85051 index c3a4233..1412161 100644
85052 --- a/net/ipv4/ip_vti.c
85053 +++ b/net/ipv4/ip_vti.c
85054 @@ -47,7 +47,7 @@
85055 #define HASH_SIZE 16
85056 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
85057
85058 -static struct rtnl_link_ops vti_link_ops __read_mostly;
85059 +static struct rtnl_link_ops vti_link_ops;
85060
85061 static int vti_net_id __read_mostly;
85062 struct vti_net {
85063 @@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
85064 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
85065 };
85066
85067 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
85068 +static struct rtnl_link_ops vti_link_ops = {
85069 .kind = "vti",
85070 .maxtype = IFLA_VTI_MAX,
85071 .policy = vti_policy,
85072 diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
85073 index 9a46dae..5f793a0 100644
85074 --- a/net/ipv4/ipcomp.c
85075 +++ b/net/ipv4/ipcomp.c
85076 @@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
85077 return;
85078
85079 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85080 - atomic_inc(&flow_cache_genid);
85081 + atomic_inc_unchecked(&flow_cache_genid);
85082 rt_genid_bump(net);
85083
85084 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
85085 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
85086 index a2e50ae..e152b7c 100644
85087 --- a/net/ipv4/ipconfig.c
85088 +++ b/net/ipv4/ipconfig.c
85089 @@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
85090
85091 mm_segment_t oldfs = get_fs();
85092 set_fs(get_ds());
85093 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85094 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85095 set_fs(oldfs);
85096 return res;
85097 }
85098 @@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
85099
85100 mm_segment_t oldfs = get_fs();
85101 set_fs(get_ds());
85102 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85103 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85104 set_fs(oldfs);
85105 return res;
85106 }
85107 @@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
85108
85109 mm_segment_t oldfs = get_fs();
85110 set_fs(get_ds());
85111 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
85112 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
85113 set_fs(oldfs);
85114 return res;
85115 }
85116 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
85117 index 191fc24..1b3b804 100644
85118 --- a/net/ipv4/ipip.c
85119 +++ b/net/ipv4/ipip.c
85120 @@ -138,7 +138,7 @@ struct ipip_net {
85121 static int ipip_tunnel_init(struct net_device *dev);
85122 static void ipip_tunnel_setup(struct net_device *dev);
85123 static void ipip_dev_free(struct net_device *dev);
85124 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
85125 +static struct rtnl_link_ops ipip_link_ops;
85126
85127 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
85128 struct rtnl_link_stats64 *tot)
85129 @@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
85130 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
85131 };
85132
85133 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
85134 +static struct rtnl_link_ops ipip_link_ops = {
85135 .kind = "ipip",
85136 .maxtype = IFLA_IPTUN_MAX,
85137 .policy = ipip_policy,
85138 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
85139 index 3ea4127..849297b 100644
85140 --- a/net/ipv4/netfilter/arp_tables.c
85141 +++ b/net/ipv4/netfilter/arp_tables.c
85142 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
85143 #endif
85144
85145 static int get_info(struct net *net, void __user *user,
85146 - const int *len, int compat)
85147 + int len, int compat)
85148 {
85149 char name[XT_TABLE_MAXNAMELEN];
85150 struct xt_table *t;
85151 int ret;
85152
85153 - if (*len != sizeof(struct arpt_getinfo)) {
85154 - duprintf("length %u != %Zu\n", *len,
85155 + if (len != sizeof(struct arpt_getinfo)) {
85156 + duprintf("length %u != %Zu\n", len,
85157 sizeof(struct arpt_getinfo));
85158 return -EINVAL;
85159 }
85160 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
85161 info.size = private->size;
85162 strcpy(info.name, name);
85163
85164 - if (copy_to_user(user, &info, *len) != 0)
85165 + if (copy_to_user(user, &info, len) != 0)
85166 ret = -EFAULT;
85167 else
85168 ret = 0;
85169 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
85170
85171 switch (cmd) {
85172 case ARPT_SO_GET_INFO:
85173 - ret = get_info(sock_net(sk), user, len, 1);
85174 + ret = get_info(sock_net(sk), user, *len, 1);
85175 break;
85176 case ARPT_SO_GET_ENTRIES:
85177 ret = compat_get_entries(sock_net(sk), user, len);
85178 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
85179
85180 switch (cmd) {
85181 case ARPT_SO_GET_INFO:
85182 - ret = get_info(sock_net(sk), user, len, 0);
85183 + ret = get_info(sock_net(sk), user, *len, 0);
85184 break;
85185
85186 case ARPT_SO_GET_ENTRIES:
85187 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
85188 index 17c5e06..1b91206 100644
85189 --- a/net/ipv4/netfilter/ip_tables.c
85190 +++ b/net/ipv4/netfilter/ip_tables.c
85191 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
85192 #endif
85193
85194 static int get_info(struct net *net, void __user *user,
85195 - const int *len, int compat)
85196 + int len, int compat)
85197 {
85198 char name[XT_TABLE_MAXNAMELEN];
85199 struct xt_table *t;
85200 int ret;
85201
85202 - if (*len != sizeof(struct ipt_getinfo)) {
85203 - duprintf("length %u != %zu\n", *len,
85204 + if (len != sizeof(struct ipt_getinfo)) {
85205 + duprintf("length %u != %zu\n", len,
85206 sizeof(struct ipt_getinfo));
85207 return -EINVAL;
85208 }
85209 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
85210 info.size = private->size;
85211 strcpy(info.name, name);
85212
85213 - if (copy_to_user(user, &info, *len) != 0)
85214 + if (copy_to_user(user, &info, len) != 0)
85215 ret = -EFAULT;
85216 else
85217 ret = 0;
85218 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85219
85220 switch (cmd) {
85221 case IPT_SO_GET_INFO:
85222 - ret = get_info(sock_net(sk), user, len, 1);
85223 + ret = get_info(sock_net(sk), user, *len, 1);
85224 break;
85225 case IPT_SO_GET_ENTRIES:
85226 ret = compat_get_entries(sock_net(sk), user, len);
85227 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85228
85229 switch (cmd) {
85230 case IPT_SO_GET_INFO:
85231 - ret = get_info(sock_net(sk), user, len, 0);
85232 + ret = get_info(sock_net(sk), user, *len, 0);
85233 break;
85234
85235 case IPT_SO_GET_ENTRIES:
85236 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
85237 index dc454cc..5bb917f 100644
85238 --- a/net/ipv4/ping.c
85239 +++ b/net/ipv4/ping.c
85240 @@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
85241 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
85242 0, sock_i_ino(sp),
85243 atomic_read(&sp->sk_refcnt), sp,
85244 - atomic_read(&sp->sk_drops), len);
85245 + atomic_read_unchecked(&sp->sk_drops), len);
85246 }
85247
85248 static int ping_seq_show(struct seq_file *seq, void *v)
85249 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
85250 index 6f08991..55867ad 100644
85251 --- a/net/ipv4/raw.c
85252 +++ b/net/ipv4/raw.c
85253 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
85254 int raw_rcv(struct sock *sk, struct sk_buff *skb)
85255 {
85256 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
85257 - atomic_inc(&sk->sk_drops);
85258 + atomic_inc_unchecked(&sk->sk_drops);
85259 kfree_skb(skb);
85260 return NET_RX_DROP;
85261 }
85262 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
85263
85264 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
85265 {
85266 + struct icmp_filter filter;
85267 +
85268 if (optlen > sizeof(struct icmp_filter))
85269 optlen = sizeof(struct icmp_filter);
85270 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
85271 + if (copy_from_user(&filter, optval, optlen))
85272 return -EFAULT;
85273 + raw_sk(sk)->filter = filter;
85274 return 0;
85275 }
85276
85277 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
85278 {
85279 int len, ret = -EFAULT;
85280 + struct icmp_filter filter;
85281
85282 if (get_user(len, optlen))
85283 goto out;
85284 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
85285 if (len > sizeof(struct icmp_filter))
85286 len = sizeof(struct icmp_filter);
85287 ret = -EFAULT;
85288 - if (put_user(len, optlen) ||
85289 - copy_to_user(optval, &raw_sk(sk)->filter, len))
85290 + filter = raw_sk(sk)->filter;
85291 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
85292 goto out;
85293 ret = 0;
85294 out: return ret;
85295 @@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
85296 0, 0L, 0,
85297 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
85298 0, sock_i_ino(sp),
85299 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
85300 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
85301 }
85302
85303 static int raw_seq_show(struct seq_file *seq, void *v)
85304 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
85305 index a0fcc47..32e2c89 100644
85306 --- a/net/ipv4/route.c
85307 +++ b/net/ipv4/route.c
85308 @@ -2552,34 +2552,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
85309 .maxlen = sizeof(int),
85310 .mode = 0200,
85311 .proc_handler = ipv4_sysctl_rtcache_flush,
85312 + .extra1 = &init_net,
85313 },
85314 { },
85315 };
85316
85317 static __net_init int sysctl_route_net_init(struct net *net)
85318 {
85319 - struct ctl_table *tbl;
85320 + ctl_table_no_const *tbl = NULL;
85321
85322 - tbl = ipv4_route_flush_table;
85323 if (!net_eq(net, &init_net)) {
85324 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
85325 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
85326 if (tbl == NULL)
85327 goto err_dup;
85328
85329 /* Don't export sysctls to unprivileged users */
85330 if (net->user_ns != &init_user_ns)
85331 tbl[0].procname = NULL;
85332 - }
85333 - tbl[0].extra1 = net;
85334 + tbl[0].extra1 = net;
85335 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
85336 + } else
85337 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
85338
85339 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
85340 if (net->ipv4.route_hdr == NULL)
85341 goto err_reg;
85342 return 0;
85343
85344 err_reg:
85345 - if (tbl != ipv4_route_flush_table)
85346 - kfree(tbl);
85347 + kfree(tbl);
85348 err_dup:
85349 return -ENOMEM;
85350 }
85351 @@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
85352
85353 static __net_init int rt_genid_init(struct net *net)
85354 {
85355 - atomic_set(&net->rt_genid, 0);
85356 + atomic_set_unchecked(&net->rt_genid, 0);
85357 get_random_bytes(&net->ipv4.dev_addr_genid,
85358 sizeof(net->ipv4.dev_addr_genid));
85359 return 0;
85360 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
85361 index d84400b..62e066e 100644
85362 --- a/net/ipv4/sysctl_net_ipv4.c
85363 +++ b/net/ipv4/sysctl_net_ipv4.c
85364 @@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
85365 {
85366 int ret;
85367 int range[2];
85368 - ctl_table tmp = {
85369 + ctl_table_no_const tmp = {
85370 .data = &range,
85371 .maxlen = sizeof(range),
85372 .mode = table->mode,
85373 @@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
85374 int ret;
85375 gid_t urange[2];
85376 kgid_t low, high;
85377 - ctl_table tmp = {
85378 + ctl_table_no_const tmp = {
85379 .data = &urange,
85380 .maxlen = sizeof(urange),
85381 .mode = table->mode,
85382 @@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
85383 void __user *buffer, size_t *lenp, loff_t *ppos)
85384 {
85385 char val[TCP_CA_NAME_MAX];
85386 - ctl_table tbl = {
85387 + ctl_table_no_const tbl = {
85388 .data = val,
85389 .maxlen = TCP_CA_NAME_MAX,
85390 };
85391 @@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
85392 void __user *buffer, size_t *lenp,
85393 loff_t *ppos)
85394 {
85395 - ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
85396 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
85397 int ret;
85398
85399 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
85400 @@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
85401 void __user *buffer, size_t *lenp,
85402 loff_t *ppos)
85403 {
85404 - ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
85405 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
85406 int ret;
85407
85408 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
85409 @@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
85410 struct mem_cgroup *memcg;
85411 #endif
85412
85413 - ctl_table tmp = {
85414 + ctl_table_no_const tmp = {
85415 .data = &vec,
85416 .maxlen = sizeof(vec),
85417 .mode = ctl->mode,
85418 };
85419
85420 if (!write) {
85421 - ctl->data = &net->ipv4.sysctl_tcp_mem;
85422 - return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
85423 + ctl_table_no_const tcp_mem = *ctl;
85424 +
85425 + tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
85426 + return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
85427 }
85428
85429 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
85430 @@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
85431 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
85432 size_t *lenp, loff_t *ppos)
85433 {
85434 - ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
85435 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
85436 struct tcp_fastopen_context *ctxt;
85437 int ret;
85438 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
85439 @@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
85440 },
85441 {
85442 .procname = "ip_local_reserved_ports",
85443 - .data = NULL, /* initialized in sysctl_ipv4_init */
85444 + .data = sysctl_local_reserved_ports,
85445 .maxlen = 65536,
85446 .mode = 0644,
85447 .proc_handler = proc_do_large_bitmap,
85448 @@ -860,11 +862,10 @@ static struct ctl_table ipv4_net_table[] = {
85449
85450 static __net_init int ipv4_sysctl_init_net(struct net *net)
85451 {
85452 - struct ctl_table *table;
85453 + ctl_table_no_const *table = NULL;
85454
85455 - table = ipv4_net_table;
85456 if (!net_eq(net, &init_net)) {
85457 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
85458 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
85459 if (table == NULL)
85460 goto err_alloc;
85461
85462 @@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
85463
85464 tcp_init_mem(net);
85465
85466 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
85467 + if (!net_eq(net, &init_net))
85468 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
85469 + else
85470 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
85471 if (net->ipv4.ipv4_hdr == NULL)
85472 goto err_reg;
85473
85474 return 0;
85475
85476 err_reg:
85477 - if (!net_eq(net, &init_net))
85478 - kfree(table);
85479 + kfree(table);
85480 err_alloc:
85481 return -ENOMEM;
85482 }
85483 @@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
85484 static __init int sysctl_ipv4_init(void)
85485 {
85486 struct ctl_table_header *hdr;
85487 - struct ctl_table *i;
85488 -
85489 - for (i = ipv4_table; i->procname; i++) {
85490 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
85491 - i->data = sysctl_local_reserved_ports;
85492 - break;
85493 - }
85494 - }
85495 - if (!i->procname)
85496 - return -EINVAL;
85497
85498 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
85499 if (hdr == NULL)
85500 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
85501 index ad70a96..50cb55b 100644
85502 --- a/net/ipv4/tcp_input.c
85503 +++ b/net/ipv4/tcp_input.c
85504 @@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
85505 * simplifies code)
85506 */
85507 static void
85508 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
85509 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
85510 struct sk_buff *head, struct sk_buff *tail,
85511 u32 start, u32 end)
85512 {
85513 @@ -5850,6 +5850,7 @@ discard:
85514 tcp_paws_reject(&tp->rx_opt, 0))
85515 goto discard_and_undo;
85516
85517 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
85518 if (th->syn) {
85519 /* We see SYN without ACK. It is attempt of
85520 * simultaneous connect with crossed SYNs.
85521 @@ -5900,6 +5901,7 @@ discard:
85522 goto discard;
85523 #endif
85524 }
85525 +#endif
85526 /* "fifth, if neither of the SYN or RST bits is set then
85527 * drop the segment and return."
85528 */
85529 @@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
85530 goto discard;
85531
85532 if (th->syn) {
85533 - if (th->fin)
85534 + if (th->fin || th->urg || th->psh)
85535 goto discard;
85536 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
85537 return 1;
85538 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
85539 index eadb693..e8f7251 100644
85540 --- a/net/ipv4/tcp_ipv4.c
85541 +++ b/net/ipv4/tcp_ipv4.c
85542 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
85543 EXPORT_SYMBOL(sysctl_tcp_low_latency);
85544
85545
85546 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85547 +extern int grsec_enable_blackhole;
85548 +#endif
85549 +
85550 #ifdef CONFIG_TCP_MD5SIG
85551 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
85552 __be32 daddr, __be32 saddr, const struct tcphdr *th);
85553 @@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
85554 return 0;
85555
85556 reset:
85557 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85558 + if (!grsec_enable_blackhole)
85559 +#endif
85560 tcp_v4_send_reset(rsk, skb);
85561 discard:
85562 kfree_skb(skb);
85563 @@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
85564 TCP_SKB_CB(skb)->sacked = 0;
85565
85566 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
85567 - if (!sk)
85568 + if (!sk) {
85569 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85570 + ret = 1;
85571 +#endif
85572 goto no_tcp_socket;
85573 -
85574 + }
85575 process:
85576 - if (sk->sk_state == TCP_TIME_WAIT)
85577 + if (sk->sk_state == TCP_TIME_WAIT) {
85578 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85579 + ret = 2;
85580 +#endif
85581 goto do_time_wait;
85582 + }
85583
85584 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
85585 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
85586 @@ -2050,6 +2064,10 @@ no_tcp_socket:
85587 bad_packet:
85588 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
85589 } else {
85590 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85591 + if (!grsec_enable_blackhole || (ret == 1 &&
85592 + (skb->dev->flags & IFF_LOOPBACK)))
85593 +#endif
85594 tcp_v4_send_reset(NULL, skb);
85595 }
85596
85597 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
85598 index f35f2df..ccb5ca6 100644
85599 --- a/net/ipv4/tcp_minisocks.c
85600 +++ b/net/ipv4/tcp_minisocks.c
85601 @@ -27,6 +27,10 @@
85602 #include <net/inet_common.h>
85603 #include <net/xfrm.h>
85604
85605 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85606 +extern int grsec_enable_blackhole;
85607 +#endif
85608 +
85609 int sysctl_tcp_syncookies __read_mostly = 1;
85610 EXPORT_SYMBOL(sysctl_tcp_syncookies);
85611
85612 @@ -742,7 +746,10 @@ embryonic_reset:
85613 * avoid becoming vulnerable to outside attack aiming at
85614 * resetting legit local connections.
85615 */
85616 - req->rsk_ops->send_reset(sk, skb);
85617 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85618 + if (!grsec_enable_blackhole)
85619 +#endif
85620 + req->rsk_ops->send_reset(sk, skb);
85621 } else if (fastopen) { /* received a valid RST pkt */
85622 reqsk_fastopen_remove(sk, req, true);
85623 tcp_reset(sk);
85624 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
85625 index 4526fe6..1a34e43 100644
85626 --- a/net/ipv4/tcp_probe.c
85627 +++ b/net/ipv4/tcp_probe.c
85628 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
85629 if (cnt + width >= len)
85630 break;
85631
85632 - if (copy_to_user(buf + cnt, tbuf, width))
85633 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
85634 return -EFAULT;
85635 cnt += width;
85636 }
85637 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
85638 index b78aac3..e18230b 100644
85639 --- a/net/ipv4/tcp_timer.c
85640 +++ b/net/ipv4/tcp_timer.c
85641 @@ -22,6 +22,10 @@
85642 #include <linux/gfp.h>
85643 #include <net/tcp.h>
85644
85645 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85646 +extern int grsec_lastack_retries;
85647 +#endif
85648 +
85649 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
85650 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
85651 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
85652 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
85653 }
85654 }
85655
85656 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85657 + if ((sk->sk_state == TCP_LAST_ACK) &&
85658 + (grsec_lastack_retries > 0) &&
85659 + (grsec_lastack_retries < retry_until))
85660 + retry_until = grsec_lastack_retries;
85661 +#endif
85662 +
85663 if (retransmits_timed_out(sk, retry_until,
85664 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
85665 /* Has it gone just too far? */
85666 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
85667 index 1f4d405..3524677 100644
85668 --- a/net/ipv4/udp.c
85669 +++ b/net/ipv4/udp.c
85670 @@ -87,6 +87,7 @@
85671 #include <linux/types.h>
85672 #include <linux/fcntl.h>
85673 #include <linux/module.h>
85674 +#include <linux/security.h>
85675 #include <linux/socket.h>
85676 #include <linux/sockios.h>
85677 #include <linux/igmp.h>
85678 @@ -111,6 +112,10 @@
85679 #include <trace/events/skb.h>
85680 #include "udp_impl.h"
85681
85682 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85683 +extern int grsec_enable_blackhole;
85684 +#endif
85685 +
85686 struct udp_table udp_table __read_mostly;
85687 EXPORT_SYMBOL(udp_table);
85688
85689 @@ -569,6 +574,9 @@ found:
85690 return s;
85691 }
85692
85693 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
85694 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
85695 +
85696 /*
85697 * This routine is called by the ICMP module when it gets some
85698 * sort of error condition. If err < 0 then the socket should
85699 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
85700 dport = usin->sin_port;
85701 if (dport == 0)
85702 return -EINVAL;
85703 +
85704 + err = gr_search_udp_sendmsg(sk, usin);
85705 + if (err)
85706 + return err;
85707 } else {
85708 if (sk->sk_state != TCP_ESTABLISHED)
85709 return -EDESTADDRREQ;
85710 +
85711 + err = gr_search_udp_sendmsg(sk, NULL);
85712 + if (err)
85713 + return err;
85714 +
85715 daddr = inet->inet_daddr;
85716 dport = inet->inet_dport;
85717 /* Open fast path for connected socket.
85718 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
85719 udp_lib_checksum_complete(skb)) {
85720 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
85721 IS_UDPLITE(sk));
85722 - atomic_inc(&sk->sk_drops);
85723 + atomic_inc_unchecked(&sk->sk_drops);
85724 __skb_unlink(skb, rcvq);
85725 __skb_queue_tail(&list_kill, skb);
85726 }
85727 @@ -1194,6 +1211,10 @@ try_again:
85728 if (!skb)
85729 goto out;
85730
85731 + err = gr_search_udp_recvmsg(sk, skb);
85732 + if (err)
85733 + goto out_free;
85734 +
85735 ulen = skb->len - sizeof(struct udphdr);
85736 copied = len;
85737 if (copied > ulen)
85738 @@ -1227,7 +1248,7 @@ try_again:
85739 if (unlikely(err)) {
85740 trace_kfree_skb(skb, udp_recvmsg);
85741 if (!peeked) {
85742 - atomic_inc(&sk->sk_drops);
85743 + atomic_inc_unchecked(&sk->sk_drops);
85744 UDP_INC_STATS_USER(sock_net(sk),
85745 UDP_MIB_INERRORS, is_udplite);
85746 }
85747 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85748
85749 drop:
85750 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
85751 - atomic_inc(&sk->sk_drops);
85752 + atomic_inc_unchecked(&sk->sk_drops);
85753 kfree_skb(skb);
85754 return -1;
85755 }
85756 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
85757 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
85758
85759 if (!skb1) {
85760 - atomic_inc(&sk->sk_drops);
85761 + atomic_inc_unchecked(&sk->sk_drops);
85762 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
85763 IS_UDPLITE(sk));
85764 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
85765 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
85766 goto csum_error;
85767
85768 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
85769 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85770 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
85771 +#endif
85772 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
85773
85774 /*
85775 @@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
85776 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
85777 0, sock_i_ino(sp),
85778 atomic_read(&sp->sk_refcnt), sp,
85779 - atomic_read(&sp->sk_drops), len);
85780 + atomic_read_unchecked(&sp->sk_drops), len);
85781 }
85782
85783 int udp4_seq_show(struct seq_file *seq, void *v)
85784 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
85785 index 1b5d8cb..ffb0833 100644
85786 --- a/net/ipv6/addrconf.c
85787 +++ b/net/ipv6/addrconf.c
85788 @@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
85789 p.iph.ihl = 5;
85790 p.iph.protocol = IPPROTO_IPV6;
85791 p.iph.ttl = 64;
85792 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
85793 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
85794
85795 if (ops->ndo_do_ioctl) {
85796 mm_segment_t oldfs = get_fs();
85797 @@ -4388,7 +4388,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
85798 int *valp = ctl->data;
85799 int val = *valp;
85800 loff_t pos = *ppos;
85801 - ctl_table lctl;
85802 + ctl_table_no_const lctl;
85803 int ret;
85804
85805 /*
85806 @@ -4470,7 +4470,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
85807 int *valp = ctl->data;
85808 int val = *valp;
85809 loff_t pos = *ppos;
85810 - ctl_table lctl;
85811 + ctl_table_no_const lctl;
85812 int ret;
85813
85814 /*
85815 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
85816 index fff5bdd..15194fb 100644
85817 --- a/net/ipv6/icmp.c
85818 +++ b/net/ipv6/icmp.c
85819 @@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
85820
85821 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
85822 {
85823 - struct ctl_table *table;
85824 + ctl_table_no_const *table;
85825
85826 table = kmemdup(ipv6_icmp_table_template,
85827 sizeof(ipv6_icmp_table_template),
85828 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
85829 index 131dd09..f7ed64f 100644
85830 --- a/net/ipv6/ip6_gre.c
85831 +++ b/net/ipv6/ip6_gre.c
85832 @@ -73,7 +73,7 @@ struct ip6gre_net {
85833 struct net_device *fb_tunnel_dev;
85834 };
85835
85836 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
85837 +static struct rtnl_link_ops ip6gre_link_ops;
85838 static int ip6gre_tunnel_init(struct net_device *dev);
85839 static void ip6gre_tunnel_setup(struct net_device *dev);
85840 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
85841 @@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
85842 }
85843
85844
85845 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
85846 +static struct inet6_protocol ip6gre_protocol = {
85847 .handler = ip6gre_rcv,
85848 .err_handler = ip6gre_err,
85849 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
85850 @@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
85851 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
85852 };
85853
85854 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
85855 +static struct rtnl_link_ops ip6gre_link_ops = {
85856 .kind = "ip6gre",
85857 .maxtype = IFLA_GRE_MAX,
85858 .policy = ip6gre_policy,
85859 @@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
85860 .fill_info = ip6gre_fill_info,
85861 };
85862
85863 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
85864 +static struct rtnl_link_ops ip6gre_tap_ops = {
85865 .kind = "ip6gretap",
85866 .maxtype = IFLA_GRE_MAX,
85867 .policy = ip6gre_policy,
85868 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
85869 index a14f28b..b4b8956 100644
85870 --- a/net/ipv6/ip6_tunnel.c
85871 +++ b/net/ipv6/ip6_tunnel.c
85872 @@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
85873
85874 static int ip6_tnl_dev_init(struct net_device *dev);
85875 static void ip6_tnl_dev_setup(struct net_device *dev);
85876 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
85877 +static struct rtnl_link_ops ip6_link_ops;
85878
85879 static int ip6_tnl_net_id __read_mostly;
85880 struct ip6_tnl_net {
85881 @@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
85882 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
85883 };
85884
85885 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
85886 +static struct rtnl_link_ops ip6_link_ops = {
85887 .kind = "ip6tnl",
85888 .maxtype = IFLA_IPTUN_MAX,
85889 .policy = ip6_tnl_policy,
85890 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
85891 index d1e2e8e..51c19ae 100644
85892 --- a/net/ipv6/ipv6_sockglue.c
85893 +++ b/net/ipv6/ipv6_sockglue.c
85894 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
85895 if (sk->sk_type != SOCK_STREAM)
85896 return -ENOPROTOOPT;
85897
85898 - msg.msg_control = optval;
85899 + msg.msg_control = (void __force_kernel *)optval;
85900 msg.msg_controllen = len;
85901 msg.msg_flags = flags;
85902
85903 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
85904 index 125a90d..2a11f36 100644
85905 --- a/net/ipv6/netfilter/ip6_tables.c
85906 +++ b/net/ipv6/netfilter/ip6_tables.c
85907 @@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
85908 #endif
85909
85910 static int get_info(struct net *net, void __user *user,
85911 - const int *len, int compat)
85912 + int len, int compat)
85913 {
85914 char name[XT_TABLE_MAXNAMELEN];
85915 struct xt_table *t;
85916 int ret;
85917
85918 - if (*len != sizeof(struct ip6t_getinfo)) {
85919 - duprintf("length %u != %zu\n", *len,
85920 + if (len != sizeof(struct ip6t_getinfo)) {
85921 + duprintf("length %u != %zu\n", len,
85922 sizeof(struct ip6t_getinfo));
85923 return -EINVAL;
85924 }
85925 @@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
85926 info.size = private->size;
85927 strcpy(info.name, name);
85928
85929 - if (copy_to_user(user, &info, *len) != 0)
85930 + if (copy_to_user(user, &info, len) != 0)
85931 ret = -EFAULT;
85932 else
85933 ret = 0;
85934 @@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85935
85936 switch (cmd) {
85937 case IP6T_SO_GET_INFO:
85938 - ret = get_info(sock_net(sk), user, len, 1);
85939 + ret = get_info(sock_net(sk), user, *len, 1);
85940 break;
85941 case IP6T_SO_GET_ENTRIES:
85942 ret = compat_get_entries(sock_net(sk), user, len);
85943 @@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85944
85945 switch (cmd) {
85946 case IP6T_SO_GET_INFO:
85947 - ret = get_info(sock_net(sk), user, len, 0);
85948 + ret = get_info(sock_net(sk), user, *len, 0);
85949 break;
85950
85951 case IP6T_SO_GET_ENTRIES:
85952 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
85953 index 3dacecc..2939087 100644
85954 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
85955 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
85956 @@ -87,12 +87,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
85957
85958 static int nf_ct_frag6_sysctl_register(struct net *net)
85959 {
85960 - struct ctl_table *table;
85961 + ctl_table_no_const *table = NULL;
85962 struct ctl_table_header *hdr;
85963
85964 - table = nf_ct_frag6_sysctl_table;
85965 if (!net_eq(net, &init_net)) {
85966 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
85967 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
85968 GFP_KERNEL);
85969 if (table == NULL)
85970 goto err_alloc;
85971 @@ -100,9 +99,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
85972 table[0].data = &net->ipv6.frags.high_thresh;
85973 table[1].data = &net->ipv6.frags.low_thresh;
85974 table[2].data = &net->ipv6.frags.timeout;
85975 - }
85976 -
85977 - hdr = register_net_sysctl(net, "net/netfilter", table);
85978 + hdr = register_net_sysctl(net, "net/netfilter", table);
85979 + } else
85980 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
85981 if (hdr == NULL)
85982 goto err_reg;
85983
85984 @@ -110,8 +109,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
85985 return 0;
85986
85987 err_reg:
85988 - if (!net_eq(net, &init_net))
85989 - kfree(table);
85990 + kfree(table);
85991 err_alloc:
85992 return -ENOMEM;
85993 }
85994 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
85995 index 70fa814..d70c28c 100644
85996 --- a/net/ipv6/raw.c
85997 +++ b/net/ipv6/raw.c
85998 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
85999 {
86000 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
86001 skb_checksum_complete(skb)) {
86002 - atomic_inc(&sk->sk_drops);
86003 + atomic_inc_unchecked(&sk->sk_drops);
86004 kfree_skb(skb);
86005 return NET_RX_DROP;
86006 }
86007 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86008 struct raw6_sock *rp = raw6_sk(sk);
86009
86010 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
86011 - atomic_inc(&sk->sk_drops);
86012 + atomic_inc_unchecked(&sk->sk_drops);
86013 kfree_skb(skb);
86014 return NET_RX_DROP;
86015 }
86016 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86017
86018 if (inet->hdrincl) {
86019 if (skb_checksum_complete(skb)) {
86020 - atomic_inc(&sk->sk_drops);
86021 + atomic_inc_unchecked(&sk->sk_drops);
86022 kfree_skb(skb);
86023 return NET_RX_DROP;
86024 }
86025 @@ -604,7 +604,7 @@ out:
86026 return err;
86027 }
86028
86029 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
86030 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
86031 struct flowi6 *fl6, struct dst_entry **dstp,
86032 unsigned int flags)
86033 {
86034 @@ -916,12 +916,15 @@ do_confirm:
86035 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
86036 char __user *optval, int optlen)
86037 {
86038 + struct icmp6_filter filter;
86039 +
86040 switch (optname) {
86041 case ICMPV6_FILTER:
86042 if (optlen > sizeof(struct icmp6_filter))
86043 optlen = sizeof(struct icmp6_filter);
86044 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
86045 + if (copy_from_user(&filter, optval, optlen))
86046 return -EFAULT;
86047 + raw6_sk(sk)->filter = filter;
86048 return 0;
86049 default:
86050 return -ENOPROTOOPT;
86051 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86052 char __user *optval, int __user *optlen)
86053 {
86054 int len;
86055 + struct icmp6_filter filter;
86056
86057 switch (optname) {
86058 case ICMPV6_FILTER:
86059 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86060 len = sizeof(struct icmp6_filter);
86061 if (put_user(len, optlen))
86062 return -EFAULT;
86063 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
86064 + filter = raw6_sk(sk)->filter;
86065 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
86066 return -EFAULT;
86067 return 0;
86068 default:
86069 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
86070 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
86071 0,
86072 sock_i_ino(sp),
86073 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
86074 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
86075 }
86076
86077 static int raw6_seq_show(struct seq_file *seq, void *v)
86078 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
86079 index e5253ec..0410257 100644
86080 --- a/net/ipv6/reassembly.c
86081 +++ b/net/ipv6/reassembly.c
86082 @@ -604,12 +604,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
86083
86084 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86085 {
86086 - struct ctl_table *table;
86087 + ctl_table_no_const *table = NULL;
86088 struct ctl_table_header *hdr;
86089
86090 - table = ip6_frags_ns_ctl_table;
86091 if (!net_eq(net, &init_net)) {
86092 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86093 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86094 if (table == NULL)
86095 goto err_alloc;
86096
86097 @@ -620,9 +619,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86098 /* Don't export sysctls to unprivileged users */
86099 if (net->user_ns != &init_user_ns)
86100 table[0].procname = NULL;
86101 - }
86102 + hdr = register_net_sysctl(net, "net/ipv6", table);
86103 + } else
86104 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
86105
86106 - hdr = register_net_sysctl(net, "net/ipv6", table);
86107 if (hdr == NULL)
86108 goto err_reg;
86109
86110 @@ -630,8 +630,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86111 return 0;
86112
86113 err_reg:
86114 - if (!net_eq(net, &init_net))
86115 - kfree(table);
86116 + kfree(table);
86117 err_alloc:
86118 return -ENOMEM;
86119 }
86120 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
86121 index 6f9f7b6..2306d63 100644
86122 --- a/net/ipv6/route.c
86123 +++ b/net/ipv6/route.c
86124 @@ -2965,7 +2965,7 @@ ctl_table ipv6_route_table_template[] = {
86125
86126 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
86127 {
86128 - struct ctl_table *table;
86129 + ctl_table_no_const *table;
86130
86131 table = kmemdup(ipv6_route_table_template,
86132 sizeof(ipv6_route_table_template),
86133 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
86134 index cfba99b..20ca511 100644
86135 --- a/net/ipv6/sit.c
86136 +++ b/net/ipv6/sit.c
86137 @@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
86138 static int ipip6_tunnel_init(struct net_device *dev);
86139 static void ipip6_tunnel_setup(struct net_device *dev);
86140 static void ipip6_dev_free(struct net_device *dev);
86141 -static struct rtnl_link_ops sit_link_ops __read_mostly;
86142 +static struct rtnl_link_ops sit_link_ops;
86143
86144 static int sit_net_id __read_mostly;
86145 struct sit_net {
86146 @@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
86147 #endif
86148 };
86149
86150 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
86151 +static struct rtnl_link_ops sit_link_ops = {
86152 .kind = "sit",
86153 .maxtype = IFLA_IPTUN_MAX,
86154 .policy = ipip6_policy,
86155 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
86156 index e85c48b..b8268d3 100644
86157 --- a/net/ipv6/sysctl_net_ipv6.c
86158 +++ b/net/ipv6/sysctl_net_ipv6.c
86159 @@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
86160
86161 static int __net_init ipv6_sysctl_net_init(struct net *net)
86162 {
86163 - struct ctl_table *ipv6_table;
86164 + ctl_table_no_const *ipv6_table;
86165 struct ctl_table *ipv6_route_table;
86166 struct ctl_table *ipv6_icmp_table;
86167 int err;
86168 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
86169 index 4f435371..5de9da7 100644
86170 --- a/net/ipv6/tcp_ipv6.c
86171 +++ b/net/ipv6/tcp_ipv6.c
86172 @@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
86173 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
86174 }
86175
86176 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86177 +extern int grsec_enable_blackhole;
86178 +#endif
86179 +
86180 static void tcp_v6_hash(struct sock *sk)
86181 {
86182 if (sk->sk_state != TCP_CLOSE) {
86183 @@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
86184 return 0;
86185
86186 reset:
86187 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86188 + if (!grsec_enable_blackhole)
86189 +#endif
86190 tcp_v6_send_reset(sk, skb);
86191 discard:
86192 if (opt_skb)
86193 @@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
86194 TCP_SKB_CB(skb)->sacked = 0;
86195
86196 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
86197 - if (!sk)
86198 + if (!sk) {
86199 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86200 + ret = 1;
86201 +#endif
86202 goto no_tcp_socket;
86203 + }
86204
86205 process:
86206 - if (sk->sk_state == TCP_TIME_WAIT)
86207 + if (sk->sk_state == TCP_TIME_WAIT) {
86208 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86209 + ret = 2;
86210 +#endif
86211 goto do_time_wait;
86212 + }
86213
86214 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
86215 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
86216 @@ -1568,6 +1583,10 @@ no_tcp_socket:
86217 bad_packet:
86218 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
86219 } else {
86220 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86221 + if (!grsec_enable_blackhole || (ret == 1 &&
86222 + (skb->dev->flags & IFF_LOOPBACK)))
86223 +#endif
86224 tcp_v6_send_reset(NULL, skb);
86225 }
86226
86227 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
86228 index fb08329..2d6919e 100644
86229 --- a/net/ipv6/udp.c
86230 +++ b/net/ipv6/udp.c
86231 @@ -51,6 +51,10 @@
86232 #include <trace/events/skb.h>
86233 #include "udp_impl.h"
86234
86235 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86236 +extern int grsec_enable_blackhole;
86237 +#endif
86238 +
86239 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
86240 {
86241 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
86242 @@ -395,7 +399,7 @@ try_again:
86243 if (unlikely(err)) {
86244 trace_kfree_skb(skb, udpv6_recvmsg);
86245 if (!peeked) {
86246 - atomic_inc(&sk->sk_drops);
86247 + atomic_inc_unchecked(&sk->sk_drops);
86248 if (is_udp4)
86249 UDP_INC_STATS_USER(sock_net(sk),
86250 UDP_MIB_INERRORS,
86251 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86252 return rc;
86253 drop:
86254 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
86255 - atomic_inc(&sk->sk_drops);
86256 + atomic_inc_unchecked(&sk->sk_drops);
86257 kfree_skb(skb);
86258 return -1;
86259 }
86260 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
86261 if (likely(skb1 == NULL))
86262 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
86263 if (!skb1) {
86264 - atomic_inc(&sk->sk_drops);
86265 + atomic_inc_unchecked(&sk->sk_drops);
86266 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
86267 IS_UDPLITE(sk));
86268 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
86269 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
86270 goto discard;
86271
86272 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
86273 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86274 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
86275 +#endif
86276 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
86277
86278 kfree_skb(skb);
86279 @@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
86280 0,
86281 sock_i_ino(sp),
86282 atomic_read(&sp->sk_refcnt), sp,
86283 - atomic_read(&sp->sk_drops));
86284 + atomic_read_unchecked(&sp->sk_drops));
86285 }
86286
86287 int udp6_seq_show(struct seq_file *seq, void *v)
86288 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
86289 index a68c88c..d55b0c5 100644
86290 --- a/net/irda/ircomm/ircomm_tty.c
86291 +++ b/net/irda/ircomm/ircomm_tty.c
86292 @@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
86293 add_wait_queue(&port->open_wait, &wait);
86294
86295 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
86296 - __FILE__, __LINE__, tty->driver->name, port->count);
86297 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
86298
86299 spin_lock_irqsave(&port->lock, flags);
86300 if (!tty_hung_up_p(filp)) {
86301 extra_count = 1;
86302 - port->count--;
86303 + atomic_dec(&port->count);
86304 }
86305 spin_unlock_irqrestore(&port->lock, flags);
86306 port->blocked_open++;
86307 @@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
86308 }
86309
86310 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
86311 - __FILE__, __LINE__, tty->driver->name, port->count);
86312 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
86313
86314 schedule();
86315 }
86316 @@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
86317 if (extra_count) {
86318 /* ++ is not atomic, so this should be protected - Jean II */
86319 spin_lock_irqsave(&port->lock, flags);
86320 - port->count++;
86321 + atomic_inc(&port->count);
86322 spin_unlock_irqrestore(&port->lock, flags);
86323 }
86324 port->blocked_open--;
86325
86326 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
86327 - __FILE__, __LINE__, tty->driver->name, port->count);
86328 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
86329
86330 if (!retval)
86331 port->flags |= ASYNC_NORMAL_ACTIVE;
86332 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
86333
86334 /* ++ is not atomic, so this should be protected - Jean II */
86335 spin_lock_irqsave(&self->port.lock, flags);
86336 - self->port.count++;
86337 + atomic_inc(&self->port.count);
86338 spin_unlock_irqrestore(&self->port.lock, flags);
86339 tty_port_tty_set(&self->port, tty);
86340
86341 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
86342 - self->line, self->port.count);
86343 + self->line, atomic_read(&self->port.count));
86344
86345 /* Not really used by us, but lets do it anyway */
86346 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
86347 @@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
86348 tty_kref_put(port->tty);
86349 }
86350 port->tty = NULL;
86351 - port->count = 0;
86352 + atomic_set(&port->count, 0);
86353 spin_unlock_irqrestore(&port->lock, flags);
86354
86355 wake_up_interruptible(&port->open_wait);
86356 @@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
86357 seq_putc(m, '\n');
86358
86359 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
86360 - seq_printf(m, "Open count: %d\n", self->port.count);
86361 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
86362 seq_printf(m, "Max data size: %d\n", self->max_data_size);
86363 seq_printf(m, "Max header size: %d\n", self->max_header_size);
86364
86365 diff --git a/net/irda/iriap.c b/net/irda/iriap.c
86366 index e71e85b..29340a9 100644
86367 --- a/net/irda/iriap.c
86368 +++ b/net/irda/iriap.c
86369 @@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
86370 /* case CS_ISO_8859_9: */
86371 /* case CS_UNICODE: */
86372 default:
86373 - IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
86374 - __func__, ias_charset_types[charset]);
86375 + IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
86376 + __func__, charset,
86377 + charset < ARRAY_SIZE(ias_charset_types) ?
86378 + ias_charset_types[charset] :
86379 + "(unknown)");
86380
86381 /* Aborting, close connection! */
86382 iriap_disconnect_request(self);
86383 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
86384 index cd6f7a9..e63fe89 100644
86385 --- a/net/iucv/af_iucv.c
86386 +++ b/net/iucv/af_iucv.c
86387 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
86388
86389 write_lock_bh(&iucv_sk_list.lock);
86390
86391 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
86392 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
86393 while (__iucv_get_sock_by_name(name)) {
86394 sprintf(name, "%08x",
86395 - atomic_inc_return(&iucv_sk_list.autobind_name));
86396 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
86397 }
86398
86399 write_unlock_bh(&iucv_sk_list.lock);
86400 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
86401 index df08250..02021fe 100644
86402 --- a/net/iucv/iucv.c
86403 +++ b/net/iucv/iucv.c
86404 @@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
86405 return NOTIFY_OK;
86406 }
86407
86408 -static struct notifier_block __refdata iucv_cpu_notifier = {
86409 +static struct notifier_block iucv_cpu_notifier = {
86410 .notifier_call = iucv_cpu_notify,
86411 };
86412
86413 diff --git a/net/key/af_key.c b/net/key/af_key.c
86414 index 5b426a6..970032b 100644
86415 --- a/net/key/af_key.c
86416 +++ b/net/key/af_key.c
86417 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
86418 static u32 get_acqseq(void)
86419 {
86420 u32 res;
86421 - static atomic_t acqseq;
86422 + static atomic_unchecked_t acqseq;
86423
86424 do {
86425 - res = atomic_inc_return(&acqseq);
86426 + res = atomic_inc_return_unchecked(&acqseq);
86427 } while (!res);
86428 return res;
86429 }
86430 diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
86431 index 716605c..044e9e1 100644
86432 --- a/net/l2tp/l2tp_ppp.c
86433 +++ b/net/l2tp/l2tp_ppp.c
86434 @@ -355,6 +355,7 @@ static int pppol2tp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msgh
86435 l2tp_xmit_skb(session, skb, session->hdr_len);
86436
86437 sock_put(ps->tunnel_sock);
86438 + sock_put(sk);
86439
86440 return error;
86441
86442 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
86443 index 0479c64..d031db6 100644
86444 --- a/net/mac80211/cfg.c
86445 +++ b/net/mac80211/cfg.c
86446 @@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
86447 ret = ieee80211_vif_use_channel(sdata, chandef,
86448 IEEE80211_CHANCTX_EXCLUSIVE);
86449 }
86450 - } else if (local->open_count == local->monitors) {
86451 + } else if (local_read(&local->open_count) == local->monitors) {
86452 local->_oper_channel = chandef->chan;
86453 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
86454 ieee80211_hw_config(local, 0);
86455 @@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
86456 else
86457 local->probe_req_reg--;
86458
86459 - if (!local->open_count)
86460 + if (!local_read(&local->open_count))
86461 break;
86462
86463 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
86464 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
86465 index 2ed065c..948177f 100644
86466 --- a/net/mac80211/ieee80211_i.h
86467 +++ b/net/mac80211/ieee80211_i.h
86468 @@ -28,6 +28,7 @@
86469 #include <net/ieee80211_radiotap.h>
86470 #include <net/cfg80211.h>
86471 #include <net/mac80211.h>
86472 +#include <asm/local.h>
86473 #include "key.h"
86474 #include "sta_info.h"
86475 #include "debug.h"
86476 @@ -909,7 +910,7 @@ struct ieee80211_local {
86477 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
86478 spinlock_t queue_stop_reason_lock;
86479
86480 - int open_count;
86481 + local_t open_count;
86482 int monitors, cooked_mntrs;
86483 /* number of interfaces with corresponding FIF_ flags */
86484 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
86485 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
86486 index 8be854e..ad72a69 100644
86487 --- a/net/mac80211/iface.c
86488 +++ b/net/mac80211/iface.c
86489 @@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86490 break;
86491 }
86492
86493 - if (local->open_count == 0) {
86494 + if (local_read(&local->open_count) == 0) {
86495 res = drv_start(local);
86496 if (res)
86497 goto err_del_bss;
86498 @@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86499 break;
86500 }
86501
86502 - if (local->monitors == 0 && local->open_count == 0) {
86503 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
86504 res = ieee80211_add_virtual_monitor(local);
86505 if (res)
86506 goto err_stop;
86507 @@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86508 mutex_unlock(&local->mtx);
86509
86510 if (coming_up)
86511 - local->open_count++;
86512 + local_inc(&local->open_count);
86513
86514 if (hw_reconf_flags)
86515 ieee80211_hw_config(local, hw_reconf_flags);
86516 @@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86517 err_del_interface:
86518 drv_remove_interface(local, sdata);
86519 err_stop:
86520 - if (!local->open_count)
86521 + if (!local_read(&local->open_count))
86522 drv_stop(local);
86523 err_del_bss:
86524 sdata->bss = NULL;
86525 @@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86526 }
86527
86528 if (going_down)
86529 - local->open_count--;
86530 + local_dec(&local->open_count);
86531
86532 switch (sdata->vif.type) {
86533 case NL80211_IFTYPE_AP_VLAN:
86534 @@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86535
86536 ieee80211_recalc_ps(local, -1);
86537
86538 - if (local->open_count == 0) {
86539 + if (local_read(&local->open_count) == 0) {
86540 if (local->ops->napi_poll)
86541 napi_disable(&local->napi);
86542 ieee80211_clear_tx_pending(local);
86543 @@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86544 }
86545 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
86546
86547 - if (local->monitors == local->open_count && local->monitors > 0)
86548 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
86549 ieee80211_add_virtual_monitor(local);
86550 }
86551
86552 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
86553 index 1b087ff..bf600e9 100644
86554 --- a/net/mac80211/main.c
86555 +++ b/net/mac80211/main.c
86556 @@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
86557 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
86558 IEEE80211_CONF_CHANGE_POWER);
86559
86560 - if (changed && local->open_count) {
86561 + if (changed && local_read(&local->open_count)) {
86562 ret = drv_config(local, changed);
86563 /*
86564 * Goal:
86565 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
86566 index 79a48f3..5e185c9 100644
86567 --- a/net/mac80211/pm.c
86568 +++ b/net/mac80211/pm.c
86569 @@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86570 struct sta_info *sta;
86571 struct ieee80211_chanctx *ctx;
86572
86573 - if (!local->open_count)
86574 + if (!local_read(&local->open_count))
86575 goto suspend;
86576
86577 ieee80211_scan_cancel(local);
86578 @@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86579 cancel_work_sync(&local->dynamic_ps_enable_work);
86580 del_timer_sync(&local->dynamic_ps_timer);
86581
86582 - local->wowlan = wowlan && local->open_count;
86583 + local->wowlan = wowlan && local_read(&local->open_count);
86584 if (local->wowlan) {
86585 int err = drv_suspend(local, wowlan);
86586 if (err < 0) {
86587 @@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86588 mutex_unlock(&local->chanctx_mtx);
86589
86590 /* stop hardware - this must stop RX */
86591 - if (local->open_count)
86592 + if (local_read(&local->open_count))
86593 ieee80211_stop_device(local);
86594
86595 suspend:
86596 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
86597 index dd88381..eef4dd6 100644
86598 --- a/net/mac80211/rate.c
86599 +++ b/net/mac80211/rate.c
86600 @@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
86601
86602 ASSERT_RTNL();
86603
86604 - if (local->open_count)
86605 + if (local_read(&local->open_count))
86606 return -EBUSY;
86607
86608 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
86609 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
86610 index c97a065..ff61928 100644
86611 --- a/net/mac80211/rc80211_pid_debugfs.c
86612 +++ b/net/mac80211/rc80211_pid_debugfs.c
86613 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
86614
86615 spin_unlock_irqrestore(&events->lock, status);
86616
86617 - if (copy_to_user(buf, pb, p))
86618 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
86619 return -EFAULT;
86620
86621 return p;
86622 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
86623 index f11e8c5..08d0013 100644
86624 --- a/net/mac80211/util.c
86625 +++ b/net/mac80211/util.c
86626 @@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
86627 }
86628 #endif
86629 /* everything else happens only if HW was up & running */
86630 - if (!local->open_count)
86631 + if (!local_read(&local->open_count))
86632 goto wake_up;
86633
86634 /*
86635 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
86636 index 49e96df..63a51c3 100644
86637 --- a/net/netfilter/Kconfig
86638 +++ b/net/netfilter/Kconfig
86639 @@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
86640
86641 To compile it as a module, choose M here. If unsure, say N.
86642
86643 +config NETFILTER_XT_MATCH_GRADM
86644 + tristate '"gradm" match support'
86645 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
86646 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
86647 + ---help---
86648 + The gradm match allows to match on grsecurity RBAC being enabled.
86649 + It is useful when iptables rules are applied early on bootup to
86650 + prevent connections to the machine (except from a trusted host)
86651 + while the RBAC system is disabled.
86652 +
86653 config NETFILTER_XT_MATCH_HASHLIMIT
86654 tristate '"hashlimit" match support'
86655 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
86656 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
86657 index 3259697..54d5393 100644
86658 --- a/net/netfilter/Makefile
86659 +++ b/net/netfilter/Makefile
86660 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
86661 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
86662 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
86663 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
86664 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
86665 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
86666 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
86667 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
86668 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
86669 index 6d6d8f2..a676749 100644
86670 --- a/net/netfilter/ipset/ip_set_core.c
86671 +++ b/net/netfilter/ipset/ip_set_core.c
86672 @@ -1800,7 +1800,7 @@ done:
86673 return ret;
86674 }
86675
86676 -static struct nf_sockopt_ops so_set __read_mostly = {
86677 +static struct nf_sockopt_ops so_set = {
86678 .pf = PF_INET,
86679 .get_optmin = SO_IP_SET,
86680 .get_optmax = SO_IP_SET + 1,
86681 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
86682 index 30e764a..c3b6a9d 100644
86683 --- a/net/netfilter/ipvs/ip_vs_conn.c
86684 +++ b/net/netfilter/ipvs/ip_vs_conn.c
86685 @@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
86686 /* Increase the refcnt counter of the dest */
86687 atomic_inc(&dest->refcnt);
86688
86689 - conn_flags = atomic_read(&dest->conn_flags);
86690 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
86691 if (cp->protocol != IPPROTO_UDP)
86692 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
86693 flags = cp->flags;
86694 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
86695 atomic_set(&cp->refcnt, 1);
86696
86697 atomic_set(&cp->n_control, 0);
86698 - atomic_set(&cp->in_pkts, 0);
86699 + atomic_set_unchecked(&cp->in_pkts, 0);
86700
86701 atomic_inc(&ipvs->conn_count);
86702 if (flags & IP_VS_CONN_F_NO_CPORT)
86703 @@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
86704
86705 /* Don't drop the entry if its number of incoming packets is not
86706 located in [0, 8] */
86707 - i = atomic_read(&cp->in_pkts);
86708 + i = atomic_read_unchecked(&cp->in_pkts);
86709 if (i > 8 || i < 0) return 0;
86710
86711 if (!todrop_rate[i]) return 0;
86712 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
86713 index 47edf5a..235b07d 100644
86714 --- a/net/netfilter/ipvs/ip_vs_core.c
86715 +++ b/net/netfilter/ipvs/ip_vs_core.c
86716 @@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
86717 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
86718 /* do not touch skb anymore */
86719
86720 - atomic_inc(&cp->in_pkts);
86721 + atomic_inc_unchecked(&cp->in_pkts);
86722 ip_vs_conn_put(cp);
86723 return ret;
86724 }
86725 @@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
86726 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
86727 pkts = sysctl_sync_threshold(ipvs);
86728 else
86729 - pkts = atomic_add_return(1, &cp->in_pkts);
86730 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86731
86732 if (ipvs->sync_state & IP_VS_STATE_MASTER)
86733 ip_vs_sync_conn(net, cp, pkts);
86734 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
86735 index ec664cb..7f34a77 100644
86736 --- a/net/netfilter/ipvs/ip_vs_ctl.c
86737 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
86738 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
86739 ip_vs_rs_hash(ipvs, dest);
86740 write_unlock_bh(&ipvs->rs_lock);
86741 }
86742 - atomic_set(&dest->conn_flags, conn_flags);
86743 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
86744
86745 /* bind the service */
86746 if (!dest->svc) {
86747 @@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
86748 * align with netns init in ip_vs_control_net_init()
86749 */
86750
86751 -static struct ctl_table vs_vars[] = {
86752 +static ctl_table_no_const vs_vars[] __read_only = {
86753 {
86754 .procname = "amemthresh",
86755 .maxlen = sizeof(int),
86756 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
86757 " %-7s %-6d %-10d %-10d\n",
86758 &dest->addr.in6,
86759 ntohs(dest->port),
86760 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
86761 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
86762 atomic_read(&dest->weight),
86763 atomic_read(&dest->activeconns),
86764 atomic_read(&dest->inactconns));
86765 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
86766 "%-7s %-6d %-10d %-10d\n",
86767 ntohl(dest->addr.ip),
86768 ntohs(dest->port),
86769 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
86770 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
86771 atomic_read(&dest->weight),
86772 atomic_read(&dest->activeconns),
86773 atomic_read(&dest->inactconns));
86774 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
86775
86776 entry.addr = dest->addr.ip;
86777 entry.port = dest->port;
86778 - entry.conn_flags = atomic_read(&dest->conn_flags);
86779 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
86780 entry.weight = atomic_read(&dest->weight);
86781 entry.u_threshold = dest->u_threshold;
86782 entry.l_threshold = dest->l_threshold;
86783 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
86784 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
86785 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
86786 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
86787 - (atomic_read(&dest->conn_flags) &
86788 + (atomic_read_unchecked(&dest->conn_flags) &
86789 IP_VS_CONN_F_FWD_MASK)) ||
86790 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
86791 atomic_read(&dest->weight)) ||
86792 @@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
86793 {
86794 int idx;
86795 struct netns_ipvs *ipvs = net_ipvs(net);
86796 - struct ctl_table *tbl;
86797 + ctl_table_no_const *tbl;
86798
86799 atomic_set(&ipvs->dropentry, 0);
86800 spin_lock_init(&ipvs->dropentry_lock);
86801 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
86802 index fdd89b9..bd96aa9 100644
86803 --- a/net/netfilter/ipvs/ip_vs_lblc.c
86804 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
86805 @@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
86806 * IPVS LBLC sysctl table
86807 */
86808 #ifdef CONFIG_SYSCTL
86809 -static ctl_table vs_vars_table[] = {
86810 +static ctl_table_no_const vs_vars_table[] __read_only = {
86811 {
86812 .procname = "lblc_expiration",
86813 .data = NULL,
86814 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
86815 index c03b6a3..8ce3681 100644
86816 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
86817 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
86818 @@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
86819 * IPVS LBLCR sysctl table
86820 */
86821
86822 -static ctl_table vs_vars_table[] = {
86823 +static ctl_table_no_const vs_vars_table[] __read_only = {
86824 {
86825 .procname = "lblcr_expiration",
86826 .data = NULL,
86827 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
86828 index 44fd10c..2a163b3 100644
86829 --- a/net/netfilter/ipvs/ip_vs_sync.c
86830 +++ b/net/netfilter/ipvs/ip_vs_sync.c
86831 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
86832 cp = cp->control;
86833 if (cp) {
86834 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
86835 - pkts = atomic_add_return(1, &cp->in_pkts);
86836 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86837 else
86838 pkts = sysctl_sync_threshold(ipvs);
86839 ip_vs_sync_conn(net, cp->control, pkts);
86840 @@ -758,7 +758,7 @@ control:
86841 if (!cp)
86842 return;
86843 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
86844 - pkts = atomic_add_return(1, &cp->in_pkts);
86845 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86846 else
86847 pkts = sysctl_sync_threshold(ipvs);
86848 goto sloop;
86849 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
86850
86851 if (opt)
86852 memcpy(&cp->in_seq, opt, sizeof(*opt));
86853 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
86854 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
86855 cp->state = state;
86856 cp->old_state = cp->state;
86857 /*
86858 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
86859 index ee6b7a9..f9a89f6 100644
86860 --- a/net/netfilter/ipvs/ip_vs_xmit.c
86861 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
86862 @@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
86863 else
86864 rc = NF_ACCEPT;
86865 /* do not touch skb anymore */
86866 - atomic_inc(&cp->in_pkts);
86867 + atomic_inc_unchecked(&cp->in_pkts);
86868 goto out;
86869 }
86870
86871 @@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
86872 else
86873 rc = NF_ACCEPT;
86874 /* do not touch skb anymore */
86875 - atomic_inc(&cp->in_pkts);
86876 + atomic_inc_unchecked(&cp->in_pkts);
86877 goto out;
86878 }
86879
86880 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
86881 index 7df424e..a527b02 100644
86882 --- a/net/netfilter/nf_conntrack_acct.c
86883 +++ b/net/netfilter/nf_conntrack_acct.c
86884 @@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
86885 #ifdef CONFIG_SYSCTL
86886 static int nf_conntrack_acct_init_sysctl(struct net *net)
86887 {
86888 - struct ctl_table *table;
86889 + ctl_table_no_const *table;
86890
86891 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
86892 GFP_KERNEL);
86893 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
86894 index e4a0c4f..c263f28 100644
86895 --- a/net/netfilter/nf_conntrack_core.c
86896 +++ b/net/netfilter/nf_conntrack_core.c
86897 @@ -1529,6 +1529,10 @@ err_extend:
86898 #define DYING_NULLS_VAL ((1<<30)+1)
86899 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
86900
86901 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86902 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
86903 +#endif
86904 +
86905 static int nf_conntrack_init_net(struct net *net)
86906 {
86907 int ret;
86908 @@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
86909 goto err_stat;
86910 }
86911
86912 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86913 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
86914 +#else
86915 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
86916 +#endif
86917 if (!net->ct.slabname) {
86918 ret = -ENOMEM;
86919 goto err_slabname;
86920 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
86921 index faa978f..1afb18f 100644
86922 --- a/net/netfilter/nf_conntrack_ecache.c
86923 +++ b/net/netfilter/nf_conntrack_ecache.c
86924 @@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
86925 #ifdef CONFIG_SYSCTL
86926 static int nf_conntrack_event_init_sysctl(struct net *net)
86927 {
86928 - struct ctl_table *table;
86929 + ctl_table_no_const *table;
86930
86931 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
86932 GFP_KERNEL);
86933 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
86934 index 884f2b3..d53b33a 100644
86935 --- a/net/netfilter/nf_conntrack_helper.c
86936 +++ b/net/netfilter/nf_conntrack_helper.c
86937 @@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
86938
86939 static int nf_conntrack_helper_init_sysctl(struct net *net)
86940 {
86941 - struct ctl_table *table;
86942 + ctl_table_no_const *table;
86943
86944 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
86945 GFP_KERNEL);
86946 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
86947 index 51e928d..72a413a 100644
86948 --- a/net/netfilter/nf_conntrack_proto.c
86949 +++ b/net/netfilter/nf_conntrack_proto.c
86950 @@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
86951
86952 static void
86953 nf_ct_unregister_sysctl(struct ctl_table_header **header,
86954 - struct ctl_table **table,
86955 + ctl_table_no_const **table,
86956 unsigned int users)
86957 {
86958 if (users > 0)
86959 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
86960 index e7185c6..4ad6c9c 100644
86961 --- a/net/netfilter/nf_conntrack_standalone.c
86962 +++ b/net/netfilter/nf_conntrack_standalone.c
86963 @@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
86964
86965 static int nf_conntrack_standalone_init_sysctl(struct net *net)
86966 {
86967 - struct ctl_table *table;
86968 + ctl_table_no_const *table;
86969
86970 if (net_eq(net, &init_net)) {
86971 nf_ct_netfilter_header =
86972 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
86973 index 7ea8026..bc9512d 100644
86974 --- a/net/netfilter/nf_conntrack_timestamp.c
86975 +++ b/net/netfilter/nf_conntrack_timestamp.c
86976 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
86977 #ifdef CONFIG_SYSCTL
86978 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
86979 {
86980 - struct ctl_table *table;
86981 + ctl_table_no_const *table;
86982
86983 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
86984 GFP_KERNEL);
86985 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
86986 index 9e31269..bc4c1b7 100644
86987 --- a/net/netfilter/nf_log.c
86988 +++ b/net/netfilter/nf_log.c
86989 @@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
86990
86991 #ifdef CONFIG_SYSCTL
86992 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
86993 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
86994 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
86995 static struct ctl_table_header *nf_log_dir_header;
86996
86997 static int nf_log_proc_dostring(ctl_table *table, int write,
86998 @@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
86999 rcu_assign_pointer(nf_loggers[tindex], logger);
87000 mutex_unlock(&nf_log_mutex);
87001 } else {
87002 + ctl_table_no_const nf_log_table = *table;
87003 +
87004 mutex_lock(&nf_log_mutex);
87005 logger = rcu_dereference_protected(nf_loggers[tindex],
87006 lockdep_is_held(&nf_log_mutex));
87007 if (!logger)
87008 - table->data = "NONE";
87009 + nf_log_table.data = "NONE";
87010 else
87011 - table->data = logger->name;
87012 - r = proc_dostring(table, write, buffer, lenp, ppos);
87013 + nf_log_table.data = logger->name;
87014 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
87015 mutex_unlock(&nf_log_mutex);
87016 }
87017
87018 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
87019 index f042ae5..30ea486 100644
87020 --- a/net/netfilter/nf_sockopt.c
87021 +++ b/net/netfilter/nf_sockopt.c
87022 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
87023 }
87024 }
87025
87026 - list_add(&reg->list, &nf_sockopts);
87027 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
87028 out:
87029 mutex_unlock(&nf_sockopt_mutex);
87030 return ret;
87031 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
87032 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
87033 {
87034 mutex_lock(&nf_sockopt_mutex);
87035 - list_del(&reg->list);
87036 + pax_list_del((struct list_head *)&reg->list);
87037 mutex_unlock(&nf_sockopt_mutex);
87038 }
87039 EXPORT_SYMBOL(nf_unregister_sockopt);
87040 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
87041 index 92fd8ec..3f6ea4b 100644
87042 --- a/net/netfilter/nfnetlink_log.c
87043 +++ b/net/netfilter/nfnetlink_log.c
87044 @@ -72,7 +72,7 @@ struct nfulnl_instance {
87045 };
87046
87047 static DEFINE_SPINLOCK(instances_lock);
87048 -static atomic_t global_seq;
87049 +static atomic_unchecked_t global_seq;
87050
87051 #define INSTANCE_BUCKETS 16
87052 static struct hlist_head instance_table[INSTANCE_BUCKETS];
87053 @@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
87054 /* global sequence number */
87055 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
87056 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
87057 - htonl(atomic_inc_return(&global_seq))))
87058 + htonl(atomic_inc_return_unchecked(&global_seq))))
87059 goto nla_put_failure;
87060
87061 if (data_len) {
87062 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
87063 new file mode 100644
87064 index 0000000..c566332
87065 --- /dev/null
87066 +++ b/net/netfilter/xt_gradm.c
87067 @@ -0,0 +1,51 @@
87068 +/*
87069 + * gradm match for netfilter
87070 + * Copyright © Zbigniew Krzystolik, 2010
87071 + *
87072 + * This program is free software; you can redistribute it and/or modify
87073 + * it under the terms of the GNU General Public License; either version
87074 + * 2 or 3 as published by the Free Software Foundation.
87075 + */
87076 +#include <linux/module.h>
87077 +#include <linux/moduleparam.h>
87078 +#include <linux/skbuff.h>
87079 +#include <linux/netfilter/x_tables.h>
87080 +#include <linux/grsecurity.h>
87081 +#include <linux/netfilter/xt_gradm.h>
87082 +
87083 +static bool
87084 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
87085 +{
87086 + const struct xt_gradm_mtinfo *info = par->matchinfo;
87087 + bool retval = false;
87088 + if (gr_acl_is_enabled())
87089 + retval = true;
87090 + return retval ^ info->invflags;
87091 +}
87092 +
87093 +static struct xt_match gradm_mt_reg __read_mostly = {
87094 + .name = "gradm",
87095 + .revision = 0,
87096 + .family = NFPROTO_UNSPEC,
87097 + .match = gradm_mt,
87098 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
87099 + .me = THIS_MODULE,
87100 +};
87101 +
87102 +static int __init gradm_mt_init(void)
87103 +{
87104 + return xt_register_match(&gradm_mt_reg);
87105 +}
87106 +
87107 +static void __exit gradm_mt_exit(void)
87108 +{
87109 + xt_unregister_match(&gradm_mt_reg);
87110 +}
87111 +
87112 +module_init(gradm_mt_init);
87113 +module_exit(gradm_mt_exit);
87114 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
87115 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
87116 +MODULE_LICENSE("GPL");
87117 +MODULE_ALIAS("ipt_gradm");
87118 +MODULE_ALIAS("ip6t_gradm");
87119 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
87120 index 4fe4fb4..87a89e5 100644
87121 --- a/net/netfilter/xt_statistic.c
87122 +++ b/net/netfilter/xt_statistic.c
87123 @@ -19,7 +19,7 @@
87124 #include <linux/module.h>
87125
87126 struct xt_statistic_priv {
87127 - atomic_t count;
87128 + atomic_unchecked_t count;
87129 } ____cacheline_aligned_in_smp;
87130
87131 MODULE_LICENSE("GPL");
87132 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
87133 break;
87134 case XT_STATISTIC_MODE_NTH:
87135 do {
87136 - oval = atomic_read(&info->master->count);
87137 + oval = atomic_read_unchecked(&info->master->count);
87138 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
87139 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
87140 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
87141 if (nval == 0)
87142 ret = !ret;
87143 break;
87144 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
87145 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
87146 if (info->master == NULL)
87147 return -ENOMEM;
87148 - atomic_set(&info->master->count, info->u.nth.count);
87149 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
87150
87151 return 0;
87152 }
87153 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
87154 index c0353d5..fcb0270 100644
87155 --- a/net/netlink/af_netlink.c
87156 +++ b/net/netlink/af_netlink.c
87157 @@ -785,7 +785,7 @@ static void netlink_overrun(struct sock *sk)
87158 sk->sk_error_report(sk);
87159 }
87160 }
87161 - atomic_inc(&sk->sk_drops);
87162 + atomic_inc_unchecked(&sk->sk_drops);
87163 }
87164
87165 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
87166 @@ -2071,7 +2071,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
87167 sk_wmem_alloc_get(s),
87168 nlk->cb,
87169 atomic_read(&s->sk_refcnt),
87170 - atomic_read(&s->sk_drops),
87171 + atomic_read_unchecked(&s->sk_drops),
87172 sock_i_ino(s)
87173 );
87174
87175 diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
87176 index f2aabb6..2e5e66e 100644
87177 --- a/net/netlink/genetlink.c
87178 +++ b/net/netlink/genetlink.c
87179 @@ -295,18 +295,20 @@ int genl_register_ops(struct genl_family *family, struct genl_ops *ops)
87180 goto errout;
87181 }
87182
87183 + pax_open_kernel();
87184 if (ops->dumpit)
87185 - ops->flags |= GENL_CMD_CAP_DUMP;
87186 + *(unsigned int *)&ops->flags |= GENL_CMD_CAP_DUMP;
87187 if (ops->doit)
87188 - ops->flags |= GENL_CMD_CAP_DO;
87189 + *(unsigned int *)&ops->flags |= GENL_CMD_CAP_DO;
87190 if (ops->policy)
87191 - ops->flags |= GENL_CMD_CAP_HASPOL;
87192 + *(unsigned int *)&ops->flags |= GENL_CMD_CAP_HASPOL;
87193 + pax_close_kernel();
87194
87195 genl_lock();
87196 - list_add_tail(&ops->ops_list, &family->ops_list);
87197 + pax_list_add_tail((struct list_head *)&ops->ops_list, &family->ops_list);
87198 genl_unlock();
87199
87200 - genl_ctrl_event(CTRL_CMD_NEWOPS, ops);
87201 + genl_ctrl_event(CTRL_CMD_NEWOPS, (void *)ops);
87202 err = 0;
87203 errout:
87204 return err;
87205 @@ -336,9 +338,9 @@ int genl_unregister_ops(struct genl_family *family, struct genl_ops *ops)
87206 genl_lock();
87207 list_for_each_entry(rc, &family->ops_list, ops_list) {
87208 if (rc == ops) {
87209 - list_del(&ops->ops_list);
87210 + pax_list_del((struct list_head *)&ops->ops_list);
87211 genl_unlock();
87212 - genl_ctrl_event(CTRL_CMD_DELOPS, ops);
87213 + genl_ctrl_event(CTRL_CMD_DELOPS, (void *)ops);
87214 return 0;
87215 }
87216 }
87217 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
87218 index 7261eb8..44e8ac6 100644
87219 --- a/net/netrom/af_netrom.c
87220 +++ b/net/netrom/af_netrom.c
87221 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
87222 struct sock *sk = sock->sk;
87223 struct nr_sock *nr = nr_sk(sk);
87224
87225 + memset(sax, 0, sizeof(*sax));
87226 lock_sock(sk);
87227 if (peer != 0) {
87228 if (sk->sk_state != TCP_ESTABLISHED) {
87229 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
87230 *uaddr_len = sizeof(struct full_sockaddr_ax25);
87231 } else {
87232 sax->fsa_ax25.sax25_family = AF_NETROM;
87233 - sax->fsa_ax25.sax25_ndigis = 0;
87234 sax->fsa_ax25.sax25_call = nr->source_addr;
87235 *uaddr_len = sizeof(struct sockaddr_ax25);
87236 }
87237 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
87238 index c111bd0..7788ff7 100644
87239 --- a/net/packet/af_packet.c
87240 +++ b/net/packet/af_packet.c
87241 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
87242
87243 spin_lock(&sk->sk_receive_queue.lock);
87244 po->stats.tp_packets++;
87245 - skb->dropcount = atomic_read(&sk->sk_drops);
87246 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
87247 __skb_queue_tail(&sk->sk_receive_queue, skb);
87248 spin_unlock(&sk->sk_receive_queue.lock);
87249 sk->sk_data_ready(sk, skb->len);
87250 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
87251 drop_n_acct:
87252 spin_lock(&sk->sk_receive_queue.lock);
87253 po->stats.tp_drops++;
87254 - atomic_inc(&sk->sk_drops);
87255 + atomic_inc_unchecked(&sk->sk_drops);
87256 spin_unlock(&sk->sk_receive_queue.lock);
87257
87258 drop_n_restore:
87259 @@ -2565,6 +2565,7 @@ out:
87260
87261 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
87262 {
87263 + struct sock_extended_err ee;
87264 struct sock_exterr_skb *serr;
87265 struct sk_buff *skb, *skb2;
87266 int copied, err;
87267 @@ -2586,8 +2587,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
87268 sock_recv_timestamp(msg, sk, skb);
87269
87270 serr = SKB_EXT_ERR(skb);
87271 + ee = serr->ee;
87272 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
87273 - sizeof(serr->ee), &serr->ee);
87274 + sizeof ee, &ee);
87275
87276 msg->msg_flags |= MSG_ERRQUEUE;
87277 err = copied;
87278 @@ -3212,7 +3214,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
87279 case PACKET_HDRLEN:
87280 if (len > sizeof(int))
87281 len = sizeof(int);
87282 - if (copy_from_user(&val, optval, len))
87283 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
87284 return -EFAULT;
87285 switch (val) {
87286 case TPACKET_V1:
87287 @@ -3254,7 +3256,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
87288 len = lv;
87289 if (put_user(len, optlen))
87290 return -EFAULT;
87291 - if (copy_to_user(optval, data, len))
87292 + if (len > sizeof(st) || copy_to_user(optval, data, len))
87293 return -EFAULT;
87294 return 0;
87295 }
87296 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
87297 index 5a940db..f0b9c12 100644
87298 --- a/net/phonet/af_phonet.c
87299 +++ b/net/phonet/af_phonet.c
87300 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
87301 {
87302 struct phonet_protocol *pp;
87303
87304 - if (protocol >= PHONET_NPROTO)
87305 + if (protocol < 0 || protocol >= PHONET_NPROTO)
87306 return NULL;
87307
87308 rcu_read_lock();
87309 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
87310 {
87311 int err = 0;
87312
87313 - if (protocol >= PHONET_NPROTO)
87314 + if (protocol < 0 || protocol >= PHONET_NPROTO)
87315 return -EINVAL;
87316
87317 err = proto_register(pp->prot, 1);
87318 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
87319 index 576f22c..bc7a71b 100644
87320 --- a/net/phonet/pep.c
87321 +++ b/net/phonet/pep.c
87322 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
87323
87324 case PNS_PEP_CTRL_REQ:
87325 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
87326 - atomic_inc(&sk->sk_drops);
87327 + atomic_inc_unchecked(&sk->sk_drops);
87328 break;
87329 }
87330 __skb_pull(skb, 4);
87331 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
87332 }
87333
87334 if (pn->rx_credits == 0) {
87335 - atomic_inc(&sk->sk_drops);
87336 + atomic_inc_unchecked(&sk->sk_drops);
87337 err = -ENOBUFS;
87338 break;
87339 }
87340 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
87341 }
87342
87343 if (pn->rx_credits == 0) {
87344 - atomic_inc(&sk->sk_drops);
87345 + atomic_inc_unchecked(&sk->sk_drops);
87346 err = NET_RX_DROP;
87347 break;
87348 }
87349 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
87350 index b7e9827..c264c85 100644
87351 --- a/net/phonet/socket.c
87352 +++ b/net/phonet/socket.c
87353 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
87354 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
87355 sock_i_ino(sk),
87356 atomic_read(&sk->sk_refcnt), sk,
87357 - atomic_read(&sk->sk_drops), &len);
87358 + atomic_read_unchecked(&sk->sk_drops), &len);
87359 }
87360 seq_printf(seq, "%*s\n", 127 - len, "");
87361 return 0;
87362 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
87363 index d6bbbbd..61561e4 100644
87364 --- a/net/phonet/sysctl.c
87365 +++ b/net/phonet/sysctl.c
87366 @@ -67,7 +67,7 @@ static int proc_local_port_range(ctl_table *table, int write,
87367 {
87368 int ret;
87369 int range[2] = {local_port_range[0], local_port_range[1]};
87370 - ctl_table tmp = {
87371 + ctl_table_no_const tmp = {
87372 .data = &range,
87373 .maxlen = sizeof(range),
87374 .mode = table->mode,
87375 diff --git a/net/rds/cong.c b/net/rds/cong.c
87376 index e5b65ac..f3b6fb7 100644
87377 --- a/net/rds/cong.c
87378 +++ b/net/rds/cong.c
87379 @@ -78,7 +78,7 @@
87380 * finds that the saved generation number is smaller than the global generation
87381 * number, it wakes up the process.
87382 */
87383 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
87384 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
87385
87386 /*
87387 * Congestion monitoring
87388 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
87389 rdsdebug("waking map %p for %pI4\n",
87390 map, &map->m_addr);
87391 rds_stats_inc(s_cong_update_received);
87392 - atomic_inc(&rds_cong_generation);
87393 + atomic_inc_unchecked(&rds_cong_generation);
87394 if (waitqueue_active(&map->m_waitq))
87395 wake_up(&map->m_waitq);
87396 if (waitqueue_active(&rds_poll_waitq))
87397 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
87398
87399 int rds_cong_updated_since(unsigned long *recent)
87400 {
87401 - unsigned long gen = atomic_read(&rds_cong_generation);
87402 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
87403
87404 if (likely(*recent == gen))
87405 return 0;
87406 diff --git a/net/rds/ib.h b/net/rds/ib.h
87407 index 7280ab8..e04f4ea 100644
87408 --- a/net/rds/ib.h
87409 +++ b/net/rds/ib.h
87410 @@ -128,7 +128,7 @@ struct rds_ib_connection {
87411 /* sending acks */
87412 unsigned long i_ack_flags;
87413 #ifdef KERNEL_HAS_ATOMIC64
87414 - atomic64_t i_ack_next; /* next ACK to send */
87415 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
87416 #else
87417 spinlock_t i_ack_lock; /* protect i_ack_next */
87418 u64 i_ack_next; /* next ACK to send */
87419 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
87420 index 31b74f5..dc1fbfa 100644
87421 --- a/net/rds/ib_cm.c
87422 +++ b/net/rds/ib_cm.c
87423 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
87424 /* Clear the ACK state */
87425 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
87426 #ifdef KERNEL_HAS_ATOMIC64
87427 - atomic64_set(&ic->i_ack_next, 0);
87428 + atomic64_set_unchecked(&ic->i_ack_next, 0);
87429 #else
87430 ic->i_ack_next = 0;
87431 #endif
87432 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
87433 index 8eb9501..0c386ff 100644
87434 --- a/net/rds/ib_recv.c
87435 +++ b/net/rds/ib_recv.c
87436 @@ -597,7 +597,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
87437 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
87438 int ack_required)
87439 {
87440 - atomic64_set(&ic->i_ack_next, seq);
87441 + atomic64_set_unchecked(&ic->i_ack_next, seq);
87442 if (ack_required) {
87443 smp_mb__before_clear_bit();
87444 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87445 @@ -609,7 +609,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
87446 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87447 smp_mb__after_clear_bit();
87448
87449 - return atomic64_read(&ic->i_ack_next);
87450 + return atomic64_read_unchecked(&ic->i_ack_next);
87451 }
87452 #endif
87453
87454 diff --git a/net/rds/iw.h b/net/rds/iw.h
87455 index 04ce3b1..48119a6 100644
87456 --- a/net/rds/iw.h
87457 +++ b/net/rds/iw.h
87458 @@ -134,7 +134,7 @@ struct rds_iw_connection {
87459 /* sending acks */
87460 unsigned long i_ack_flags;
87461 #ifdef KERNEL_HAS_ATOMIC64
87462 - atomic64_t i_ack_next; /* next ACK to send */
87463 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
87464 #else
87465 spinlock_t i_ack_lock; /* protect i_ack_next */
87466 u64 i_ack_next; /* next ACK to send */
87467 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
87468 index a91e1db..cf3053f 100644
87469 --- a/net/rds/iw_cm.c
87470 +++ b/net/rds/iw_cm.c
87471 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
87472 /* Clear the ACK state */
87473 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
87474 #ifdef KERNEL_HAS_ATOMIC64
87475 - atomic64_set(&ic->i_ack_next, 0);
87476 + atomic64_set_unchecked(&ic->i_ack_next, 0);
87477 #else
87478 ic->i_ack_next = 0;
87479 #endif
87480 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
87481 index 4503335..db566b4 100644
87482 --- a/net/rds/iw_recv.c
87483 +++ b/net/rds/iw_recv.c
87484 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
87485 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
87486 int ack_required)
87487 {
87488 - atomic64_set(&ic->i_ack_next, seq);
87489 + atomic64_set_unchecked(&ic->i_ack_next, seq);
87490 if (ack_required) {
87491 smp_mb__before_clear_bit();
87492 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87493 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
87494 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87495 smp_mb__after_clear_bit();
87496
87497 - return atomic64_read(&ic->i_ack_next);
87498 + return atomic64_read_unchecked(&ic->i_ack_next);
87499 }
87500 #endif
87501
87502 diff --git a/net/rds/message.c b/net/rds/message.c
87503 index f0a4658..aff589c 100644
87504 --- a/net/rds/message.c
87505 +++ b/net/rds/message.c
87506 @@ -197,6 +197,9 @@ struct rds_message *rds_message_alloc(unsigned int extra_len, gfp_t gfp)
87507 {
87508 struct rds_message *rm;
87509
87510 + if (extra_len > KMALLOC_MAX_SIZE - sizeof(struct rds_message))
87511 + return NULL;
87512 +
87513 rm = kzalloc(sizeof(struct rds_message) + extra_len, gfp);
87514 if (!rm)
87515 goto out;
87516 diff --git a/net/rds/rds.h b/net/rds/rds.h
87517 index ec1d731..90a3a8d 100644
87518 --- a/net/rds/rds.h
87519 +++ b/net/rds/rds.h
87520 @@ -449,7 +449,7 @@ struct rds_transport {
87521 void (*sync_mr)(void *trans_private, int direction);
87522 void (*free_mr)(void *trans_private, int invalidate);
87523 void (*flush_mrs)(void);
87524 -};
87525 +} __do_const;
87526
87527 struct rds_sock {
87528 struct sock rs_sk;
87529 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
87530 index edac9ef..16bcb98 100644
87531 --- a/net/rds/tcp.c
87532 +++ b/net/rds/tcp.c
87533 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
87534 int val = 1;
87535
87536 set_fs(KERNEL_DS);
87537 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
87538 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
87539 sizeof(val));
87540 set_fs(oldfs);
87541 }
87542 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
87543 index 81cf5a4..b5826ff 100644
87544 --- a/net/rds/tcp_send.c
87545 +++ b/net/rds/tcp_send.c
87546 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
87547
87548 oldfs = get_fs();
87549 set_fs(KERNEL_DS);
87550 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
87551 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
87552 sizeof(val));
87553 set_fs(oldfs);
87554 }
87555 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
87556 index 05996d0..5a1dfe0 100644
87557 --- a/net/rxrpc/af_rxrpc.c
87558 +++ b/net/rxrpc/af_rxrpc.c
87559 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
87560 __be32 rxrpc_epoch;
87561
87562 /* current debugging ID */
87563 -atomic_t rxrpc_debug_id;
87564 +atomic_unchecked_t rxrpc_debug_id;
87565
87566 /* count of skbs currently in use */
87567 atomic_t rxrpc_n_skbs;
87568 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
87569 index e4d9cbc..b229649 100644
87570 --- a/net/rxrpc/ar-ack.c
87571 +++ b/net/rxrpc/ar-ack.c
87572 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
87573
87574 _enter("{%d,%d,%d,%d},",
87575 call->acks_hard, call->acks_unacked,
87576 - atomic_read(&call->sequence),
87577 + atomic_read_unchecked(&call->sequence),
87578 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
87579
87580 stop = 0;
87581 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
87582
87583 /* each Tx packet has a new serial number */
87584 sp->hdr.serial =
87585 - htonl(atomic_inc_return(&call->conn->serial));
87586 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
87587
87588 hdr = (struct rxrpc_header *) txb->head;
87589 hdr->serial = sp->hdr.serial;
87590 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
87591 */
87592 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
87593 {
87594 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
87595 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
87596 }
87597
87598 /*
87599 @@ -629,7 +629,7 @@ process_further:
87600
87601 latest = ntohl(sp->hdr.serial);
87602 hard = ntohl(ack.firstPacket);
87603 - tx = atomic_read(&call->sequence);
87604 + tx = atomic_read_unchecked(&call->sequence);
87605
87606 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
87607 latest,
87608 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
87609 goto maybe_reschedule;
87610
87611 send_ACK_with_skew:
87612 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
87613 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
87614 ntohl(ack.serial));
87615 send_ACK:
87616 mtu = call->conn->trans->peer->if_mtu;
87617 @@ -1173,7 +1173,7 @@ send_ACK:
87618 ackinfo.rxMTU = htonl(5692);
87619 ackinfo.jumbo_max = htonl(4);
87620
87621 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
87622 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
87623 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
87624 ntohl(hdr.serial),
87625 ntohs(ack.maxSkew),
87626 @@ -1191,7 +1191,7 @@ send_ACK:
87627 send_message:
87628 _debug("send message");
87629
87630 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
87631 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
87632 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
87633 send_message_2:
87634
87635 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
87636 index a3bbb36..3341fb9 100644
87637 --- a/net/rxrpc/ar-call.c
87638 +++ b/net/rxrpc/ar-call.c
87639 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
87640 spin_lock_init(&call->lock);
87641 rwlock_init(&call->state_lock);
87642 atomic_set(&call->usage, 1);
87643 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
87644 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87645 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
87646
87647 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
87648 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
87649 index 4106ca9..a338d7a 100644
87650 --- a/net/rxrpc/ar-connection.c
87651 +++ b/net/rxrpc/ar-connection.c
87652 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
87653 rwlock_init(&conn->lock);
87654 spin_lock_init(&conn->state_lock);
87655 atomic_set(&conn->usage, 1);
87656 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
87657 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87658 conn->avail_calls = RXRPC_MAXCALLS;
87659 conn->size_align = 4;
87660 conn->header_size = sizeof(struct rxrpc_header);
87661 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
87662 index e7ed43a..6afa140 100644
87663 --- a/net/rxrpc/ar-connevent.c
87664 +++ b/net/rxrpc/ar-connevent.c
87665 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
87666
87667 len = iov[0].iov_len + iov[1].iov_len;
87668
87669 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
87670 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
87671 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
87672
87673 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
87674 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
87675 index 529572f..c758ca7 100644
87676 --- a/net/rxrpc/ar-input.c
87677 +++ b/net/rxrpc/ar-input.c
87678 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
87679 /* track the latest serial number on this connection for ACK packet
87680 * information */
87681 serial = ntohl(sp->hdr.serial);
87682 - hi_serial = atomic_read(&call->conn->hi_serial);
87683 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
87684 while (serial > hi_serial)
87685 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
87686 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
87687 serial);
87688
87689 /* request ACK generation for any ACK or DATA packet that requests
87690 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
87691 index a693aca..81e7293 100644
87692 --- a/net/rxrpc/ar-internal.h
87693 +++ b/net/rxrpc/ar-internal.h
87694 @@ -272,8 +272,8 @@ struct rxrpc_connection {
87695 int error; /* error code for local abort */
87696 int debug_id; /* debug ID for printks */
87697 unsigned int call_counter; /* call ID counter */
87698 - atomic_t serial; /* packet serial number counter */
87699 - atomic_t hi_serial; /* highest serial number received */
87700 + atomic_unchecked_t serial; /* packet serial number counter */
87701 + atomic_unchecked_t hi_serial; /* highest serial number received */
87702 u8 avail_calls; /* number of calls available */
87703 u8 size_align; /* data size alignment (for security) */
87704 u8 header_size; /* rxrpc + security header size */
87705 @@ -346,7 +346,7 @@ struct rxrpc_call {
87706 spinlock_t lock;
87707 rwlock_t state_lock; /* lock for state transition */
87708 atomic_t usage;
87709 - atomic_t sequence; /* Tx data packet sequence counter */
87710 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
87711 u32 abort_code; /* local/remote abort code */
87712 enum { /* current state of call */
87713 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
87714 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
87715 */
87716 extern atomic_t rxrpc_n_skbs;
87717 extern __be32 rxrpc_epoch;
87718 -extern atomic_t rxrpc_debug_id;
87719 +extern atomic_unchecked_t rxrpc_debug_id;
87720 extern struct workqueue_struct *rxrpc_workqueue;
87721
87722 /*
87723 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
87724 index 87f7135..74d3703 100644
87725 --- a/net/rxrpc/ar-local.c
87726 +++ b/net/rxrpc/ar-local.c
87727 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
87728 spin_lock_init(&local->lock);
87729 rwlock_init(&local->services_lock);
87730 atomic_set(&local->usage, 1);
87731 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
87732 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87733 memcpy(&local->srx, srx, sizeof(*srx));
87734 }
87735
87736 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
87737 index e1ac183..b43e10e 100644
87738 --- a/net/rxrpc/ar-output.c
87739 +++ b/net/rxrpc/ar-output.c
87740 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
87741 sp->hdr.cid = call->cid;
87742 sp->hdr.callNumber = call->call_id;
87743 sp->hdr.seq =
87744 - htonl(atomic_inc_return(&call->sequence));
87745 + htonl(atomic_inc_return_unchecked(&call->sequence));
87746 sp->hdr.serial =
87747 - htonl(atomic_inc_return(&conn->serial));
87748 + htonl(atomic_inc_return_unchecked(&conn->serial));
87749 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
87750 sp->hdr.userStatus = 0;
87751 sp->hdr.securityIndex = conn->security_ix;
87752 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
87753 index bebaa43..2644591 100644
87754 --- a/net/rxrpc/ar-peer.c
87755 +++ b/net/rxrpc/ar-peer.c
87756 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
87757 INIT_LIST_HEAD(&peer->error_targets);
87758 spin_lock_init(&peer->lock);
87759 atomic_set(&peer->usage, 1);
87760 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
87761 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87762 memcpy(&peer->srx, srx, sizeof(*srx));
87763
87764 rxrpc_assess_MTU_size(peer);
87765 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
87766 index 38047f7..9f48511 100644
87767 --- a/net/rxrpc/ar-proc.c
87768 +++ b/net/rxrpc/ar-proc.c
87769 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
87770 atomic_read(&conn->usage),
87771 rxrpc_conn_states[conn->state],
87772 key_serial(conn->key),
87773 - atomic_read(&conn->serial),
87774 - atomic_read(&conn->hi_serial));
87775 + atomic_read_unchecked(&conn->serial),
87776 + atomic_read_unchecked(&conn->hi_serial));
87777
87778 return 0;
87779 }
87780 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
87781 index 92df566..87ec1bf 100644
87782 --- a/net/rxrpc/ar-transport.c
87783 +++ b/net/rxrpc/ar-transport.c
87784 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
87785 spin_lock_init(&trans->client_lock);
87786 rwlock_init(&trans->conn_lock);
87787 atomic_set(&trans->usage, 1);
87788 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
87789 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87790
87791 if (peer->srx.transport.family == AF_INET) {
87792 switch (peer->srx.transport_type) {
87793 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
87794 index f226709..0e735a8 100644
87795 --- a/net/rxrpc/rxkad.c
87796 +++ b/net/rxrpc/rxkad.c
87797 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
87798
87799 len = iov[0].iov_len + iov[1].iov_len;
87800
87801 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
87802 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
87803 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
87804
87805 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
87806 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
87807
87808 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
87809
87810 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
87811 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
87812 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
87813
87814 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
87815 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
87816 index 391a245..296b3d7 100644
87817 --- a/net/sctp/ipv6.c
87818 +++ b/net/sctp/ipv6.c
87819 @@ -981,7 +981,7 @@ static const struct inet6_protocol sctpv6_protocol = {
87820 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
87821 };
87822
87823 -static struct sctp_af sctp_af_inet6 = {
87824 +static struct sctp_af sctp_af_inet6 __read_only = {
87825 .sa_family = AF_INET6,
87826 .sctp_xmit = sctp_v6_xmit,
87827 .setsockopt = ipv6_setsockopt,
87828 @@ -1013,7 +1013,7 @@ static struct sctp_af sctp_af_inet6 = {
87829 #endif
87830 };
87831
87832 -static struct sctp_pf sctp_pf_inet6 = {
87833 +static struct sctp_pf sctp_pf_inet6 __read_only = {
87834 .event_msgname = sctp_inet6_event_msgname,
87835 .skb_msgname = sctp_inet6_skb_msgname,
87836 .af_supported = sctp_inet6_af_supported,
87837 @@ -1038,7 +1038,7 @@ void sctp_v6_pf_init(void)
87838
87839 void sctp_v6_pf_exit(void)
87840 {
87841 - list_del(&sctp_af_inet6.list);
87842 + pax_list_del(&sctp_af_inet6.list);
87843 }
87844
87845 /* Initialize IPv6 support and register with socket layer. */
87846 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
87847 index 8c19e97..16264b8 100644
87848 --- a/net/sctp/proc.c
87849 +++ b/net/sctp/proc.c
87850 @@ -338,7 +338,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
87851 seq_printf(seq,
87852 "%8pK %8pK %-3d %-3d %-2d %-4d "
87853 "%4d %8d %8d %7d %5lu %-5d %5d ",
87854 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
87855 + assoc, sk,
87856 + sctp_sk(sk)->type, sk->sk_state,
87857 assoc->state, hash,
87858 assoc->assoc_id,
87859 assoc->sndbuf_used,
87860 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
87861 index f898b1c..a2d0fe8 100644
87862 --- a/net/sctp/protocol.c
87863 +++ b/net/sctp/protocol.c
87864 @@ -834,8 +834,10 @@ int sctp_register_af(struct sctp_af *af)
87865 return 0;
87866 }
87867
87868 + pax_open_kernel();
87869 INIT_LIST_HEAD(&af->list);
87870 - list_add_tail(&af->list, &sctp_address_families);
87871 + pax_close_kernel();
87872 + pax_list_add_tail(&af->list, &sctp_address_families);
87873 return 1;
87874 }
87875
87876 @@ -966,7 +968,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
87877
87878 static struct sctp_af sctp_af_inet;
87879
87880 -static struct sctp_pf sctp_pf_inet = {
87881 +static struct sctp_pf sctp_pf_inet __read_only = {
87882 .event_msgname = sctp_inet_event_msgname,
87883 .skb_msgname = sctp_inet_skb_msgname,
87884 .af_supported = sctp_inet_af_supported,
87885 @@ -1037,7 +1039,7 @@ static const struct net_protocol sctp_protocol = {
87886 };
87887
87888 /* IPv4 address related functions. */
87889 -static struct sctp_af sctp_af_inet = {
87890 +static struct sctp_af sctp_af_inet __read_only = {
87891 .sa_family = AF_INET,
87892 .sctp_xmit = sctp_v4_xmit,
87893 .setsockopt = ip_setsockopt,
87894 @@ -1122,7 +1124,7 @@ static void sctp_v4_pf_init(void)
87895
87896 static void sctp_v4_pf_exit(void)
87897 {
87898 - list_del(&sctp_af_inet.list);
87899 + pax_list_del(&sctp_af_inet.list);
87900 }
87901
87902 static int sctp_v4_protosw_init(void)
87903 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
87904 index c957775..6d4593a 100644
87905 --- a/net/sctp/sm_sideeffect.c
87906 +++ b/net/sctp/sm_sideeffect.c
87907 @@ -447,7 +447,7 @@ static void sctp_generate_sack_event(unsigned long data)
87908 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
87909 }
87910
87911 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
87912 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
87913 NULL,
87914 sctp_generate_t1_cookie_event,
87915 sctp_generate_t1_init_event,
87916 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
87917 index cedd9bf..d577d71 100644
87918 --- a/net/sctp/socket.c
87919 +++ b/net/sctp/socket.c
87920 @@ -4665,6 +4665,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
87921 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
87922 if (space_left < addrlen)
87923 return -ENOMEM;
87924 + if (addrlen > sizeof(temp) || addrlen < 0)
87925 + return -EFAULT;
87926 if (copy_to_user(to, &temp, addrlen))
87927 return -EFAULT;
87928 to += addrlen;
87929 @@ -5653,6 +5655,9 @@ static int sctp_getsockopt_assoc_stats(struct sock *sk, int len,
87930 if (len < sizeof(sctp_assoc_t))
87931 return -EINVAL;
87932
87933 + /* Allow the struct to grow and fill in as much as possible */
87934 + len = min_t(size_t, len, sizeof(sas));
87935 +
87936 if (copy_from_user(&sas, optval, len))
87937 return -EFAULT;
87938
87939 @@ -5686,9 +5691,6 @@ static int sctp_getsockopt_assoc_stats(struct sock *sk, int len,
87940 /* Mark beginning of a new observation period */
87941 asoc->stats.max_obs_rto = asoc->rto_min;
87942
87943 - /* Allow the struct to grow and fill in as much as possible */
87944 - len = min_t(size_t, len, sizeof(sas));
87945 -
87946 if (put_user(len, optlen))
87947 return -EFAULT;
87948
87949 diff --git a/net/sctp/ssnmap.c b/net/sctp/ssnmap.c
87950 index 442ad4e..825ea94 100644
87951 --- a/net/sctp/ssnmap.c
87952 +++ b/net/sctp/ssnmap.c
87953 @@ -41,8 +41,6 @@
87954 #include <net/sctp/sctp.h>
87955 #include <net/sctp/sm.h>
87956
87957 -#define MAX_KMALLOC_SIZE 131072
87958 -
87959 static struct sctp_ssnmap *sctp_ssnmap_init(struct sctp_ssnmap *map, __u16 in,
87960 __u16 out);
87961
87962 @@ -65,7 +63,7 @@ struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
87963 int size;
87964
87965 size = sctp_ssnmap_size(in, out);
87966 - if (size <= MAX_KMALLOC_SIZE)
87967 + if (size <= KMALLOC_MAX_SIZE)
87968 retval = kmalloc(size, gfp);
87969 else
87970 retval = (struct sctp_ssnmap *)
87971 @@ -82,7 +80,7 @@ struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
87972 return retval;
87973
87974 fail_map:
87975 - if (size <= MAX_KMALLOC_SIZE)
87976 + if (size <= KMALLOC_MAX_SIZE)
87977 kfree(retval);
87978 else
87979 free_pages((unsigned long)retval, get_order(size));
87980 @@ -124,7 +122,7 @@ void sctp_ssnmap_free(struct sctp_ssnmap *map)
87981 int size;
87982
87983 size = sctp_ssnmap_size(map->in.len, map->out.len);
87984 - if (size <= MAX_KMALLOC_SIZE)
87985 + if (size <= KMALLOC_MAX_SIZE)
87986 kfree(map);
87987 else
87988 free_pages((unsigned long)map, get_order(size));
87989 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
87990 index bf3c6e8..376d8d0 100644
87991 --- a/net/sctp/sysctl.c
87992 +++ b/net/sctp/sysctl.c
87993 @@ -307,7 +307,7 @@ static int proc_sctp_do_hmac_alg(ctl_table *ctl,
87994 {
87995 struct net *net = current->nsproxy->net_ns;
87996 char tmp[8];
87997 - ctl_table tbl;
87998 + ctl_table_no_const tbl;
87999 int ret;
88000 int changed = 0;
88001 char *none = "none";
88002 @@ -350,7 +350,7 @@ static int proc_sctp_do_hmac_alg(ctl_table *ctl,
88003
88004 int sctp_sysctl_net_register(struct net *net)
88005 {
88006 - struct ctl_table *table;
88007 + ctl_table_no_const *table;
88008 int i;
88009
88010 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
88011 diff --git a/net/socket.c b/net/socket.c
88012 index 2ca51c7..45d0b31 100644
88013 --- a/net/socket.c
88014 +++ b/net/socket.c
88015 @@ -89,6 +89,7 @@
88016 #include <linux/magic.h>
88017 #include <linux/slab.h>
88018 #include <linux/xattr.h>
88019 +#include <linux/in.h>
88020
88021 #include <asm/uaccess.h>
88022 #include <asm/unistd.h>
88023 @@ -106,6 +107,8 @@
88024 #include <linux/sockios.h>
88025 #include <linux/atalk.h>
88026
88027 +#include <linux/grsock.h>
88028 +
88029 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
88030 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
88031 unsigned long nr_segs, loff_t pos);
88032 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
88033 &sockfs_dentry_operations, SOCKFS_MAGIC);
88034 }
88035
88036 -static struct vfsmount *sock_mnt __read_mostly;
88037 +struct vfsmount *sock_mnt __read_mostly;
88038
88039 static struct file_system_type sock_fs_type = {
88040 .name = "sockfs",
88041 @@ -1270,6 +1273,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
88042 return -EAFNOSUPPORT;
88043 if (type < 0 || type >= SOCK_MAX)
88044 return -EINVAL;
88045 + if (protocol < 0)
88046 + return -EINVAL;
88047
88048 /* Compatibility.
88049
88050 @@ -1401,6 +1406,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
88051 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
88052 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
88053
88054 + if(!gr_search_socket(family, type, protocol)) {
88055 + retval = -EACCES;
88056 + goto out;
88057 + }
88058 +
88059 + if (gr_handle_sock_all(family, type, protocol)) {
88060 + retval = -EACCES;
88061 + goto out;
88062 + }
88063 +
88064 retval = sock_create(family, type, protocol, &sock);
88065 if (retval < 0)
88066 goto out;
88067 @@ -1528,6 +1543,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
88068 if (sock) {
88069 err = move_addr_to_kernel(umyaddr, addrlen, &address);
88070 if (err >= 0) {
88071 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
88072 + err = -EACCES;
88073 + goto error;
88074 + }
88075 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
88076 + if (err)
88077 + goto error;
88078 +
88079 err = security_socket_bind(sock,
88080 (struct sockaddr *)&address,
88081 addrlen);
88082 @@ -1536,6 +1559,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
88083 (struct sockaddr *)
88084 &address, addrlen);
88085 }
88086 +error:
88087 fput_light(sock->file, fput_needed);
88088 }
88089 return err;
88090 @@ -1559,10 +1583,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
88091 if ((unsigned int)backlog > somaxconn)
88092 backlog = somaxconn;
88093
88094 + if (gr_handle_sock_server_other(sock->sk)) {
88095 + err = -EPERM;
88096 + goto error;
88097 + }
88098 +
88099 + err = gr_search_listen(sock);
88100 + if (err)
88101 + goto error;
88102 +
88103 err = security_socket_listen(sock, backlog);
88104 if (!err)
88105 err = sock->ops->listen(sock, backlog);
88106
88107 +error:
88108 fput_light(sock->file, fput_needed);
88109 }
88110 return err;
88111 @@ -1606,6 +1640,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
88112 newsock->type = sock->type;
88113 newsock->ops = sock->ops;
88114
88115 + if (gr_handle_sock_server_other(sock->sk)) {
88116 + err = -EPERM;
88117 + sock_release(newsock);
88118 + goto out_put;
88119 + }
88120 +
88121 + err = gr_search_accept(sock);
88122 + if (err) {
88123 + sock_release(newsock);
88124 + goto out_put;
88125 + }
88126 +
88127 /*
88128 * We don't need try_module_get here, as the listening socket (sock)
88129 * has the protocol module (sock->ops->owner) held.
88130 @@ -1651,6 +1697,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
88131 fd_install(newfd, newfile);
88132 err = newfd;
88133
88134 + gr_attach_curr_ip(newsock->sk);
88135 +
88136 out_put:
88137 fput_light(sock->file, fput_needed);
88138 out:
88139 @@ -1683,6 +1731,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
88140 int, addrlen)
88141 {
88142 struct socket *sock;
88143 + struct sockaddr *sck;
88144 struct sockaddr_storage address;
88145 int err, fput_needed;
88146
88147 @@ -1693,6 +1742,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
88148 if (err < 0)
88149 goto out_put;
88150
88151 + sck = (struct sockaddr *)&address;
88152 +
88153 + if (gr_handle_sock_client(sck)) {
88154 + err = -EACCES;
88155 + goto out_put;
88156 + }
88157 +
88158 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
88159 + if (err)
88160 + goto out_put;
88161 +
88162 err =
88163 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
88164 if (err)
88165 @@ -2047,7 +2107,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
88166 * checking falls down on this.
88167 */
88168 if (copy_from_user(ctl_buf,
88169 - (void __user __force *)msg_sys->msg_control,
88170 + (void __force_user *)msg_sys->msg_control,
88171 ctl_len))
88172 goto out_freectl;
88173 msg_sys->msg_control = ctl_buf;
88174 @@ -2215,7 +2275,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
88175 * kernel msghdr to use the kernel address space)
88176 */
88177
88178 - uaddr = (__force void __user *)msg_sys->msg_name;
88179 + uaddr = (void __force_user *)msg_sys->msg_name;
88180 uaddr_len = COMPAT_NAMELEN(msg);
88181 if (MSG_CMSG_COMPAT & flags) {
88182 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
88183 @@ -2838,7 +2898,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
88184 }
88185
88186 ifr = compat_alloc_user_space(buf_size);
88187 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
88188 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
88189
88190 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
88191 return -EFAULT;
88192 @@ -2862,12 +2922,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
88193 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
88194
88195 if (copy_in_user(rxnfc, compat_rxnfc,
88196 - (void *)(&rxnfc->fs.m_ext + 1) -
88197 - (void *)rxnfc) ||
88198 + (void __user *)(&rxnfc->fs.m_ext + 1) -
88199 + (void __user *)rxnfc) ||
88200 copy_in_user(&rxnfc->fs.ring_cookie,
88201 &compat_rxnfc->fs.ring_cookie,
88202 - (void *)(&rxnfc->fs.location + 1) -
88203 - (void *)&rxnfc->fs.ring_cookie) ||
88204 + (void __user *)(&rxnfc->fs.location + 1) -
88205 + (void __user *)&rxnfc->fs.ring_cookie) ||
88206 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
88207 sizeof(rxnfc->rule_cnt)))
88208 return -EFAULT;
88209 @@ -2879,12 +2939,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
88210
88211 if (convert_out) {
88212 if (copy_in_user(compat_rxnfc, rxnfc,
88213 - (const void *)(&rxnfc->fs.m_ext + 1) -
88214 - (const void *)rxnfc) ||
88215 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
88216 + (const void __user *)rxnfc) ||
88217 copy_in_user(&compat_rxnfc->fs.ring_cookie,
88218 &rxnfc->fs.ring_cookie,
88219 - (const void *)(&rxnfc->fs.location + 1) -
88220 - (const void *)&rxnfc->fs.ring_cookie) ||
88221 + (const void __user *)(&rxnfc->fs.location + 1) -
88222 + (const void __user *)&rxnfc->fs.ring_cookie) ||
88223 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
88224 sizeof(rxnfc->rule_cnt)))
88225 return -EFAULT;
88226 @@ -2954,7 +3014,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
88227 old_fs = get_fs();
88228 set_fs(KERNEL_DS);
88229 err = dev_ioctl(net, cmd,
88230 - (struct ifreq __user __force *) &kifr);
88231 + (struct ifreq __force_user *) &kifr);
88232 set_fs(old_fs);
88233
88234 return err;
88235 @@ -3063,7 +3123,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
88236
88237 old_fs = get_fs();
88238 set_fs(KERNEL_DS);
88239 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
88240 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
88241 set_fs(old_fs);
88242
88243 if (cmd == SIOCGIFMAP && !err) {
88244 @@ -3168,7 +3228,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
88245 ret |= __get_user(rtdev, &(ur4->rt_dev));
88246 if (rtdev) {
88247 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
88248 - r4.rt_dev = (char __user __force *)devname;
88249 + r4.rt_dev = (char __force_user *)devname;
88250 devname[15] = 0;
88251 } else
88252 r4.rt_dev = NULL;
88253 @@ -3394,8 +3454,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
88254 int __user *uoptlen;
88255 int err;
88256
88257 - uoptval = (char __user __force *) optval;
88258 - uoptlen = (int __user __force *) optlen;
88259 + uoptval = (char __force_user *) optval;
88260 + uoptlen = (int __force_user *) optlen;
88261
88262 set_fs(KERNEL_DS);
88263 if (level == SOL_SOCKET)
88264 @@ -3415,7 +3475,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
88265 char __user *uoptval;
88266 int err;
88267
88268 - uoptval = (char __user __force *) optval;
88269 + uoptval = (char __force_user *) optval;
88270
88271 set_fs(KERNEL_DS);
88272 if (level == SOL_SOCKET)
88273 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
88274 index 507b5e8..049e64a 100644
88275 --- a/net/sunrpc/clnt.c
88276 +++ b/net/sunrpc/clnt.c
88277 @@ -1272,7 +1272,9 @@ call_start(struct rpc_task *task)
88278 (RPC_IS_ASYNC(task) ? "async" : "sync"));
88279
88280 /* Increment call count */
88281 - task->tk_msg.rpc_proc->p_count++;
88282 + pax_open_kernel();
88283 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
88284 + pax_close_kernel();
88285 clnt->cl_stats->rpccnt++;
88286 task->tk_action = call_reserve;
88287 }
88288 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
88289 index fb20f25..e3ba316 100644
88290 --- a/net/sunrpc/sched.c
88291 +++ b/net/sunrpc/sched.c
88292 @@ -259,9 +259,9 @@ static int rpc_wait_bit_killable(void *word)
88293 #ifdef RPC_DEBUG
88294 static void rpc_task_set_debuginfo(struct rpc_task *task)
88295 {
88296 - static atomic_t rpc_pid;
88297 + static atomic_unchecked_t rpc_pid;
88298
88299 - task->tk_pid = atomic_inc_return(&rpc_pid);
88300 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
88301 }
88302 #else
88303 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
88304 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
88305 index 2d34b6b..e2d584d 100644
88306 --- a/net/sunrpc/svc.c
88307 +++ b/net/sunrpc/svc.c
88308 @@ -1156,7 +1156,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
88309 svc_putnl(resv, RPC_SUCCESS);
88310
88311 /* Bump per-procedure stats counter */
88312 - procp->pc_count++;
88313 + pax_open_kernel();
88314 + (*(unsigned int *)&procp->pc_count)++;
88315 + pax_close_kernel();
88316
88317 /* Initialize storage for argp and resp */
88318 memset(rqstp->rq_argp, 0, procp->pc_argsize);
88319 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
88320 index 8343737..677025e 100644
88321 --- a/net/sunrpc/xprtrdma/svc_rdma.c
88322 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
88323 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
88324 static unsigned int min_max_inline = 4096;
88325 static unsigned int max_max_inline = 65536;
88326
88327 -atomic_t rdma_stat_recv;
88328 -atomic_t rdma_stat_read;
88329 -atomic_t rdma_stat_write;
88330 -atomic_t rdma_stat_sq_starve;
88331 -atomic_t rdma_stat_rq_starve;
88332 -atomic_t rdma_stat_rq_poll;
88333 -atomic_t rdma_stat_rq_prod;
88334 -atomic_t rdma_stat_sq_poll;
88335 -atomic_t rdma_stat_sq_prod;
88336 +atomic_unchecked_t rdma_stat_recv;
88337 +atomic_unchecked_t rdma_stat_read;
88338 +atomic_unchecked_t rdma_stat_write;
88339 +atomic_unchecked_t rdma_stat_sq_starve;
88340 +atomic_unchecked_t rdma_stat_rq_starve;
88341 +atomic_unchecked_t rdma_stat_rq_poll;
88342 +atomic_unchecked_t rdma_stat_rq_prod;
88343 +atomic_unchecked_t rdma_stat_sq_poll;
88344 +atomic_unchecked_t rdma_stat_sq_prod;
88345
88346 /* Temporary NFS request map and context caches */
88347 struct kmem_cache *svc_rdma_map_cachep;
88348 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
88349 len -= *ppos;
88350 if (len > *lenp)
88351 len = *lenp;
88352 - if (len && copy_to_user(buffer, str_buf, len))
88353 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
88354 return -EFAULT;
88355 *lenp = len;
88356 *ppos += len;
88357 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
88358 {
88359 .procname = "rdma_stat_read",
88360 .data = &rdma_stat_read,
88361 - .maxlen = sizeof(atomic_t),
88362 + .maxlen = sizeof(atomic_unchecked_t),
88363 .mode = 0644,
88364 .proc_handler = read_reset_stat,
88365 },
88366 {
88367 .procname = "rdma_stat_recv",
88368 .data = &rdma_stat_recv,
88369 - .maxlen = sizeof(atomic_t),
88370 + .maxlen = sizeof(atomic_unchecked_t),
88371 .mode = 0644,
88372 .proc_handler = read_reset_stat,
88373 },
88374 {
88375 .procname = "rdma_stat_write",
88376 .data = &rdma_stat_write,
88377 - .maxlen = sizeof(atomic_t),
88378 + .maxlen = sizeof(atomic_unchecked_t),
88379 .mode = 0644,
88380 .proc_handler = read_reset_stat,
88381 },
88382 {
88383 .procname = "rdma_stat_sq_starve",
88384 .data = &rdma_stat_sq_starve,
88385 - .maxlen = sizeof(atomic_t),
88386 + .maxlen = sizeof(atomic_unchecked_t),
88387 .mode = 0644,
88388 .proc_handler = read_reset_stat,
88389 },
88390 {
88391 .procname = "rdma_stat_rq_starve",
88392 .data = &rdma_stat_rq_starve,
88393 - .maxlen = sizeof(atomic_t),
88394 + .maxlen = sizeof(atomic_unchecked_t),
88395 .mode = 0644,
88396 .proc_handler = read_reset_stat,
88397 },
88398 {
88399 .procname = "rdma_stat_rq_poll",
88400 .data = &rdma_stat_rq_poll,
88401 - .maxlen = sizeof(atomic_t),
88402 + .maxlen = sizeof(atomic_unchecked_t),
88403 .mode = 0644,
88404 .proc_handler = read_reset_stat,
88405 },
88406 {
88407 .procname = "rdma_stat_rq_prod",
88408 .data = &rdma_stat_rq_prod,
88409 - .maxlen = sizeof(atomic_t),
88410 + .maxlen = sizeof(atomic_unchecked_t),
88411 .mode = 0644,
88412 .proc_handler = read_reset_stat,
88413 },
88414 {
88415 .procname = "rdma_stat_sq_poll",
88416 .data = &rdma_stat_sq_poll,
88417 - .maxlen = sizeof(atomic_t),
88418 + .maxlen = sizeof(atomic_unchecked_t),
88419 .mode = 0644,
88420 .proc_handler = read_reset_stat,
88421 },
88422 {
88423 .procname = "rdma_stat_sq_prod",
88424 .data = &rdma_stat_sq_prod,
88425 - .maxlen = sizeof(atomic_t),
88426 + .maxlen = sizeof(atomic_unchecked_t),
88427 .mode = 0644,
88428 .proc_handler = read_reset_stat,
88429 },
88430 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
88431 index 0ce7552..d074459 100644
88432 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
88433 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
88434 @@ -501,7 +501,7 @@ next_sge:
88435 svc_rdma_put_context(ctxt, 0);
88436 goto out;
88437 }
88438 - atomic_inc(&rdma_stat_read);
88439 + atomic_inc_unchecked(&rdma_stat_read);
88440
88441 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
88442 chl_map->ch[ch_no].count -= read_wr.num_sge;
88443 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
88444 dto_q);
88445 list_del_init(&ctxt->dto_q);
88446 } else {
88447 - atomic_inc(&rdma_stat_rq_starve);
88448 + atomic_inc_unchecked(&rdma_stat_rq_starve);
88449 clear_bit(XPT_DATA, &xprt->xpt_flags);
88450 ctxt = NULL;
88451 }
88452 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
88453 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
88454 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
88455 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
88456 - atomic_inc(&rdma_stat_recv);
88457 + atomic_inc_unchecked(&rdma_stat_recv);
88458
88459 /* Build up the XDR from the receive buffers. */
88460 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
88461 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
88462 index c1d124d..acfc59e 100644
88463 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
88464 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
88465 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
88466 write_wr.wr.rdma.remote_addr = to;
88467
88468 /* Post It */
88469 - atomic_inc(&rdma_stat_write);
88470 + atomic_inc_unchecked(&rdma_stat_write);
88471 if (svc_rdma_send(xprt, &write_wr))
88472 goto err;
88473 return 0;
88474 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
88475 index 62e4f9b..dd3f2d7 100644
88476 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
88477 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
88478 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
88479 return;
88480
88481 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
88482 - atomic_inc(&rdma_stat_rq_poll);
88483 + atomic_inc_unchecked(&rdma_stat_rq_poll);
88484
88485 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
88486 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
88487 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
88488 }
88489
88490 if (ctxt)
88491 - atomic_inc(&rdma_stat_rq_prod);
88492 + atomic_inc_unchecked(&rdma_stat_rq_prod);
88493
88494 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
88495 /*
88496 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
88497 return;
88498
88499 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
88500 - atomic_inc(&rdma_stat_sq_poll);
88501 + atomic_inc_unchecked(&rdma_stat_sq_poll);
88502 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
88503 if (wc.status != IB_WC_SUCCESS)
88504 /* Close the transport */
88505 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
88506 }
88507
88508 if (ctxt)
88509 - atomic_inc(&rdma_stat_sq_prod);
88510 + atomic_inc_unchecked(&rdma_stat_sq_prod);
88511 }
88512
88513 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
88514 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
88515 spin_lock_bh(&xprt->sc_lock);
88516 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
88517 spin_unlock_bh(&xprt->sc_lock);
88518 - atomic_inc(&rdma_stat_sq_starve);
88519 + atomic_inc_unchecked(&rdma_stat_sq_starve);
88520
88521 /* See if we can opportunistically reap SQ WR to make room */
88522 sq_cq_reap(xprt);
88523 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
88524 index 9bc6db0..47ac8c0 100644
88525 --- a/net/sysctl_net.c
88526 +++ b/net/sysctl_net.c
88527 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
88528 kgid_t root_gid = make_kgid(net->user_ns, 0);
88529
88530 /* Allow network administrator to have same access as root. */
88531 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
88532 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
88533 uid_eq(root_uid, current_uid())) {
88534 int mode = (table->mode >> 6) & 7;
88535 return (mode << 6) | (mode << 3) | mode;
88536 diff --git a/net/tipc/link.c b/net/tipc/link.c
88537 index daa6080..02d357f 100644
88538 --- a/net/tipc/link.c
88539 +++ b/net/tipc/link.c
88540 @@ -1201,7 +1201,7 @@ static int link_send_sections_long(struct tipc_port *sender,
88541 struct tipc_msg fragm_hdr;
88542 struct sk_buff *buf, *buf_chain, *prev;
88543 u32 fragm_crs, fragm_rest, hsz, sect_rest;
88544 - const unchar *sect_crs;
88545 + const unchar __user *sect_crs;
88546 int curr_sect;
88547 u32 fragm_no;
88548
88549 @@ -1242,7 +1242,7 @@ again:
88550
88551 if (!sect_rest) {
88552 sect_rest = msg_sect[++curr_sect].iov_len;
88553 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
88554 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
88555 }
88556
88557 if (sect_rest < fragm_rest)
88558 @@ -1261,7 +1261,7 @@ error:
88559 }
88560 } else
88561 skb_copy_to_linear_data_offset(buf, fragm_crs,
88562 - sect_crs, sz);
88563 + (const void __force_kernel *)sect_crs, sz);
88564 sect_crs += sz;
88565 sect_rest -= sz;
88566 fragm_crs += sz;
88567 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
88568 index f2db8a8..9245aa4 100644
88569 --- a/net/tipc/msg.c
88570 +++ b/net/tipc/msg.c
88571 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
88572 msg_sect[cnt].iov_len);
88573 else
88574 skb_copy_to_linear_data_offset(*buf, pos,
88575 - msg_sect[cnt].iov_base,
88576 + (const void __force_kernel *)msg_sect[cnt].iov_base,
88577 msg_sect[cnt].iov_len);
88578 pos += msg_sect[cnt].iov_len;
88579 }
88580 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
88581 index 6b42d47..2ac24d5 100644
88582 --- a/net/tipc/subscr.c
88583 +++ b/net/tipc/subscr.c
88584 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
88585 {
88586 struct iovec msg_sect;
88587
88588 - msg_sect.iov_base = (void *)&sub->evt;
88589 + msg_sect.iov_base = (void __force_user *)&sub->evt;
88590 msg_sect.iov_len = sizeof(struct tipc_event);
88591
88592 sub->evt.event = htohl(event, sub->swap);
88593 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
88594 index 5b5c876..6713b81 100644
88595 --- a/net/unix/af_unix.c
88596 +++ b/net/unix/af_unix.c
88597 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
88598 err = -ECONNREFUSED;
88599 if (!S_ISSOCK(inode->i_mode))
88600 goto put_fail;
88601 +
88602 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
88603 + err = -EACCES;
88604 + goto put_fail;
88605 + }
88606 +
88607 u = unix_find_socket_byinode(inode);
88608 if (!u)
88609 goto put_fail;
88610 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
88611 if (u) {
88612 struct dentry *dentry;
88613 dentry = unix_sk(u)->path.dentry;
88614 +
88615 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
88616 + err = -EPERM;
88617 + sock_put(u);
88618 + goto fail;
88619 + }
88620 +
88621 if (dentry)
88622 touch_atime(&unix_sk(u)->path);
88623 } else
88624 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
88625 */
88626 err = security_path_mknod(&path, dentry, mode, 0);
88627 if (!err) {
88628 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
88629 + err = -EACCES;
88630 + goto out;
88631 + }
88632 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
88633 if (!err) {
88634 res->mnt = mntget(path.mnt);
88635 res->dentry = dget(dentry);
88636 + gr_handle_create(dentry, path.mnt);
88637 }
88638 }
88639 +out:
88640 done_path_create(&path, dentry);
88641 return err;
88642 }
88643 @@ -2326,9 +2345,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
88644 seq_puts(seq, "Num RefCount Protocol Flags Type St "
88645 "Inode Path\n");
88646 else {
88647 - struct sock *s = v;
88648 + struct sock *s = v, *peer;
88649 struct unix_sock *u = unix_sk(s);
88650 unix_state_lock(s);
88651 + peer = unix_peer(s);
88652 + unix_state_unlock(s);
88653 +
88654 + unix_state_double_lock(s, peer);
88655
88656 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
88657 s,
88658 @@ -2355,8 +2378,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
88659 }
88660 for ( ; i < len; i++)
88661 seq_putc(seq, u->addr->name->sun_path[i]);
88662 - }
88663 - unix_state_unlock(s);
88664 + } else if (peer)
88665 + seq_printf(seq, " P%lu", sock_i_ino(peer));
88666 +
88667 + unix_state_double_unlock(s, peer);
88668 seq_putc(seq, '\n');
88669 }
88670
88671 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
88672 index 8800604..0526440 100644
88673 --- a/net/unix/sysctl_net_unix.c
88674 +++ b/net/unix/sysctl_net_unix.c
88675 @@ -28,7 +28,7 @@ static ctl_table unix_table[] = {
88676
88677 int __net_init unix_sysctl_register(struct net *net)
88678 {
88679 - struct ctl_table *table;
88680 + ctl_table_no_const *table;
88681
88682 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
88683 if (table == NULL)
88684 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
88685 index c8717c1..08539f5 100644
88686 --- a/net/wireless/wext-core.c
88687 +++ b/net/wireless/wext-core.c
88688 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
88689 */
88690
88691 /* Support for very large requests */
88692 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
88693 - (user_length > descr->max_tokens)) {
88694 + if (user_length > descr->max_tokens) {
88695 /* Allow userspace to GET more than max so
88696 * we can support any size GET requests.
88697 * There is still a limit : -ENOMEM.
88698 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
88699 }
88700 }
88701
88702 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
88703 - /*
88704 - * If this is a GET, but not NOMAX, it means that the extra
88705 - * data is not bounded by userspace, but by max_tokens. Thus
88706 - * set the length to max_tokens. This matches the extra data
88707 - * allocation.
88708 - * The driver should fill it with the number of tokens it
88709 - * provided, and it may check iwp->length rather than having
88710 - * knowledge of max_tokens. If the driver doesn't change the
88711 - * iwp->length, this ioctl just copies back max_token tokens
88712 - * filled with zeroes. Hopefully the driver isn't claiming
88713 - * them to be valid data.
88714 - */
88715 - iwp->length = descr->max_tokens;
88716 - }
88717 -
88718 err = handler(dev, info, (union iwreq_data *) iwp, extra);
88719
88720 iwp->length += essid_compat;
88721 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
88722 index 07c5857..fde4018 100644
88723 --- a/net/xfrm/xfrm_policy.c
88724 +++ b/net/xfrm/xfrm_policy.c
88725 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
88726 {
88727 policy->walk.dead = 1;
88728
88729 - atomic_inc(&policy->genid);
88730 + atomic_inc_unchecked(&policy->genid);
88731
88732 if (del_timer(&policy->timer))
88733 xfrm_pol_put(policy);
88734 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
88735 hlist_add_head(&policy->bydst, chain);
88736 xfrm_pol_hold(policy);
88737 net->xfrm.policy_count[dir]++;
88738 - atomic_inc(&flow_cache_genid);
88739 + atomic_inc_unchecked(&flow_cache_genid);
88740 rt_genid_bump(net);
88741 if (delpol)
88742 __xfrm_policy_unlink(delpol, dir);
88743 @@ -1550,7 +1550,7 @@ free_dst:
88744 goto out;
88745 }
88746
88747 -static int inline
88748 +static inline int
88749 xfrm_dst_alloc_copy(void **target, const void *src, int size)
88750 {
88751 if (!*target) {
88752 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
88753 return 0;
88754 }
88755
88756 -static int inline
88757 +static inline int
88758 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
88759 {
88760 #ifdef CONFIG_XFRM_SUB_POLICY
88761 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
88762 #endif
88763 }
88764
88765 -static int inline
88766 +static inline int
88767 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
88768 {
88769 #ifdef CONFIG_XFRM_SUB_POLICY
88770 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
88771
88772 xdst->num_pols = num_pols;
88773 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
88774 - xdst->policy_genid = atomic_read(&pols[0]->genid);
88775 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
88776
88777 return xdst;
88778 }
88779 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
88780 if (xdst->xfrm_genid != dst->xfrm->genid)
88781 return 0;
88782 if (xdst->num_pols > 0 &&
88783 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
88784 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
88785 return 0;
88786
88787 mtu = dst_mtu(dst->child);
88788 @@ -2457,8 +2457,11 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
88789 dst_ops->link_failure = xfrm_link_failure;
88790 if (likely(dst_ops->neigh_lookup == NULL))
88791 dst_ops->neigh_lookup = xfrm_neigh_lookup;
88792 - if (likely(afinfo->garbage_collect == NULL))
88793 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
88794 + if (likely(afinfo->garbage_collect == NULL)) {
88795 + pax_open_kernel();
88796 + *(void **)&afinfo->garbage_collect = xfrm_garbage_collect_deferred;
88797 + pax_close_kernel();
88798 + }
88799 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
88800 }
88801 spin_unlock(&xfrm_policy_afinfo_lock);
88802 @@ -2512,7 +2515,9 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
88803 dst_ops->check = NULL;
88804 dst_ops->negative_advice = NULL;
88805 dst_ops->link_failure = NULL;
88806 - afinfo->garbage_collect = NULL;
88807 + pax_open_kernel();
88808 + *(void **)&afinfo->garbage_collect = NULL;
88809 + pax_close_kernel();
88810 }
88811 return err;
88812 }
88813 @@ -2896,7 +2901,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
88814 sizeof(pol->xfrm_vec[i].saddr));
88815 pol->xfrm_vec[i].encap_family = mp->new_family;
88816 /* flush bundles */
88817 - atomic_inc(&pol->genid);
88818 + atomic_inc_unchecked(&pol->genid);
88819 }
88820 }
88821
88822 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
88823 index 3459692..e7cdb1a 100644
88824 --- a/net/xfrm/xfrm_state.c
88825 +++ b/net/xfrm/xfrm_state.c
88826 @@ -194,11 +194,13 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
88827
88828 if (unlikely(afinfo == NULL))
88829 return -EAFNOSUPPORT;
88830 - typemap = afinfo->type_map;
88831 + typemap = (const struct xfrm_type **)afinfo->type_map;
88832
88833 - if (likely(typemap[type->proto] == NULL))
88834 + if (likely(typemap[type->proto] == NULL)) {
88835 + pax_open_kernel();
88836 typemap[type->proto] = type;
88837 - else
88838 + pax_close_kernel();
88839 + } else
88840 err = -EEXIST;
88841 xfrm_state_unlock_afinfo(afinfo);
88842 return err;
88843 @@ -213,12 +215,15 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
88844
88845 if (unlikely(afinfo == NULL))
88846 return -EAFNOSUPPORT;
88847 - typemap = afinfo->type_map;
88848 + typemap = (const struct xfrm_type **)afinfo->type_map;
88849
88850 if (unlikely(typemap[type->proto] != type))
88851 err = -ENOENT;
88852 - else
88853 + else {
88854 + pax_open_kernel();
88855 typemap[type->proto] = NULL;
88856 + pax_close_kernel();
88857 + }
88858 xfrm_state_unlock_afinfo(afinfo);
88859 return err;
88860 }
88861 @@ -227,7 +232,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
88862 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
88863 {
88864 struct xfrm_state_afinfo *afinfo;
88865 - const struct xfrm_type **typemap;
88866 const struct xfrm_type *type;
88867 int modload_attempted = 0;
88868
88869 @@ -235,9 +239,8 @@ retry:
88870 afinfo = xfrm_state_get_afinfo(family);
88871 if (unlikely(afinfo == NULL))
88872 return NULL;
88873 - typemap = afinfo->type_map;
88874
88875 - type = typemap[proto];
88876 + type = afinfo->type_map[proto];
88877 if (unlikely(type && !try_module_get(type->owner)))
88878 type = NULL;
88879 if (!type && !modload_attempted) {
88880 @@ -270,7 +273,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
88881 return -EAFNOSUPPORT;
88882
88883 err = -EEXIST;
88884 - modemap = afinfo->mode_map;
88885 + modemap = (struct xfrm_mode **)afinfo->mode_map;
88886 if (modemap[mode->encap])
88887 goto out;
88888
88889 @@ -278,8 +281,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
88890 if (!try_module_get(afinfo->owner))
88891 goto out;
88892
88893 - mode->afinfo = afinfo;
88894 + pax_open_kernel();
88895 + *(const void **)&mode->afinfo = afinfo;
88896 modemap[mode->encap] = mode;
88897 + pax_close_kernel();
88898 err = 0;
88899
88900 out:
88901 @@ -302,9 +307,11 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
88902 return -EAFNOSUPPORT;
88903
88904 err = -ENOENT;
88905 - modemap = afinfo->mode_map;
88906 + modemap = (struct xfrm_mode **)afinfo->mode_map;
88907 if (likely(modemap[mode->encap] == mode)) {
88908 + pax_open_kernel();
88909 modemap[mode->encap] = NULL;
88910 + pax_close_kernel();
88911 module_put(mode->afinfo->owner);
88912 err = 0;
88913 }
88914 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
88915 index 05a6e3d..6716ec9 100644
88916 --- a/net/xfrm/xfrm_sysctl.c
88917 +++ b/net/xfrm/xfrm_sysctl.c
88918 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
88919
88920 int __net_init xfrm_sysctl_init(struct net *net)
88921 {
88922 - struct ctl_table *table;
88923 + ctl_table_no_const *table;
88924
88925 __xfrm_sysctl_init(net);
88926
88927 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
88928 index 0e801c3..5c8ad3b 100644
88929 --- a/scripts/Makefile.build
88930 +++ b/scripts/Makefile.build
88931 @@ -111,7 +111,7 @@ endif
88932 endif
88933
88934 # Do not include host rules unless needed
88935 -ifneq ($(hostprogs-y)$(hostprogs-m),)
88936 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
88937 include scripts/Makefile.host
88938 endif
88939
88940 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
88941 index 686cb0d..9d653bf 100644
88942 --- a/scripts/Makefile.clean
88943 +++ b/scripts/Makefile.clean
88944 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
88945 __clean-files := $(extra-y) $(always) \
88946 $(targets) $(clean-files) \
88947 $(host-progs) \
88948 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
88949 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
88950 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
88951
88952 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
88953
88954 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
88955 index 1ac414f..38575f7 100644
88956 --- a/scripts/Makefile.host
88957 +++ b/scripts/Makefile.host
88958 @@ -31,6 +31,8 @@
88959 # Note: Shared libraries consisting of C++ files are not supported
88960
88961 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
88962 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
88963 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
88964
88965 # C code
88966 # Executables compiled from a single .c file
88967 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
88968 # Shared libaries (only .c supported)
88969 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
88970 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
88971 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
88972 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
88973 # Remove .so files from "xxx-objs"
88974 host-cobjs := $(filter-out %.so,$(host-cobjs))
88975 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
88976
88977 -#Object (.o) files used by the shared libaries
88978 +# Object (.o) files used by the shared libaries
88979 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
88980 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
88981
88982 # output directory for programs/.o files
88983 # hostprogs-y := tools/build may have been specified. Retrieve directory
88984 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
88985 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
88986 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
88987 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
88988 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
88989 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
88990 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
88991 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
88992
88993 obj-dirs += $(host-objdirs)
88994 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
88995 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
88996 $(call if_changed_dep,host-cshobjs)
88997
88998 +# Compile .c file, create position independent .o file
88999 +# host-cxxshobjs -> .o
89000 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
89001 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
89002 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
89003 + $(call if_changed_dep,host-cxxshobjs)
89004 +
89005 # Link a shared library, based on position independent .o files
89006 # *.o -> .so shared library (host-cshlib)
89007 quiet_cmd_host-cshlib = HOSTLLD -shared $@
89008 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
89009 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
89010 $(call if_changed,host-cshlib)
89011
89012 +# Link a shared library, based on position independent .o files
89013 +# *.o -> .so shared library (host-cxxshlib)
89014 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
89015 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
89016 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
89017 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
89018 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
89019 + $(call if_changed,host-cxxshlib)
89020 +
89021 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
89022 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
89023 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
89024
89025 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
89026 index cb1f50c..cef2a7c 100644
89027 --- a/scripts/basic/fixdep.c
89028 +++ b/scripts/basic/fixdep.c
89029 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
89030 /*
89031 * Lookup a value in the configuration string.
89032 */
89033 -static int is_defined_config(const char *name, int len, unsigned int hash)
89034 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
89035 {
89036 struct item *aux;
89037
89038 @@ -211,10 +211,10 @@ static void clear_config(void)
89039 /*
89040 * Record the use of a CONFIG_* word.
89041 */
89042 -static void use_config(const char *m, int slen)
89043 +static void use_config(const char *m, unsigned int slen)
89044 {
89045 unsigned int hash = strhash(m, slen);
89046 - int c, i;
89047 + unsigned int c, i;
89048
89049 if (is_defined_config(m, slen, hash))
89050 return;
89051 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
89052
89053 static void parse_config_file(const char *map, size_t len)
89054 {
89055 - const int *end = (const int *) (map + len);
89056 + const unsigned int *end = (const unsigned int *) (map + len);
89057 /* start at +1, so that p can never be < map */
89058 - const int *m = (const int *) map + 1;
89059 + const unsigned int *m = (const unsigned int *) map + 1;
89060 const char *p, *q;
89061
89062 for (; m < end; m++) {
89063 @@ -406,7 +406,7 @@ static void print_deps(void)
89064 static void traps(void)
89065 {
89066 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
89067 - int *p = (int *)test;
89068 + unsigned int *p = (unsigned int *)test;
89069
89070 if (*p != INT_CONF) {
89071 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
89072 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
89073 new file mode 100644
89074 index 0000000..5e0222d
89075 --- /dev/null
89076 +++ b/scripts/gcc-plugin.sh
89077 @@ -0,0 +1,17 @@
89078 +#!/bin/bash
89079 +plugincc=`$1 -E -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
89080 +#include "gcc-plugin.h"
89081 +#include "tree.h"
89082 +#include "tm.h"
89083 +#include "rtl.h"
89084 +#ifdef ENABLE_BUILD_WITH_CXX
89085 +#warning $2
89086 +#else
89087 +#warning $1
89088 +#endif
89089 +EOF`
89090 +if [ $? -eq 0 ]
89091 +then
89092 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
89093 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
89094 +fi
89095 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
89096 index b3d907e..a4782ab 100644
89097 --- a/scripts/link-vmlinux.sh
89098 +++ b/scripts/link-vmlinux.sh
89099 @@ -152,7 +152,7 @@ else
89100 fi;
89101
89102 # final build of init/
89103 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
89104 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
89105
89106 kallsymso=""
89107 kallsyms_vmlinux=""
89108 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
89109 index df4fc23..0ea719d 100644
89110 --- a/scripts/mod/file2alias.c
89111 +++ b/scripts/mod/file2alias.c
89112 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
89113 unsigned long size, unsigned long id_size,
89114 void *symval)
89115 {
89116 - int i;
89117 + unsigned int i;
89118
89119 if (size % id_size || size < id_size) {
89120 if (cross_build != 0)
89121 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
89122 /* USB is special because the bcdDevice can be matched against a numeric range */
89123 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
89124 static void do_usb_entry(struct usb_device_id *id,
89125 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
89126 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
89127 unsigned char range_lo, unsigned char range_hi,
89128 unsigned char max, struct module *mod)
89129 {
89130 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
89131 {
89132 unsigned int devlo, devhi;
89133 unsigned char chi, clo, max;
89134 - int ndigits;
89135 + unsigned int ndigits;
89136
89137 id->match_flags = TO_NATIVE(id->match_flags);
89138 id->idVendor = TO_NATIVE(id->idVendor);
89139 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
89140 for (i = 0; i < count; i++) {
89141 const char *id = (char *)devs[i].id;
89142 char acpi_id[sizeof(devs[0].id)];
89143 - int j;
89144 + unsigned int j;
89145
89146 buf_printf(&mod->dev_table_buf,
89147 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
89148 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
89149
89150 for (j = 0; j < PNP_MAX_DEVICES; j++) {
89151 const char *id = (char *)card->devs[j].id;
89152 - int i2, j2;
89153 + unsigned int i2, j2;
89154 int dup = 0;
89155
89156 if (!id[0])
89157 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
89158 /* add an individual alias for every device entry */
89159 if (!dup) {
89160 char acpi_id[sizeof(card->devs[0].id)];
89161 - int k;
89162 + unsigned int k;
89163
89164 buf_printf(&mod->dev_table_buf,
89165 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
89166 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
89167 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
89168 char *alias)
89169 {
89170 - int i, j;
89171 + unsigned int i, j;
89172
89173 sprintf(alias, "dmi*");
89174
89175 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
89176 index ff36c50..7ab4fa9 100644
89177 --- a/scripts/mod/modpost.c
89178 +++ b/scripts/mod/modpost.c
89179 @@ -929,6 +929,7 @@ enum mismatch {
89180 ANY_INIT_TO_ANY_EXIT,
89181 ANY_EXIT_TO_ANY_INIT,
89182 EXPORT_TO_INIT_EXIT,
89183 + DATA_TO_TEXT
89184 };
89185
89186 struct sectioncheck {
89187 @@ -1043,6 +1044,12 @@ const struct sectioncheck sectioncheck[] = {
89188 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
89189 .mismatch = EXPORT_TO_INIT_EXIT,
89190 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
89191 +},
89192 +/* Do not reference code from writable data */
89193 +{
89194 + .fromsec = { DATA_SECTIONS, NULL },
89195 + .tosec = { TEXT_SECTIONS, NULL },
89196 + .mismatch = DATA_TO_TEXT
89197 }
89198 };
89199
89200 @@ -1165,10 +1172,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
89201 continue;
89202 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
89203 continue;
89204 - if (sym->st_value == addr)
89205 - return sym;
89206 /* Find a symbol nearby - addr are maybe negative */
89207 d = sym->st_value - addr;
89208 + if (d == 0)
89209 + return sym;
89210 if (d < 0)
89211 d = addr - sym->st_value;
89212 if (d < distance) {
89213 @@ -1447,6 +1454,14 @@ static void report_sec_mismatch(const char *modname,
89214 tosym, prl_to, prl_to, tosym);
89215 free(prl_to);
89216 break;
89217 + case DATA_TO_TEXT:
89218 +#if 0
89219 + fprintf(stderr,
89220 + "The %s %s:%s references\n"
89221 + "the %s %s:%s%s\n",
89222 + from, fromsec, fromsym, to, tosec, tosym, to_p);
89223 +#endif
89224 + break;
89225 }
89226 fprintf(stderr, "\n");
89227 }
89228 @@ -1681,7 +1696,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
89229 static void check_sec_ref(struct module *mod, const char *modname,
89230 struct elf_info *elf)
89231 {
89232 - int i;
89233 + unsigned int i;
89234 Elf_Shdr *sechdrs = elf->sechdrs;
89235
89236 /* Walk through all sections */
89237 @@ -1779,7 +1794,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
89238 va_end(ap);
89239 }
89240
89241 -void buf_write(struct buffer *buf, const char *s, int len)
89242 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
89243 {
89244 if (buf->size - buf->pos < len) {
89245 buf->size += len + SZ;
89246 @@ -1997,7 +2012,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
89247 if (fstat(fileno(file), &st) < 0)
89248 goto close_write;
89249
89250 - if (st.st_size != b->pos)
89251 + if (st.st_size != (off_t)b->pos)
89252 goto close_write;
89253
89254 tmp = NOFAIL(malloc(b->pos));
89255 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
89256 index 51207e4..f7d603d 100644
89257 --- a/scripts/mod/modpost.h
89258 +++ b/scripts/mod/modpost.h
89259 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
89260
89261 struct buffer {
89262 char *p;
89263 - int pos;
89264 - int size;
89265 + unsigned int pos;
89266 + unsigned int size;
89267 };
89268
89269 void __attribute__((format(printf, 2, 3)))
89270 buf_printf(struct buffer *buf, const char *fmt, ...);
89271
89272 void
89273 -buf_write(struct buffer *buf, const char *s, int len);
89274 +buf_write(struct buffer *buf, const char *s, unsigned int len);
89275
89276 struct module {
89277 struct module *next;
89278 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
89279 index 9dfcd6d..099068e 100644
89280 --- a/scripts/mod/sumversion.c
89281 +++ b/scripts/mod/sumversion.c
89282 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
89283 goto out;
89284 }
89285
89286 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
89287 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
89288 warn("writing sum in %s failed: %s\n",
89289 filename, strerror(errno));
89290 goto out;
89291 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
89292 index 68bb4ef..2f419e1 100644
89293 --- a/scripts/pnmtologo.c
89294 +++ b/scripts/pnmtologo.c
89295 @@ -244,14 +244,14 @@ static void write_header(void)
89296 fprintf(out, " * Linux logo %s\n", logoname);
89297 fputs(" */\n\n", out);
89298 fputs("#include <linux/linux_logo.h>\n\n", out);
89299 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
89300 + fprintf(out, "static unsigned char %s_data[] = {\n",
89301 logoname);
89302 }
89303
89304 static void write_footer(void)
89305 {
89306 fputs("\n};\n\n", out);
89307 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
89308 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
89309 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
89310 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
89311 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
89312 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
89313 fputs("\n};\n\n", out);
89314
89315 /* write logo clut */
89316 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
89317 + fprintf(out, "static unsigned char %s_clut[] = {\n",
89318 logoname);
89319 write_hex_cnt = 0;
89320 for (i = 0; i < logo_clutsize; i++) {
89321 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
89322 index e4fd45b..2eeb5c4 100644
89323 --- a/scripts/sortextable.h
89324 +++ b/scripts/sortextable.h
89325 @@ -106,9 +106,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
89326 const char *secstrtab;
89327 const char *strtab;
89328 char *extab_image;
89329 - int extab_index = 0;
89330 - int i;
89331 - int idx;
89332 + unsigned int extab_index = 0;
89333 + unsigned int i;
89334 + unsigned int idx;
89335
89336 shdr = (Elf_Shdr *)((char *)ehdr + _r(&ehdr->e_shoff));
89337 shstrtab_sec = shdr + r2(&ehdr->e_shstrndx);
89338 diff --git a/security/Kconfig b/security/Kconfig
89339 index e9c6ac7..952353c 100644
89340 --- a/security/Kconfig
89341 +++ b/security/Kconfig
89342 @@ -4,6 +4,925 @@
89343
89344 menu "Security options"
89345
89346 +menu "Grsecurity"
89347 +
89348 + config ARCH_TRACK_EXEC_LIMIT
89349 + bool
89350 +
89351 + config PAX_KERNEXEC_PLUGIN
89352 + bool
89353 +
89354 + config PAX_PER_CPU_PGD
89355 + bool
89356 +
89357 + config TASK_SIZE_MAX_SHIFT
89358 + int
89359 + depends on X86_64
89360 + default 47 if !PAX_PER_CPU_PGD
89361 + default 42 if PAX_PER_CPU_PGD
89362 +
89363 + config PAX_ENABLE_PAE
89364 + bool
89365 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
89366 +
89367 + config PAX_USERCOPY_SLABS
89368 + bool
89369 +
89370 +config GRKERNSEC
89371 + bool "Grsecurity"
89372 + select CRYPTO
89373 + select CRYPTO_SHA256
89374 + select PROC_FS
89375 + select STOP_MACHINE
89376 + help
89377 + If you say Y here, you will be able to configure many features
89378 + that will enhance the security of your system. It is highly
89379 + recommended that you say Y here and read through the help
89380 + for each option so that you fully understand the features and
89381 + can evaluate their usefulness for your machine.
89382 +
89383 +choice
89384 + prompt "Configuration Method"
89385 + depends on GRKERNSEC
89386 + default GRKERNSEC_CONFIG_CUSTOM
89387 + help
89388 +
89389 +config GRKERNSEC_CONFIG_AUTO
89390 + bool "Automatic"
89391 + help
89392 + If you choose this configuration method, you'll be able to answer a small
89393 + number of simple questions about how you plan to use this kernel.
89394 + The settings of grsecurity and PaX will be automatically configured for
89395 + the highest commonly-used settings within the provided constraints.
89396 +
89397 + If you require additional configuration, custom changes can still be made
89398 + from the "custom configuration" menu.
89399 +
89400 +config GRKERNSEC_CONFIG_CUSTOM
89401 + bool "Custom"
89402 + help
89403 + If you choose this configuration method, you'll be able to configure all
89404 + grsecurity and PaX settings manually. Via this method, no options are
89405 + automatically enabled.
89406 +
89407 +endchoice
89408 +
89409 +choice
89410 + prompt "Usage Type"
89411 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
89412 + default GRKERNSEC_CONFIG_SERVER
89413 + help
89414 +
89415 +config GRKERNSEC_CONFIG_SERVER
89416 + bool "Server"
89417 + help
89418 + Choose this option if you plan to use this kernel on a server.
89419 +
89420 +config GRKERNSEC_CONFIG_DESKTOP
89421 + bool "Desktop"
89422 + help
89423 + Choose this option if you plan to use this kernel on a desktop.
89424 +
89425 +endchoice
89426 +
89427 +choice
89428 + prompt "Virtualization Type"
89429 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
89430 + default GRKERNSEC_CONFIG_VIRT_NONE
89431 + help
89432 +
89433 +config GRKERNSEC_CONFIG_VIRT_NONE
89434 + bool "None"
89435 + help
89436 + Choose this option if this kernel will be run on bare metal.
89437 +
89438 +config GRKERNSEC_CONFIG_VIRT_GUEST
89439 + bool "Guest"
89440 + help
89441 + Choose this option if this kernel will be run as a VM guest.
89442 +
89443 +config GRKERNSEC_CONFIG_VIRT_HOST
89444 + bool "Host"
89445 + help
89446 + Choose this option if this kernel will be run as a VM host.
89447 +
89448 +endchoice
89449 +
89450 +choice
89451 + prompt "Virtualization Hardware"
89452 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
89453 + help
89454 +
89455 +config GRKERNSEC_CONFIG_VIRT_EPT
89456 + bool "EPT/RVI Processor Support"
89457 + depends on X86
89458 + help
89459 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
89460 + hardware virtualization. This allows for additional kernel hardening protections
89461 + to operate without additional performance impact.
89462 +
89463 + To see if your Intel processor supports EPT, see:
89464 + http://ark.intel.com/Products/VirtualizationTechnology
89465 + (Most Core i3/5/7 support EPT)
89466 +
89467 + To see if your AMD processor supports RVI, see:
89468 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
89469 +
89470 +config GRKERNSEC_CONFIG_VIRT_SOFT
89471 + bool "First-gen/No Hardware Virtualization"
89472 + help
89473 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
89474 + support hardware virtualization or doesn't support the EPT/RVI extensions.
89475 +
89476 +endchoice
89477 +
89478 +choice
89479 + prompt "Virtualization Software"
89480 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
89481 + help
89482 +
89483 +config GRKERNSEC_CONFIG_VIRT_XEN
89484 + bool "Xen"
89485 + help
89486 + Choose this option if this kernel is running as a Xen guest or host.
89487 +
89488 +config GRKERNSEC_CONFIG_VIRT_VMWARE
89489 + bool "VMWare"
89490 + help
89491 + Choose this option if this kernel is running as a VMWare guest or host.
89492 +
89493 +config GRKERNSEC_CONFIG_VIRT_KVM
89494 + bool "KVM"
89495 + help
89496 + Choose this option if this kernel is running as a KVM guest or host.
89497 +
89498 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
89499 + bool "VirtualBox"
89500 + help
89501 + Choose this option if this kernel is running as a VirtualBox guest or host.
89502 +
89503 +endchoice
89504 +
89505 +choice
89506 + prompt "Required Priorities"
89507 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
89508 + default GRKERNSEC_CONFIG_PRIORITY_PERF
89509 + help
89510 +
89511 +config GRKERNSEC_CONFIG_PRIORITY_PERF
89512 + bool "Performance"
89513 + help
89514 + Choose this option if performance is of highest priority for this deployment
89515 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
89516 + and freed memory sanitizing will be disabled.
89517 +
89518 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
89519 + bool "Security"
89520 + help
89521 + Choose this option if security is of highest priority for this deployment of
89522 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
89523 + be enabled for this kernel. In a worst-case scenario, these features can
89524 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
89525 +
89526 +endchoice
89527 +
89528 +menu "Default Special Groups"
89529 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
89530 +
89531 +config GRKERNSEC_PROC_GID
89532 + int "GID exempted from /proc restrictions"
89533 + default 1001
89534 + help
89535 + Setting this GID determines which group will be exempted from
89536 + grsecurity's /proc restrictions, allowing users of the specified
89537 + group to view network statistics and the existence of other users'
89538 + processes on the system. This GID may also be chosen at boot time
89539 + via "grsec_proc_gid=" on the kernel commandline.
89540 +
89541 +config GRKERNSEC_TPE_UNTRUSTED_GID
89542 + int "GID for TPE-untrusted users"
89543 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
89544 + default 1005
89545 + help
89546 + Setting this GID determines which group untrusted users should
89547 + be added to. These users will be placed under grsecurity's Trusted Path
89548 + Execution mechanism, preventing them from executing their own binaries.
89549 + The users will only be able to execute binaries in directories owned and
89550 + writable only by the root user. If the sysctl option is enabled, a sysctl
89551 + option with name "tpe_gid" is created.
89552 +
89553 +config GRKERNSEC_TPE_TRUSTED_GID
89554 + int "GID for TPE-trusted users"
89555 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
89556 + default 1005
89557 + help
89558 + Setting this GID determines what group TPE restrictions will be
89559 + *disabled* for. If the sysctl option is enabled, a sysctl option
89560 + with name "tpe_gid" is created.
89561 +
89562 +config GRKERNSEC_SYMLINKOWN_GID
89563 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
89564 + depends on GRKERNSEC_CONFIG_SERVER
89565 + default 1006
89566 + help
89567 + Setting this GID determines what group kernel-enforced
89568 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
89569 + is enabled, a sysctl option with name "symlinkown_gid" is created.
89570 +
89571 +
89572 +endmenu
89573 +
89574 +menu "Customize Configuration"
89575 +depends on GRKERNSEC
89576 +
89577 +menu "PaX"
89578 +
89579 +config PAX
89580 + bool "Enable various PaX features"
89581 + default y if GRKERNSEC_CONFIG_AUTO
89582 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
89583 + help
89584 + This allows you to enable various PaX features. PaX adds
89585 + intrusion prevention mechanisms to the kernel that reduce
89586 + the risks posed by exploitable memory corruption bugs.
89587 +
89588 +menu "PaX Control"
89589 + depends on PAX
89590 +
89591 +config PAX_SOFTMODE
89592 + bool 'Support soft mode'
89593 + help
89594 + Enabling this option will allow you to run PaX in soft mode, that
89595 + is, PaX features will not be enforced by default, only on executables
89596 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
89597 + support as they are the only way to mark executables for soft mode use.
89598 +
89599 + Soft mode can be activated by using the "pax_softmode=1" kernel command
89600 + line option on boot. Furthermore you can control various PaX features
89601 + at runtime via the entries in /proc/sys/kernel/pax.
89602 +
89603 +config PAX_EI_PAX
89604 + bool 'Use legacy ELF header marking'
89605 + default y if GRKERNSEC_CONFIG_AUTO
89606 + help
89607 + Enabling this option will allow you to control PaX features on
89608 + a per executable basis via the 'chpax' utility available at
89609 + http://pax.grsecurity.net/. The control flags will be read from
89610 + an otherwise reserved part of the ELF header. This marking has
89611 + numerous drawbacks (no support for soft-mode, toolchain does not
89612 + know about the non-standard use of the ELF header) therefore it
89613 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
89614 + support.
89615 +
89616 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
89617 + support as well, they will override the legacy EI_PAX marks.
89618 +
89619 + If you enable none of the marking options then all applications
89620 + will run with PaX enabled on them by default.
89621 +
89622 +config PAX_PT_PAX_FLAGS
89623 + bool 'Use ELF program header marking'
89624 + default y if GRKERNSEC_CONFIG_AUTO
89625 + help
89626 + Enabling this option will allow you to control PaX features on
89627 + a per executable basis via the 'paxctl' utility available at
89628 + http://pax.grsecurity.net/. The control flags will be read from
89629 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
89630 + has the benefits of supporting both soft mode and being fully
89631 + integrated into the toolchain (the binutils patch is available
89632 + from http://pax.grsecurity.net).
89633 +
89634 + Note that if you enable the legacy EI_PAX marking support as well,
89635 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
89636 +
89637 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
89638 + must make sure that the marks are the same if a binary has both marks.
89639 +
89640 + If you enable none of the marking options then all applications
89641 + will run with PaX enabled on them by default.
89642 +
89643 +config PAX_XATTR_PAX_FLAGS
89644 + bool 'Use filesystem extended attributes marking'
89645 + default y if GRKERNSEC_CONFIG_AUTO
89646 + select CIFS_XATTR if CIFS
89647 + select EXT2_FS_XATTR if EXT2_FS
89648 + select EXT3_FS_XATTR if EXT3_FS
89649 + select EXT4_FS_XATTR if EXT4_FS
89650 + select JFFS2_FS_XATTR if JFFS2_FS
89651 + select REISERFS_FS_XATTR if REISERFS_FS
89652 + select SQUASHFS_XATTR if SQUASHFS
89653 + select TMPFS_XATTR if TMPFS
89654 + select UBIFS_FS_XATTR if UBIFS_FS
89655 + help
89656 + Enabling this option will allow you to control PaX features on
89657 + a per executable basis via the 'setfattr' utility. The control
89658 + flags will be read from the user.pax.flags extended attribute of
89659 + the file. This marking has the benefit of supporting binary-only
89660 + applications that self-check themselves (e.g., skype) and would
89661 + not tolerate chpax/paxctl changes. The main drawback is that
89662 + extended attributes are not supported by some filesystems (e.g.,
89663 + isofs, udf, vfat) so copying files through such filesystems will
89664 + lose the extended attributes and these PaX markings.
89665 +
89666 + Note that if you enable the legacy EI_PAX marking support as well,
89667 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
89668 +
89669 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
89670 + must make sure that the marks are the same if a binary has both marks.
89671 +
89672 + If you enable none of the marking options then all applications
89673 + will run with PaX enabled on them by default.
89674 +
89675 +choice
89676 + prompt 'MAC system integration'
89677 + default PAX_HAVE_ACL_FLAGS
89678 + help
89679 + Mandatory Access Control systems have the option of controlling
89680 + PaX flags on a per executable basis, choose the method supported
89681 + by your particular system.
89682 +
89683 + - "none": if your MAC system does not interact with PaX,
89684 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
89685 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
89686 +
89687 + NOTE: this option is for developers/integrators only.
89688 +
89689 + config PAX_NO_ACL_FLAGS
89690 + bool 'none'
89691 +
89692 + config PAX_HAVE_ACL_FLAGS
89693 + bool 'direct'
89694 +
89695 + config PAX_HOOK_ACL_FLAGS
89696 + bool 'hook'
89697 +endchoice
89698 +
89699 +endmenu
89700 +
89701 +menu "Non-executable pages"
89702 + depends on PAX
89703 +
89704 +config PAX_NOEXEC
89705 + bool "Enforce non-executable pages"
89706 + default y if GRKERNSEC_CONFIG_AUTO
89707 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
89708 + help
89709 + By design some architectures do not allow for protecting memory
89710 + pages against execution or even if they do, Linux does not make
89711 + use of this feature. In practice this means that if a page is
89712 + readable (such as the stack or heap) it is also executable.
89713 +
89714 + There is a well known exploit technique that makes use of this
89715 + fact and a common programming mistake where an attacker can
89716 + introduce code of his choice somewhere in the attacked program's
89717 + memory (typically the stack or the heap) and then execute it.
89718 +
89719 + If the attacked program was running with different (typically
89720 + higher) privileges than that of the attacker, then he can elevate
89721 + his own privilege level (e.g. get a root shell, write to files for
89722 + which he does not have write access to, etc).
89723 +
89724 + Enabling this option will let you choose from various features
89725 + that prevent the injection and execution of 'foreign' code in
89726 + a program.
89727 +
89728 + This will also break programs that rely on the old behaviour and
89729 + expect that dynamically allocated memory via the malloc() family
89730 + of functions is executable (which it is not). Notable examples
89731 + are the XFree86 4.x server, the java runtime and wine.
89732 +
89733 +config PAX_PAGEEXEC
89734 + bool "Paging based non-executable pages"
89735 + default y if GRKERNSEC_CONFIG_AUTO
89736 + 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)
89737 + select S390_SWITCH_AMODE if S390
89738 + select S390_EXEC_PROTECT if S390
89739 + select ARCH_TRACK_EXEC_LIMIT if X86_32
89740 + help
89741 + This implementation is based on the paging feature of the CPU.
89742 + On i386 without hardware non-executable bit support there is a
89743 + variable but usually low performance impact, however on Intel's
89744 + P4 core based CPUs it is very high so you should not enable this
89745 + for kernels meant to be used on such CPUs.
89746 +
89747 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
89748 + with hardware non-executable bit support there is no performance
89749 + impact, on ppc the impact is negligible.
89750 +
89751 + Note that several architectures require various emulations due to
89752 + badly designed userland ABIs, this will cause a performance impact
89753 + but will disappear as soon as userland is fixed. For example, ppc
89754 + userland MUST have been built with secure-plt by a recent toolchain.
89755 +
89756 +config PAX_SEGMEXEC
89757 + bool "Segmentation based non-executable pages"
89758 + default y if GRKERNSEC_CONFIG_AUTO
89759 + depends on PAX_NOEXEC && X86_32
89760 + help
89761 + This implementation is based on the segmentation feature of the
89762 + CPU and has a very small performance impact, however applications
89763 + will be limited to a 1.5 GB address space instead of the normal
89764 + 3 GB.
89765 +
89766 +config PAX_EMUTRAMP
89767 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
89768 + default y if PARISC
89769 + help
89770 + There are some programs and libraries that for one reason or
89771 + another attempt to execute special small code snippets from
89772 + non-executable memory pages. Most notable examples are the
89773 + signal handler return code generated by the kernel itself and
89774 + the GCC trampolines.
89775 +
89776 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
89777 + such programs will no longer work under your kernel.
89778 +
89779 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
89780 + utilities to enable trampoline emulation for the affected programs
89781 + yet still have the protection provided by the non-executable pages.
89782 +
89783 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
89784 + your system will not even boot.
89785 +
89786 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
89787 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
89788 + for the affected files.
89789 +
89790 + NOTE: enabling this feature *may* open up a loophole in the
89791 + protection provided by non-executable pages that an attacker
89792 + could abuse. Therefore the best solution is to not have any
89793 + files on your system that would require this option. This can
89794 + be achieved by not using libc5 (which relies on the kernel
89795 + signal handler return code) and not using or rewriting programs
89796 + that make use of the nested function implementation of GCC.
89797 + Skilled users can just fix GCC itself so that it implements
89798 + nested function calls in a way that does not interfere with PaX.
89799 +
89800 +config PAX_EMUSIGRT
89801 + bool "Automatically emulate sigreturn trampolines"
89802 + depends on PAX_EMUTRAMP && PARISC
89803 + default y
89804 + help
89805 + Enabling this option will have the kernel automatically detect
89806 + and emulate signal return trampolines executing on the stack
89807 + that would otherwise lead to task termination.
89808 +
89809 + This solution is intended as a temporary one for users with
89810 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
89811 + Modula-3 runtime, etc) or executables linked to such, basically
89812 + everything that does not specify its own SA_RESTORER function in
89813 + normal executable memory like glibc 2.1+ does.
89814 +
89815 + On parisc you MUST enable this option, otherwise your system will
89816 + not even boot.
89817 +
89818 + NOTE: this feature cannot be disabled on a per executable basis
89819 + and since it *does* open up a loophole in the protection provided
89820 + by non-executable pages, the best solution is to not have any
89821 + files on your system that would require this option.
89822 +
89823 +config PAX_MPROTECT
89824 + bool "Restrict mprotect()"
89825 + default y if GRKERNSEC_CONFIG_AUTO
89826 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
89827 + help
89828 + Enabling this option will prevent programs from
89829 + - changing the executable status of memory pages that were
89830 + not originally created as executable,
89831 + - making read-only executable pages writable again,
89832 + - creating executable pages from anonymous memory,
89833 + - making read-only-after-relocations (RELRO) data pages writable again.
89834 +
89835 + You should say Y here to complete the protection provided by
89836 + the enforcement of non-executable pages.
89837 +
89838 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
89839 + this feature on a per file basis.
89840 +
89841 +config PAX_MPROTECT_COMPAT
89842 + bool "Use legacy/compat protection demoting (read help)"
89843 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
89844 + depends on PAX_MPROTECT
89845 + help
89846 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
89847 + by sending the proper error code to the application. For some broken
89848 + userland, this can cause problems with Python or other applications. The
89849 + current implementation however allows for applications like clamav to
89850 + detect if JIT compilation/execution is allowed and to fall back gracefully
89851 + to an interpreter-based mode if it does not. While we encourage everyone
89852 + to use the current implementation as-is and push upstream to fix broken
89853 + userland (note that the RWX logging option can assist with this), in some
89854 + environments this may not be possible. Having to disable MPROTECT
89855 + completely on certain binaries reduces the security benefit of PaX,
89856 + so this option is provided for those environments to revert to the old
89857 + behavior.
89858 +
89859 +config PAX_ELFRELOCS
89860 + bool "Allow ELF text relocations (read help)"
89861 + depends on PAX_MPROTECT
89862 + default n
89863 + help
89864 + Non-executable pages and mprotect() restrictions are effective
89865 + in preventing the introduction of new executable code into an
89866 + attacked task's address space. There remain only two venues
89867 + for this kind of attack: if the attacker can execute already
89868 + existing code in the attacked task then he can either have it
89869 + create and mmap() a file containing his code or have it mmap()
89870 + an already existing ELF library that does not have position
89871 + independent code in it and use mprotect() on it to make it
89872 + writable and copy his code there. While protecting against
89873 + the former approach is beyond PaX, the latter can be prevented
89874 + by having only PIC ELF libraries on one's system (which do not
89875 + need to relocate their code). If you are sure this is your case,
89876 + as is the case with all modern Linux distributions, then leave
89877 + this option disabled. You should say 'n' here.
89878 +
89879 +config PAX_ETEXECRELOCS
89880 + bool "Allow ELF ET_EXEC text relocations"
89881 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
89882 + select PAX_ELFRELOCS
89883 + default y
89884 + help
89885 + On some architectures there are incorrectly created applications
89886 + that require text relocations and would not work without enabling
89887 + this option. If you are an alpha, ia64 or parisc user, you should
89888 + enable this option and disable it once you have made sure that
89889 + none of your applications need it.
89890 +
89891 +config PAX_EMUPLT
89892 + bool "Automatically emulate ELF PLT"
89893 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
89894 + default y
89895 + help
89896 + Enabling this option will have the kernel automatically detect
89897 + and emulate the Procedure Linkage Table entries in ELF files.
89898 + On some architectures such entries are in writable memory, and
89899 + become non-executable leading to task termination. Therefore
89900 + it is mandatory that you enable this option on alpha, parisc,
89901 + sparc and sparc64, otherwise your system would not even boot.
89902 +
89903 + NOTE: this feature *does* open up a loophole in the protection
89904 + provided by the non-executable pages, therefore the proper
89905 + solution is to modify the toolchain to produce a PLT that does
89906 + not need to be writable.
89907 +
89908 +config PAX_DLRESOLVE
89909 + bool 'Emulate old glibc resolver stub'
89910 + depends on PAX_EMUPLT && SPARC
89911 + default n
89912 + help
89913 + This option is needed if userland has an old glibc (before 2.4)
89914 + that puts a 'save' instruction into the runtime generated resolver
89915 + stub that needs special emulation.
89916 +
89917 +config PAX_KERNEXEC
89918 + bool "Enforce non-executable kernel pages"
89919 + 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))
89920 + depends on ((X86 && (!X86_32 || X86_WP_WORKS_OK)) || (ARM && (CPU_V6 || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
89921 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
89922 + select PAX_KERNEXEC_PLUGIN if X86_64
89923 + help
89924 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
89925 + that is, enabling this option will make it harder to inject
89926 + and execute 'foreign' code in kernel memory itself.
89927 +
89928 +choice
89929 + prompt "Return Address Instrumentation Method"
89930 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
89931 + depends on PAX_KERNEXEC_PLUGIN
89932 + help
89933 + Select the method used to instrument function pointer dereferences.
89934 + Note that binary modules cannot be instrumented by this approach.
89935 +
89936 + Note that the implementation requires a gcc with plugin support,
89937 + i.e., gcc 4.5 or newer. You may need to install the supporting
89938 + headers explicitly in addition to the normal gcc package.
89939 +
89940 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
89941 + bool "bts"
89942 + help
89943 + This method is compatible with binary only modules but has
89944 + a higher runtime overhead.
89945 +
89946 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
89947 + bool "or"
89948 + depends on !PARAVIRT
89949 + help
89950 + This method is incompatible with binary only modules but has
89951 + a lower runtime overhead.
89952 +endchoice
89953 +
89954 +config PAX_KERNEXEC_PLUGIN_METHOD
89955 + string
89956 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
89957 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
89958 + default ""
89959 +
89960 +config PAX_KERNEXEC_MODULE_TEXT
89961 + int "Minimum amount of memory reserved for module code"
89962 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
89963 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
89964 + depends on PAX_KERNEXEC && X86_32 && MODULES
89965 + help
89966 + Due to implementation details the kernel must reserve a fixed
89967 + amount of memory for module code at compile time that cannot be
89968 + changed at runtime. Here you can specify the minimum amount
89969 + in MB that will be reserved. Due to the same implementation
89970 + details this size will always be rounded up to the next 2/4 MB
89971 + boundary (depends on PAE) so the actually available memory for
89972 + module code will usually be more than this minimum.
89973 +
89974 + The default 4 MB should be enough for most users but if you have
89975 + an excessive number of modules (e.g., most distribution configs
89976 + compile many drivers as modules) or use huge modules such as
89977 + nvidia's kernel driver, you will need to adjust this amount.
89978 + A good rule of thumb is to look at your currently loaded kernel
89979 + modules and add up their sizes.
89980 +
89981 +endmenu
89982 +
89983 +menu "Address Space Layout Randomization"
89984 + depends on PAX
89985 +
89986 +config PAX_ASLR
89987 + bool "Address Space Layout Randomization"
89988 + default y if GRKERNSEC_CONFIG_AUTO
89989 + help
89990 + Many if not most exploit techniques rely on the knowledge of
89991 + certain addresses in the attacked program. The following options
89992 + will allow the kernel to apply a certain amount of randomization
89993 + to specific parts of the program thereby forcing an attacker to
89994 + guess them in most cases. Any failed guess will most likely crash
89995 + the attacked program which allows the kernel to detect such attempts
89996 + and react on them. PaX itself provides no reaction mechanisms,
89997 + instead it is strongly encouraged that you make use of Nergal's
89998 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
89999 + (http://www.grsecurity.net/) built-in crash detection features or
90000 + develop one yourself.
90001 +
90002 + By saying Y here you can choose to randomize the following areas:
90003 + - top of the task's kernel stack
90004 + - top of the task's userland stack
90005 + - base address for mmap() requests that do not specify one
90006 + (this includes all libraries)
90007 + - base address of the main executable
90008 +
90009 + It is strongly recommended to say Y here as address space layout
90010 + randomization has negligible impact on performance yet it provides
90011 + a very effective protection.
90012 +
90013 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
90014 + this feature on a per file basis.
90015 +
90016 +config PAX_RANDKSTACK
90017 + bool "Randomize kernel stack base"
90018 + default y if GRKERNSEC_CONFIG_AUTO
90019 + depends on X86_TSC && X86
90020 + help
90021 + By saying Y here the kernel will randomize every task's kernel
90022 + stack on every system call. This will not only force an attacker
90023 + to guess it but also prevent him from making use of possible
90024 + leaked information about it.
90025 +
90026 + Since the kernel stack is a rather scarce resource, randomization
90027 + may cause unexpected stack overflows, therefore you should very
90028 + carefully test your system. Note that once enabled in the kernel
90029 + configuration, this feature cannot be disabled on a per file basis.
90030 +
90031 +config PAX_RANDUSTACK
90032 + bool "Randomize user stack base"
90033 + default y if GRKERNSEC_CONFIG_AUTO
90034 + depends on PAX_ASLR
90035 + help
90036 + By saying Y here the kernel will randomize every task's userland
90037 + stack. The randomization is done in two steps where the second
90038 + one may apply a big amount of shift to the top of the stack and
90039 + cause problems for programs that want to use lots of memory (more
90040 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
90041 + For this reason the second step can be controlled by 'chpax' or
90042 + 'paxctl' on a per file basis.
90043 +
90044 +config PAX_RANDMMAP
90045 + bool "Randomize mmap() base"
90046 + default y if GRKERNSEC_CONFIG_AUTO
90047 + depends on PAX_ASLR
90048 + help
90049 + By saying Y here the kernel will use a randomized base address for
90050 + mmap() requests that do not specify one themselves. As a result
90051 + all dynamically loaded libraries will appear at random addresses
90052 + and therefore be harder to exploit by a technique where an attacker
90053 + attempts to execute library code for his purposes (e.g. spawn a
90054 + shell from an exploited program that is running at an elevated
90055 + privilege level).
90056 +
90057 + Furthermore, if a program is relinked as a dynamic ELF file, its
90058 + base address will be randomized as well, completing the full
90059 + randomization of the address space layout. Attacking such programs
90060 + becomes a guess game. You can find an example of doing this at
90061 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
90062 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
90063 +
90064 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
90065 + feature on a per file basis.
90066 +
90067 +endmenu
90068 +
90069 +menu "Miscellaneous hardening features"
90070 +
90071 +config PAX_MEMORY_SANITIZE
90072 + bool "Sanitize all freed memory"
90073 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
90074 + depends on !HIBERNATION
90075 + help
90076 + By saying Y here the kernel will erase memory pages as soon as they
90077 + are freed. This in turn reduces the lifetime of data stored in the
90078 + pages, making it less likely that sensitive information such as
90079 + passwords, cryptographic secrets, etc stay in memory for too long.
90080 +
90081 + This is especially useful for programs whose runtime is short, long
90082 + lived processes and the kernel itself benefit from this as long as
90083 + they operate on whole memory pages and ensure timely freeing of pages
90084 + that may hold sensitive information.
90085 +
90086 + The tradeoff is performance impact, on a single CPU system kernel
90087 + compilation sees a 3% slowdown, other systems and workloads may vary
90088 + and you are advised to test this feature on your expected workload
90089 + before deploying it.
90090 +
90091 + Note that this feature does not protect data stored in live pages,
90092 + e.g., process memory swapped to disk may stay there for a long time.
90093 +
90094 +config PAX_MEMORY_STACKLEAK
90095 + bool "Sanitize kernel stack"
90096 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
90097 + depends on X86
90098 + help
90099 + By saying Y here the kernel will erase the kernel stack before it
90100 + returns from a system call. This in turn reduces the information
90101 + that a kernel stack leak bug can reveal.
90102 +
90103 + Note that such a bug can still leak information that was put on
90104 + the stack by the current system call (the one eventually triggering
90105 + the bug) but traces of earlier system calls on the kernel stack
90106 + cannot leak anymore.
90107 +
90108 + The tradeoff is performance impact: on a single CPU system kernel
90109 + compilation sees a 1% slowdown, other systems and workloads may vary
90110 + and you are advised to test this feature on your expected workload
90111 + before deploying it.
90112 +
90113 + Note that the full feature requires a gcc with plugin support,
90114 + i.e., gcc 4.5 or newer. You may need to install the supporting
90115 + headers explicitly in addition to the normal gcc package. Using
90116 + older gcc versions means that functions with large enough stack
90117 + frames may leave uninitialized memory behind that may be exposed
90118 + to a later syscall leaking the stack.
90119 +
90120 +config PAX_MEMORY_UDEREF
90121 + bool "Prevent invalid userland pointer dereference"
90122 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
90123 + depends on (X86 || (ARM && (CPU_V6 || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
90124 + select PAX_PER_CPU_PGD if X86_64
90125 + help
90126 + By saying Y here the kernel will be prevented from dereferencing
90127 + userland pointers in contexts where the kernel expects only kernel
90128 + pointers. This is both a useful runtime debugging feature and a
90129 + security measure that prevents exploiting a class of kernel bugs.
90130 +
90131 + The tradeoff is that some virtualization solutions may experience
90132 + a huge slowdown and therefore you should not enable this feature
90133 + for kernels meant to run in such environments. Whether a given VM
90134 + solution is affected or not is best determined by simply trying it
90135 + out, the performance impact will be obvious right on boot as this
90136 + mechanism engages from very early on. A good rule of thumb is that
90137 + VMs running on CPUs without hardware virtualization support (i.e.,
90138 + the majority of IA-32 CPUs) will likely experience the slowdown.
90139 +
90140 +config PAX_REFCOUNT
90141 + bool "Prevent various kernel object reference counter overflows"
90142 + default y if GRKERNSEC_CONFIG_AUTO
90143 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
90144 + help
90145 + By saying Y here the kernel will detect and prevent overflowing
90146 + various (but not all) kinds of object reference counters. Such
90147 + overflows can normally occur due to bugs only and are often, if
90148 + not always, exploitable.
90149 +
90150 + The tradeoff is that data structures protected by an overflowed
90151 + refcount will never be freed and therefore will leak memory. Note
90152 + that this leak also happens even without this protection but in
90153 + that case the overflow can eventually trigger the freeing of the
90154 + data structure while it is still being used elsewhere, resulting
90155 + in the exploitable situation that this feature prevents.
90156 +
90157 + Since this has a negligible performance impact, you should enable
90158 + this feature.
90159 +
90160 +config PAX_CONSTIFY_PLUGIN
90161 + bool "Automatically constify eligible structures"
90162 + default y
90163 + depends on !UML
90164 + help
90165 + By saying Y here the compiler will automatically constify a class
90166 + of types that contain only function pointers. This reduces the
90167 + kernel's attack surface and also produces a better memory layout.
90168 +
90169 + Note that the implementation requires a gcc with plugin support,
90170 + i.e., gcc 4.5 or newer. You may need to install the supporting
90171 + headers explicitly in addition to the normal gcc package.
90172 +
90173 + Note that if some code really has to modify constified variables
90174 + then the source code will have to be patched to allow it. Examples
90175 + can be found in PaX itself (the no_const attribute) and for some
90176 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
90177 +
90178 +config PAX_USERCOPY
90179 + bool "Harden heap object copies between kernel and userland"
90180 + default y if GRKERNSEC_CONFIG_AUTO
90181 + depends on ARM || IA64 || PPC || SPARC || X86
90182 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
90183 + select PAX_USERCOPY_SLABS
90184 + help
90185 + By saying Y here the kernel will enforce the size of heap objects
90186 + when they are copied in either direction between the kernel and
90187 + userland, even if only a part of the heap object is copied.
90188 +
90189 + Specifically, this checking prevents information leaking from the
90190 + kernel heap during kernel to userland copies (if the kernel heap
90191 + object is otherwise fully initialized) and prevents kernel heap
90192 + overflows during userland to kernel copies.
90193 +
90194 + Note that the current implementation provides the strictest bounds
90195 + checks for the SLUB allocator.
90196 +
90197 + Enabling this option also enables per-slab cache protection against
90198 + data in a given cache being copied into/out of via userland
90199 + accessors. Though the whitelist of regions will be reduced over
90200 + time, it notably protects important data structures like task structs.
90201 +
90202 + If frame pointers are enabled on x86, this option will also restrict
90203 + copies into and out of the kernel stack to local variables within a
90204 + single frame.
90205 +
90206 + Since this has a negligible performance impact, you should enable
90207 + this feature.
90208 +
90209 +
90210 +config PAX_USERCOPY_DEBUG
90211 + bool
90212 + depends on X86 && PAX_USERCOPY
90213 + default n
90214 +
90215 +config PAX_SIZE_OVERFLOW
90216 + bool "Prevent various integer overflows in function size parameters"
90217 + default y if GRKERNSEC_CONFIG_AUTO
90218 + depends on X86
90219 + help
90220 + By saying Y here the kernel recomputes expressions of function
90221 + arguments marked by a size_overflow attribute with double integer
90222 + precision (DImode/TImode for 32/64 bit integer types).
90223 +
90224 + The recomputed argument is checked against TYPE_MAX and an event
90225 + is logged on overflow and the triggering process is killed.
90226 +
90227 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
90228 +
90229 + Note that the implementation requires a gcc with plugin support,
90230 + i.e., gcc 4.5 or newer. You may need to install the supporting
90231 + headers explicitly in addition to the normal gcc package.
90232 +
90233 +config PAX_LATENT_ENTROPY
90234 + bool "Generate some entropy during boot"
90235 + default y if GRKERNSEC_CONFIG_AUTO
90236 + help
90237 + By saying Y here the kernel will instrument early boot code to
90238 + extract some entropy from both original and artificially created
90239 + program state. This will help especially embedded systems where
90240 + there is little 'natural' source of entropy normally. The cost
90241 + is some slowdown of the boot process.
90242 +
90243 + When pax_extra_latent_entropy is passed on the kernel command line,
90244 + entropy will be extracted from up to the first 4GB of RAM while the
90245 + runtime memory allocator is being initialized. This costs even more
90246 + slowdown of the boot process.
90247 +
90248 + Note that the implementation requires a gcc with plugin support,
90249 + i.e., gcc 4.5 or newer. You may need to install the supporting
90250 + headers explicitly in addition to the normal gcc package.
90251 +
90252 + Note that entropy extracted this way is not cryptographically
90253 + secure!
90254 +
90255 +endmenu
90256 +
90257 +endmenu
90258 +
90259 +source grsecurity/Kconfig
90260 +
90261 +endmenu
90262 +
90263 +endmenu
90264 +
90265 source security/keys/Kconfig
90266
90267 config SECURITY_DMESG_RESTRICT
90268 @@ -103,7 +1022,7 @@ config INTEL_TXT
90269 config LSM_MMAP_MIN_ADDR
90270 int "Low address space for LSM to protect from user allocation"
90271 depends on SECURITY && SECURITY_SELINUX
90272 - default 32768 if ARM
90273 + default 32768 if ALPHA || ARM || PARISC || SPARC32
90274 default 65536
90275 help
90276 This is the portion of low virtual memory which should be protected
90277 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
90278 index 8c2a7f6..b133ac9 100644
90279 --- a/security/apparmor/lsm.c
90280 +++ b/security/apparmor/lsm.c
90281 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
90282 return error;
90283 }
90284
90285 -static struct security_operations apparmor_ops = {
90286 +static struct security_operations apparmor_ops __read_only = {
90287 .name = "apparmor",
90288
90289 .ptrace_access_check = apparmor_ptrace_access_check,
90290 diff --git a/security/commoncap.c b/security/commoncap.c
90291 index 7ee08c7..8d1a9d6 100644
90292 --- a/security/commoncap.c
90293 +++ b/security/commoncap.c
90294 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
90295 return 0;
90296 }
90297
90298 +/* returns:
90299 + 1 for suid privilege
90300 + 2 for sgid privilege
90301 + 3 for fscap privilege
90302 +*/
90303 +int is_privileged_binary(const struct dentry *dentry)
90304 +{
90305 + struct cpu_vfs_cap_data capdata;
90306 + struct inode *inode = dentry->d_inode;
90307 +
90308 + if (!inode || S_ISDIR(inode->i_mode))
90309 + return 0;
90310 +
90311 + if (inode->i_mode & S_ISUID)
90312 + return 1;
90313 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
90314 + return 2;
90315 +
90316 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
90317 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
90318 + return 3;
90319 + }
90320 +
90321 + return 0;
90322 +}
90323 +
90324 /*
90325 * Attempt to get the on-exec apply capability sets for an executable file from
90326 * its xattrs and, if present, apply them to the proposed credentials being
90327 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
90328 const struct cred *cred = current_cred();
90329 kuid_t root_uid = make_kuid(cred->user_ns, 0);
90330
90331 + if (gr_acl_enable_at_secure())
90332 + return 1;
90333 +
90334 if (!uid_eq(cred->uid, root_uid)) {
90335 if (bprm->cap_effective)
90336 return 1;
90337 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
90338 index 079a85d..12e93f8 100644
90339 --- a/security/integrity/ima/ima.h
90340 +++ b/security/integrity/ima/ima.h
90341 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
90342 extern spinlock_t ima_queue_lock;
90343
90344 struct ima_h_table {
90345 - atomic_long_t len; /* number of stored measurements in the list */
90346 - atomic_long_t violations;
90347 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
90348 + atomic_long_unchecked_t violations;
90349 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
90350 };
90351 extern struct ima_h_table ima_htable;
90352 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
90353 index 0cea3db..2f0ef77 100644
90354 --- a/security/integrity/ima/ima_api.c
90355 +++ b/security/integrity/ima/ima_api.c
90356 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
90357 int result;
90358
90359 /* can overflow, only indicator */
90360 - atomic_long_inc(&ima_htable.violations);
90361 + atomic_long_inc_unchecked(&ima_htable.violations);
90362
90363 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
90364 if (!entry) {
90365 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
90366 index 38477c9..87a60c7 100644
90367 --- a/security/integrity/ima/ima_fs.c
90368 +++ b/security/integrity/ima/ima_fs.c
90369 @@ -28,12 +28,12 @@
90370 static int valid_policy = 1;
90371 #define TMPBUFLEN 12
90372 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
90373 - loff_t *ppos, atomic_long_t *val)
90374 + loff_t *ppos, atomic_long_unchecked_t *val)
90375 {
90376 char tmpbuf[TMPBUFLEN];
90377 ssize_t len;
90378
90379 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
90380 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
90381 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
90382 }
90383
90384 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
90385 index 55a6271..ad829c3 100644
90386 --- a/security/integrity/ima/ima_queue.c
90387 +++ b/security/integrity/ima/ima_queue.c
90388 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
90389 INIT_LIST_HEAD(&qe->later);
90390 list_add_tail_rcu(&qe->later, &ima_measurements);
90391
90392 - atomic_long_inc(&ima_htable.len);
90393 + atomic_long_inc_unchecked(&ima_htable.len);
90394 key = ima_hash_key(entry->digest);
90395 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
90396 return 0;
90397 diff --git a/security/keys/compat.c b/security/keys/compat.c
90398 index d65fa7f..cbfe366 100644
90399 --- a/security/keys/compat.c
90400 +++ b/security/keys/compat.c
90401 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
90402 if (ret == 0)
90403 goto no_payload_free;
90404
90405 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
90406 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
90407 err:
90408 if (iov != iovstack)
90409 kfree(iov);
90410 diff --git a/security/keys/key.c b/security/keys/key.c
90411 index 8fb7c7b..ba3610d 100644
90412 --- a/security/keys/key.c
90413 +++ b/security/keys/key.c
90414 @@ -284,7 +284,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
90415
90416 atomic_set(&key->usage, 1);
90417 init_rwsem(&key->sem);
90418 - lockdep_set_class(&key->sem, &type->lock_class);
90419 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
90420 key->type = type;
90421 key->user = user;
90422 key->quotalen = quotalen;
90423 @@ -1032,7 +1032,9 @@ int register_key_type(struct key_type *ktype)
90424 struct key_type *p;
90425 int ret;
90426
90427 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
90428 + pax_open_kernel();
90429 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
90430 + pax_close_kernel();
90431
90432 ret = -EEXIST;
90433 down_write(&key_types_sem);
90434 @@ -1044,7 +1046,7 @@ int register_key_type(struct key_type *ktype)
90435 }
90436
90437 /* store the type */
90438 - list_add(&ktype->link, &key_types_list);
90439 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
90440
90441 pr_notice("Key type %s registered\n", ktype->name);
90442 ret = 0;
90443 @@ -1066,7 +1068,7 @@ EXPORT_SYMBOL(register_key_type);
90444 void unregister_key_type(struct key_type *ktype)
90445 {
90446 down_write(&key_types_sem);
90447 - list_del_init(&ktype->link);
90448 + pax_list_del_init((struct list_head *)&ktype->link);
90449 downgrade_write(&key_types_sem);
90450 key_gc_keytype(ktype);
90451 pr_notice("Key type %s unregistered\n", ktype->name);
90452 @@ -1084,10 +1086,10 @@ void __init key_init(void)
90453 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
90454
90455 /* add the special key types */
90456 - list_add_tail(&key_type_keyring.link, &key_types_list);
90457 - list_add_tail(&key_type_dead.link, &key_types_list);
90458 - list_add_tail(&key_type_user.link, &key_types_list);
90459 - list_add_tail(&key_type_logon.link, &key_types_list);
90460 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
90461 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
90462 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
90463 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
90464
90465 /* record the root user tracking */
90466 rb_link_node(&root_key_user.node,
90467 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
90468 index 4b5c948..2054dc1 100644
90469 --- a/security/keys/keyctl.c
90470 +++ b/security/keys/keyctl.c
90471 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
90472 /*
90473 * Copy the iovec data from userspace
90474 */
90475 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
90476 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
90477 unsigned ioc)
90478 {
90479 for (; ioc > 0; ioc--) {
90480 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
90481 * If successful, 0 will be returned.
90482 */
90483 long keyctl_instantiate_key_common(key_serial_t id,
90484 - const struct iovec *payload_iov,
90485 + const struct iovec __user *payload_iov,
90486 unsigned ioc,
90487 size_t plen,
90488 key_serial_t ringid)
90489 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
90490 [0].iov_len = plen
90491 };
90492
90493 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
90494 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
90495 }
90496
90497 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
90498 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
90499 if (ret == 0)
90500 goto no_payload_free;
90501
90502 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
90503 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
90504 err:
90505 if (iov != iovstack)
90506 kfree(iov);
90507 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
90508 index 6ece7f2..ecdb55c 100644
90509 --- a/security/keys/keyring.c
90510 +++ b/security/keys/keyring.c
90511 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
90512 ret = -EFAULT;
90513
90514 for (loop = 0; loop < klist->nkeys; loop++) {
90515 + key_serial_t serial;
90516 key = rcu_deref_link_locked(klist, loop,
90517 keyring);
90518 + serial = key->serial;
90519
90520 tmp = sizeof(key_serial_t);
90521 if (tmp > buflen)
90522 tmp = buflen;
90523
90524 - if (copy_to_user(buffer,
90525 - &key->serial,
90526 - tmp) != 0)
90527 + if (copy_to_user(buffer, &serial, tmp))
90528 goto error;
90529
90530 buflen -= tmp;
90531 diff --git a/security/min_addr.c b/security/min_addr.c
90532 index f728728..6457a0c 100644
90533 --- a/security/min_addr.c
90534 +++ b/security/min_addr.c
90535 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
90536 */
90537 static void update_mmap_min_addr(void)
90538 {
90539 +#ifndef SPARC
90540 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
90541 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
90542 mmap_min_addr = dac_mmap_min_addr;
90543 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
90544 #else
90545 mmap_min_addr = dac_mmap_min_addr;
90546 #endif
90547 +#endif
90548 }
90549
90550 /*
90551 diff --git a/security/security.c b/security/security.c
90552 index 7b88c6a..1e3ea8f 100644
90553 --- a/security/security.c
90554 +++ b/security/security.c
90555 @@ -20,6 +20,7 @@
90556 #include <linux/ima.h>
90557 #include <linux/evm.h>
90558 #include <linux/fsnotify.h>
90559 +#include <linux/mm.h>
90560 #include <linux/mman.h>
90561 #include <linux/mount.h>
90562 #include <linux/personality.h>
90563 @@ -32,8 +33,8 @@
90564 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
90565 CONFIG_DEFAULT_SECURITY;
90566
90567 -static struct security_operations *security_ops;
90568 -static struct security_operations default_security_ops = {
90569 +static struct security_operations *security_ops __read_only;
90570 +static struct security_operations default_security_ops __read_only = {
90571 .name = "default",
90572 };
90573
90574 @@ -74,7 +75,9 @@ int __init security_init(void)
90575
90576 void reset_security_ops(void)
90577 {
90578 + pax_open_kernel();
90579 security_ops = &default_security_ops;
90580 + pax_close_kernel();
90581 }
90582
90583 /* Save user chosen LSM */
90584 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
90585 index ef26e96..642fb78 100644
90586 --- a/security/selinux/hooks.c
90587 +++ b/security/selinux/hooks.c
90588 @@ -95,8 +95,6 @@
90589
90590 #define NUM_SEL_MNT_OPTS 5
90591
90592 -extern struct security_operations *security_ops;
90593 -
90594 /* SECMARK reference count */
90595 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
90596
90597 @@ -5501,7 +5499,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
90598
90599 #endif
90600
90601 -static struct security_operations selinux_ops = {
90602 +static struct security_operations selinux_ops __read_only = {
90603 .name = "selinux",
90604
90605 .ptrace_access_check = selinux_ptrace_access_check,
90606 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
90607 index 65f67cb..3f141ef 100644
90608 --- a/security/selinux/include/xfrm.h
90609 +++ b/security/selinux/include/xfrm.h
90610 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
90611
90612 static inline void selinux_xfrm_notify_policyload(void)
90613 {
90614 - atomic_inc(&flow_cache_genid);
90615 + atomic_inc_unchecked(&flow_cache_genid);
90616 rt_genid_bump(&init_net);
90617 }
90618 #else
90619 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
90620 index 38be92c..21f49ee 100644
90621 --- a/security/smack/smack_lsm.c
90622 +++ b/security/smack/smack_lsm.c
90623 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
90624 return 0;
90625 }
90626
90627 -struct security_operations smack_ops = {
90628 +struct security_operations smack_ops __read_only = {
90629 .name = "smack",
90630
90631 .ptrace_access_check = smack_ptrace_access_check,
90632 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
90633 index 390c646..f2f8db3 100644
90634 --- a/security/tomoyo/mount.c
90635 +++ b/security/tomoyo/mount.c
90636 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
90637 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
90638 need_dev = -1; /* dev_name is a directory */
90639 } else {
90640 + if (!capable(CAP_SYS_ADMIN)) {
90641 + error = -EPERM;
90642 + goto out;
90643 + }
90644 fstype = get_fs_type(type);
90645 if (!fstype) {
90646 error = -ENODEV;
90647 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
90648 index a2ee362..5754f34 100644
90649 --- a/security/tomoyo/tomoyo.c
90650 +++ b/security/tomoyo/tomoyo.c
90651 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
90652 * tomoyo_security_ops is a "struct security_operations" which is used for
90653 * registering TOMOYO.
90654 */
90655 -static struct security_operations tomoyo_security_ops = {
90656 +static struct security_operations tomoyo_security_ops __read_only = {
90657 .name = "tomoyo",
90658 .cred_alloc_blank = tomoyo_cred_alloc_blank,
90659 .cred_prepare = tomoyo_cred_prepare,
90660 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
90661 index 20ef514..4182bed 100644
90662 --- a/security/yama/Kconfig
90663 +++ b/security/yama/Kconfig
90664 @@ -1,6 +1,6 @@
90665 config SECURITY_YAMA
90666 bool "Yama support"
90667 - depends on SECURITY
90668 + depends on SECURITY && !GRKERNSEC
90669 select SECURITYFS
90670 select SECURITY_PATH
90671 default n
90672 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
90673 index 23414b9..b92b314 100644
90674 --- a/security/yama/yama_lsm.c
90675 +++ b/security/yama/yama_lsm.c
90676 @@ -367,7 +367,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
90677 }
90678
90679 #ifndef CONFIG_SECURITY_YAMA_STACKED
90680 -static struct security_operations yama_ops = {
90681 +static struct security_operations yama_ops __read_only = {
90682 .name = "yama",
90683
90684 .ptrace_access_check = yama_ptrace_access_check,
90685 @@ -378,28 +378,24 @@ static struct security_operations yama_ops = {
90686 #endif
90687
90688 #ifdef CONFIG_SYSCTL
90689 +static int zero __read_only;
90690 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
90691 +
90692 static int yama_dointvec_minmax(struct ctl_table *table, int write,
90693 void __user *buffer, size_t *lenp, loff_t *ppos)
90694 {
90695 - int rc;
90696 + ctl_table_no_const yama_table;
90697
90698 if (write && !capable(CAP_SYS_PTRACE))
90699 return -EPERM;
90700
90701 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90702 - if (rc)
90703 - return rc;
90704 -
90705 + yama_table = *table;
90706 /* Lock the max value if it ever gets set. */
90707 - if (write && *(int *)table->data == *(int *)table->extra2)
90708 - table->extra1 = table->extra2;
90709 -
90710 - return rc;
90711 + if (ptrace_scope == max_scope)
90712 + yama_table.extra1 = &max_scope;
90713 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
90714 }
90715
90716 -static int zero;
90717 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
90718 -
90719 struct ctl_path yama_sysctl_path[] = {
90720 { .procname = "kernel", },
90721 { .procname = "yama", },
90722 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
90723 index 4cedc69..e59d8a3 100644
90724 --- a/sound/aoa/codecs/onyx.c
90725 +++ b/sound/aoa/codecs/onyx.c
90726 @@ -54,7 +54,7 @@ struct onyx {
90727 spdif_locked:1,
90728 analog_locked:1,
90729 original_mute:2;
90730 - int open_count;
90731 + local_t open_count;
90732 struct codec_info *codec_info;
90733
90734 /* mutex serializes concurrent access to the device
90735 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
90736 struct onyx *onyx = cii->codec_data;
90737
90738 mutex_lock(&onyx->mutex);
90739 - onyx->open_count++;
90740 + local_inc(&onyx->open_count);
90741 mutex_unlock(&onyx->mutex);
90742
90743 return 0;
90744 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
90745 struct onyx *onyx = cii->codec_data;
90746
90747 mutex_lock(&onyx->mutex);
90748 - onyx->open_count--;
90749 - if (!onyx->open_count)
90750 + if (local_dec_and_test(&onyx->open_count))
90751 onyx->spdif_locked = onyx->analog_locked = 0;
90752 mutex_unlock(&onyx->mutex);
90753
90754 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
90755 index ffd2025..df062c9 100644
90756 --- a/sound/aoa/codecs/onyx.h
90757 +++ b/sound/aoa/codecs/onyx.h
90758 @@ -11,6 +11,7 @@
90759 #include <linux/i2c.h>
90760 #include <asm/pmac_low_i2c.h>
90761 #include <asm/prom.h>
90762 +#include <asm/local.h>
90763
90764 /* PCM3052 register definitions */
90765
90766 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
90767 index 4c1cc51..16040040 100644
90768 --- a/sound/core/oss/pcm_oss.c
90769 +++ b/sound/core/oss/pcm_oss.c
90770 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
90771 if (in_kernel) {
90772 mm_segment_t fs;
90773 fs = snd_enter_user();
90774 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
90775 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
90776 snd_leave_user(fs);
90777 } else {
90778 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
90779 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
90780 }
90781 if (ret != -EPIPE && ret != -ESTRPIPE)
90782 break;
90783 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
90784 if (in_kernel) {
90785 mm_segment_t fs;
90786 fs = snd_enter_user();
90787 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
90788 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
90789 snd_leave_user(fs);
90790 } else {
90791 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
90792 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
90793 }
90794 if (ret == -EPIPE) {
90795 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
90796 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
90797 struct snd_pcm_plugin_channel *channels;
90798 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
90799 if (!in_kernel) {
90800 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
90801 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
90802 return -EFAULT;
90803 buf = runtime->oss.buffer;
90804 }
90805 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
90806 }
90807 } else {
90808 tmp = snd_pcm_oss_write2(substream,
90809 - (const char __force *)buf,
90810 + (const char __force_kernel *)buf,
90811 runtime->oss.period_bytes, 0);
90812 if (tmp <= 0)
90813 goto err;
90814 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
90815 struct snd_pcm_runtime *runtime = substream->runtime;
90816 snd_pcm_sframes_t frames, frames1;
90817 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
90818 - char __user *final_dst = (char __force __user *)buf;
90819 + char __user *final_dst = (char __force_user *)buf;
90820 if (runtime->oss.plugin_first) {
90821 struct snd_pcm_plugin_channel *channels;
90822 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
90823 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
90824 xfer += tmp;
90825 runtime->oss.buffer_used -= tmp;
90826 } else {
90827 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
90828 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
90829 runtime->oss.period_bytes, 0);
90830 if (tmp <= 0)
90831 goto err;
90832 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
90833 size1);
90834 size1 /= runtime->channels; /* frames */
90835 fs = snd_enter_user();
90836 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
90837 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
90838 snd_leave_user(fs);
90839 }
90840 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
90841 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
90842 index af49721..e85058e 100644
90843 --- a/sound/core/pcm_compat.c
90844 +++ b/sound/core/pcm_compat.c
90845 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
90846 int err;
90847
90848 fs = snd_enter_user();
90849 - err = snd_pcm_delay(substream, &delay);
90850 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
90851 snd_leave_user(fs);
90852 if (err < 0)
90853 return err;
90854 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
90855 index 09b4286..8620fac 100644
90856 --- a/sound/core/pcm_native.c
90857 +++ b/sound/core/pcm_native.c
90858 @@ -2806,11 +2806,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
90859 switch (substream->stream) {
90860 case SNDRV_PCM_STREAM_PLAYBACK:
90861 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
90862 - (void __user *)arg);
90863 + (void __force_user *)arg);
90864 break;
90865 case SNDRV_PCM_STREAM_CAPTURE:
90866 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
90867 - (void __user *)arg);
90868 + (void __force_user *)arg);
90869 break;
90870 default:
90871 result = -EINVAL;
90872 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
90873 index 040c60e..989a19a 100644
90874 --- a/sound/core/seq/seq_device.c
90875 +++ b/sound/core/seq/seq_device.c
90876 @@ -64,7 +64,7 @@ struct ops_list {
90877 int argsize; /* argument size */
90878
90879 /* operators */
90880 - struct snd_seq_dev_ops ops;
90881 + struct snd_seq_dev_ops *ops;
90882
90883 /* registered devices */
90884 struct list_head dev_list; /* list of devices */
90885 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
90886
90887 mutex_lock(&ops->reg_mutex);
90888 /* copy driver operators */
90889 - ops->ops = *entry;
90890 + ops->ops = entry;
90891 ops->driver |= DRIVER_LOADED;
90892 ops->argsize = argsize;
90893
90894 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
90895 dev->name, ops->id, ops->argsize, dev->argsize);
90896 return -EINVAL;
90897 }
90898 - if (ops->ops.init_device(dev) >= 0) {
90899 + if (ops->ops->init_device(dev) >= 0) {
90900 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
90901 ops->num_init_devices++;
90902 } else {
90903 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
90904 dev->name, ops->id, ops->argsize, dev->argsize);
90905 return -EINVAL;
90906 }
90907 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
90908 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
90909 dev->status = SNDRV_SEQ_DEVICE_FREE;
90910 dev->driver_data = NULL;
90911 ops->num_init_devices--;
90912 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
90913 index 4e0dd22..7a1f32c 100644
90914 --- a/sound/drivers/mts64.c
90915 +++ b/sound/drivers/mts64.c
90916 @@ -29,6 +29,7 @@
90917 #include <sound/initval.h>
90918 #include <sound/rawmidi.h>
90919 #include <sound/control.h>
90920 +#include <asm/local.h>
90921
90922 #define CARD_NAME "Miditerminal 4140"
90923 #define DRIVER_NAME "MTS64"
90924 @@ -67,7 +68,7 @@ struct mts64 {
90925 struct pardevice *pardev;
90926 int pardev_claimed;
90927
90928 - int open_count;
90929 + local_t open_count;
90930 int current_midi_output_port;
90931 int current_midi_input_port;
90932 u8 mode[MTS64_NUM_INPUT_PORTS];
90933 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
90934 {
90935 struct mts64 *mts = substream->rmidi->private_data;
90936
90937 - if (mts->open_count == 0) {
90938 + if (local_read(&mts->open_count) == 0) {
90939 /* We don't need a spinlock here, because this is just called
90940 if the device has not been opened before.
90941 So there aren't any IRQs from the device */
90942 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
90943
90944 msleep(50);
90945 }
90946 - ++(mts->open_count);
90947 + local_inc(&mts->open_count);
90948
90949 return 0;
90950 }
90951 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
90952 struct mts64 *mts = substream->rmidi->private_data;
90953 unsigned long flags;
90954
90955 - --(mts->open_count);
90956 - if (mts->open_count == 0) {
90957 + if (local_dec_return(&mts->open_count) == 0) {
90958 /* We need the spinlock_irqsave here because we can still
90959 have IRQs at this point */
90960 spin_lock_irqsave(&mts->lock, flags);
90961 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
90962
90963 msleep(500);
90964
90965 - } else if (mts->open_count < 0)
90966 - mts->open_count = 0;
90967 + } else if (local_read(&mts->open_count) < 0)
90968 + local_set(&mts->open_count, 0);
90969
90970 return 0;
90971 }
90972 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
90973 index b953fb4..1999c01 100644
90974 --- a/sound/drivers/opl4/opl4_lib.c
90975 +++ b/sound/drivers/opl4/opl4_lib.c
90976 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
90977 MODULE_DESCRIPTION("OPL4 driver");
90978 MODULE_LICENSE("GPL");
90979
90980 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
90981 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
90982 {
90983 int timeout = 10;
90984 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
90985 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
90986 index 991018d..8984740 100644
90987 --- a/sound/drivers/portman2x4.c
90988 +++ b/sound/drivers/portman2x4.c
90989 @@ -48,6 +48,7 @@
90990 #include <sound/initval.h>
90991 #include <sound/rawmidi.h>
90992 #include <sound/control.h>
90993 +#include <asm/local.h>
90994
90995 #define CARD_NAME "Portman 2x4"
90996 #define DRIVER_NAME "portman"
90997 @@ -85,7 +86,7 @@ struct portman {
90998 struct pardevice *pardev;
90999 int pardev_claimed;
91000
91001 - int open_count;
91002 + local_t open_count;
91003 int mode[PORTMAN_NUM_INPUT_PORTS];
91004 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
91005 };
91006 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
91007 index ea995af..f1bfa37 100644
91008 --- a/sound/firewire/amdtp.c
91009 +++ b/sound/firewire/amdtp.c
91010 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
91011 ptr = s->pcm_buffer_pointer + data_blocks;
91012 if (ptr >= pcm->runtime->buffer_size)
91013 ptr -= pcm->runtime->buffer_size;
91014 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
91015 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
91016
91017 s->pcm_period_pointer += data_blocks;
91018 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
91019 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
91020 */
91021 void amdtp_out_stream_update(struct amdtp_out_stream *s)
91022 {
91023 - ACCESS_ONCE(s->source_node_id_field) =
91024 + ACCESS_ONCE_RW(s->source_node_id_field) =
91025 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
91026 }
91027 EXPORT_SYMBOL(amdtp_out_stream_update);
91028 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
91029 index b680c5e..061b7a0 100644
91030 --- a/sound/firewire/amdtp.h
91031 +++ b/sound/firewire/amdtp.h
91032 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
91033 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
91034 struct snd_pcm_substream *pcm)
91035 {
91036 - ACCESS_ONCE(s->pcm) = pcm;
91037 + ACCESS_ONCE_RW(s->pcm) = pcm;
91038 }
91039
91040 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
91041 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
91042 index d428ffe..751ef78 100644
91043 --- a/sound/firewire/isight.c
91044 +++ b/sound/firewire/isight.c
91045 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
91046 ptr += count;
91047 if (ptr >= runtime->buffer_size)
91048 ptr -= runtime->buffer_size;
91049 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
91050 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
91051
91052 isight->period_counter += count;
91053 if (isight->period_counter >= runtime->period_size) {
91054 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
91055 if (err < 0)
91056 return err;
91057
91058 - ACCESS_ONCE(isight->pcm_active) = true;
91059 + ACCESS_ONCE_RW(isight->pcm_active) = true;
91060
91061 return 0;
91062 }
91063 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
91064 {
91065 struct isight *isight = substream->private_data;
91066
91067 - ACCESS_ONCE(isight->pcm_active) = false;
91068 + ACCESS_ONCE_RW(isight->pcm_active) = false;
91069
91070 mutex_lock(&isight->mutex);
91071 isight_stop_streaming(isight);
91072 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
91073
91074 switch (cmd) {
91075 case SNDRV_PCM_TRIGGER_START:
91076 - ACCESS_ONCE(isight->pcm_running) = true;
91077 + ACCESS_ONCE_RW(isight->pcm_running) = true;
91078 break;
91079 case SNDRV_PCM_TRIGGER_STOP:
91080 - ACCESS_ONCE(isight->pcm_running) = false;
91081 + ACCESS_ONCE_RW(isight->pcm_running) = false;
91082 break;
91083 default:
91084 return -EINVAL;
91085 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
91086 index 844a555..985ab83 100644
91087 --- a/sound/firewire/scs1x.c
91088 +++ b/sound/firewire/scs1x.c
91089 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
91090 {
91091 struct scs *scs = stream->rmidi->private_data;
91092
91093 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
91094 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
91095 if (up) {
91096 scs->output_idle = false;
91097 tasklet_schedule(&scs->tasklet);
91098 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
91099 {
91100 struct scs *scs = stream->rmidi->private_data;
91101
91102 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
91103 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
91104 }
91105
91106 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
91107 @@ -457,8 +457,8 @@ static int scs_remove(struct device *dev)
91108
91109 snd_card_disconnect(scs->card);
91110
91111 - ACCESS_ONCE(scs->output) = NULL;
91112 - ACCESS_ONCE(scs->input) = NULL;
91113 + ACCESS_ONCE_RW(scs->output) = NULL;
91114 + ACCESS_ONCE_RW(scs->input) = NULL;
91115
91116 wait_event(scs->idle_wait, scs->output_idle);
91117
91118 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
91119 index 048439a..3be9f6f 100644
91120 --- a/sound/oss/sb_audio.c
91121 +++ b/sound/oss/sb_audio.c
91122 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
91123 buf16 = (signed short *)(localbuf + localoffs);
91124 while (c)
91125 {
91126 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
91127 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
91128 if (copy_from_user(lbuf8,
91129 userbuf+useroffs + p,
91130 locallen))
91131 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
91132 index 7d8803a..559f8d0 100644
91133 --- a/sound/oss/swarm_cs4297a.c
91134 +++ b/sound/oss/swarm_cs4297a.c
91135 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
91136 {
91137 struct cs4297a_state *s;
91138 u32 pwr, id;
91139 - mm_segment_t fs;
91140 int rval;
91141 #ifndef CONFIG_BCM_CS4297A_CSWARM
91142 u64 cfg;
91143 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
91144 if (!rval) {
91145 char *sb1250_duart_present;
91146
91147 +#if 0
91148 + mm_segment_t fs;
91149 fs = get_fs();
91150 set_fs(KERNEL_DS);
91151 -#if 0
91152 val = SOUND_MASK_LINE;
91153 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
91154 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
91155 val = initvol[i].vol;
91156 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
91157 }
91158 + set_fs(fs);
91159 // cs4297a_write_ac97(s, 0x18, 0x0808);
91160 #else
91161 // cs4297a_write_ac97(s, 0x5e, 0x180);
91162 cs4297a_write_ac97(s, 0x02, 0x0808);
91163 cs4297a_write_ac97(s, 0x18, 0x0808);
91164 #endif
91165 - set_fs(fs);
91166
91167 list_add(&s->list, &cs4297a_devs);
91168
91169 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
91170 index 4631a23..001ae57 100644
91171 --- a/sound/pci/ymfpci/ymfpci.h
91172 +++ b/sound/pci/ymfpci/ymfpci.h
91173 @@ -358,7 +358,7 @@ struct snd_ymfpci {
91174 spinlock_t reg_lock;
91175 spinlock_t voice_lock;
91176 wait_queue_head_t interrupt_sleep;
91177 - atomic_t interrupt_sleep_count;
91178 + atomic_unchecked_t interrupt_sleep_count;
91179 struct snd_info_entry *proc_entry;
91180 const struct firmware *dsp_microcode;
91181 const struct firmware *controller_microcode;
91182 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
91183 index 22056c5..25d3244 100644
91184 --- a/sound/pci/ymfpci/ymfpci_main.c
91185 +++ b/sound/pci/ymfpci/ymfpci_main.c
91186 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
91187 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
91188 break;
91189 }
91190 - if (atomic_read(&chip->interrupt_sleep_count)) {
91191 - atomic_set(&chip->interrupt_sleep_count, 0);
91192 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
91193 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
91194 wake_up(&chip->interrupt_sleep);
91195 }
91196 __end:
91197 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
91198 continue;
91199 init_waitqueue_entry(&wait, current);
91200 add_wait_queue(&chip->interrupt_sleep, &wait);
91201 - atomic_inc(&chip->interrupt_sleep_count);
91202 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
91203 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
91204 remove_wait_queue(&chip->interrupt_sleep, &wait);
91205 }
91206 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
91207 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
91208 spin_unlock(&chip->reg_lock);
91209
91210 - if (atomic_read(&chip->interrupt_sleep_count)) {
91211 - atomic_set(&chip->interrupt_sleep_count, 0);
91212 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
91213 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
91214 wake_up(&chip->interrupt_sleep);
91215 }
91216 }
91217 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
91218 spin_lock_init(&chip->reg_lock);
91219 spin_lock_init(&chip->voice_lock);
91220 init_waitqueue_head(&chip->interrupt_sleep);
91221 - atomic_set(&chip->interrupt_sleep_count, 0);
91222 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
91223 chip->card = card;
91224 chip->pci = pci;
91225 chip->irq = -1;
91226 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
91227 new file mode 100644
91228 index 0000000..50f2f2f
91229 --- /dev/null
91230 +++ b/tools/gcc/.gitignore
91231 @@ -0,0 +1 @@
91232 +size_overflow_hash.h
91233 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
91234 new file mode 100644
91235 index 0000000..6920fb3
91236 --- /dev/null
91237 +++ b/tools/gcc/Makefile
91238 @@ -0,0 +1,43 @@
91239 +#CC := gcc
91240 +#PLUGIN_SOURCE_FILES := pax_plugin.c
91241 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
91242 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
91243 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
91244 +
91245 +ifeq ($(PLUGINCC),$(HOSTCC))
91246 +HOSTLIBS := hostlibs
91247 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu99 -ggdb
91248 +else
91249 +HOSTLIBS := hostcxxlibs
91250 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu++98 -ggdb -Wno-unused-parameter
91251 +endif
91252 +
91253 +$(HOSTLIBS)-y := constify_plugin.so
91254 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
91255 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
91256 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
91257 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
91258 +$(HOSTLIBS)-y += colorize_plugin.so
91259 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
91260 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
91261 +
91262 +always := $($(HOSTLIBS)-y)
91263 +
91264 +constify_plugin-objs := constify_plugin.o
91265 +stackleak_plugin-objs := stackleak_plugin.o
91266 +kallocstat_plugin-objs := kallocstat_plugin.o
91267 +kernexec_plugin-objs := kernexec_plugin.o
91268 +checker_plugin-objs := checker_plugin.o
91269 +colorize_plugin-objs := colorize_plugin.o
91270 +size_overflow_plugin-objs := size_overflow_plugin.o
91271 +latent_entropy_plugin-objs := latent_entropy_plugin.o
91272 +
91273 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
91274 +
91275 +quiet_cmd_build_size_overflow_hash = GENHASH $@
91276 + cmd_build_size_overflow_hash = \
91277 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
91278 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
91279 + $(call if_changed,build_size_overflow_hash)
91280 +
91281 +targets += size_overflow_hash.h
91282 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
91283 new file mode 100644
91284 index 0000000..d41b5af
91285 --- /dev/null
91286 +++ b/tools/gcc/checker_plugin.c
91287 @@ -0,0 +1,171 @@
91288 +/*
91289 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
91290 + * Licensed under the GPL v2
91291 + *
91292 + * Note: the choice of the license means that the compilation process is
91293 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
91294 + * but for the kernel it doesn't matter since it doesn't link against
91295 + * any of the gcc libraries
91296 + *
91297 + * gcc plugin to implement various sparse (source code checker) features
91298 + *
91299 + * TODO:
91300 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
91301 + *
91302 + * BUGS:
91303 + * - none known
91304 + */
91305 +#include "gcc-plugin.h"
91306 +#include "config.h"
91307 +#include "system.h"
91308 +#include "coretypes.h"
91309 +#include "tree.h"
91310 +#include "tree-pass.h"
91311 +#include "flags.h"
91312 +#include "intl.h"
91313 +#include "toplev.h"
91314 +#include "plugin.h"
91315 +//#include "expr.h" where are you...
91316 +#include "diagnostic.h"
91317 +#include "plugin-version.h"
91318 +#include "tm.h"
91319 +#include "function.h"
91320 +#include "basic-block.h"
91321 +#include "gimple.h"
91322 +#include "rtl.h"
91323 +#include "emit-rtl.h"
91324 +#include "tree-flow.h"
91325 +#include "target.h"
91326 +
91327 +extern void c_register_addr_space (const char *str, addr_space_t as);
91328 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
91329 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
91330 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
91331 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
91332 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
91333 +
91334 +extern void print_gimple_stmt(FILE *, gimple, int, int);
91335 +extern rtx emit_move_insn(rtx x, rtx y);
91336 +
91337 +int plugin_is_GPL_compatible;
91338 +
91339 +static struct plugin_info checker_plugin_info = {
91340 + .version = "201111150100",
91341 +};
91342 +
91343 +#define ADDR_SPACE_KERNEL 0
91344 +#define ADDR_SPACE_FORCE_KERNEL 1
91345 +#define ADDR_SPACE_USER 2
91346 +#define ADDR_SPACE_FORCE_USER 3
91347 +#define ADDR_SPACE_IOMEM 0
91348 +#define ADDR_SPACE_FORCE_IOMEM 0
91349 +#define ADDR_SPACE_PERCPU 0
91350 +#define ADDR_SPACE_FORCE_PERCPU 0
91351 +#define ADDR_SPACE_RCU 0
91352 +#define ADDR_SPACE_FORCE_RCU 0
91353 +
91354 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
91355 +{
91356 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
91357 +}
91358 +
91359 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
91360 +{
91361 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
91362 +}
91363 +
91364 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
91365 +{
91366 + return default_addr_space_valid_pointer_mode(mode, as);
91367 +}
91368 +
91369 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
91370 +{
91371 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
91372 +}
91373 +
91374 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
91375 +{
91376 + return default_addr_space_legitimize_address(x, oldx, mode, as);
91377 +}
91378 +
91379 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
91380 +{
91381 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
91382 + return true;
91383 +
91384 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
91385 + return true;
91386 +
91387 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
91388 + return true;
91389 +
91390 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
91391 + return true;
91392 +
91393 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
91394 + return true;
91395 +
91396 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
91397 + return true;
91398 +
91399 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
91400 + return true;
91401 +
91402 + return subset == superset;
91403 +}
91404 +
91405 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
91406 +{
91407 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
91408 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
91409 +
91410 + return op;
91411 +}
91412 +
91413 +static void register_checker_address_spaces(void *event_data, void *data)
91414 +{
91415 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
91416 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
91417 + c_register_addr_space("__user", ADDR_SPACE_USER);
91418 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
91419 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
91420 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
91421 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
91422 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
91423 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
91424 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
91425 +
91426 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
91427 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
91428 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
91429 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
91430 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
91431 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
91432 + targetm.addr_space.convert = checker_addr_space_convert;
91433 +}
91434 +
91435 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91436 +{
91437 + const char * const plugin_name = plugin_info->base_name;
91438 + const int argc = plugin_info->argc;
91439 + const struct plugin_argument * const argv = plugin_info->argv;
91440 + int i;
91441 +
91442 + if (!plugin_default_version_check(version, &gcc_version)) {
91443 + error(G_("incompatible gcc/plugin versions"));
91444 + return 1;
91445 + }
91446 +
91447 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
91448 +
91449 + for (i = 0; i < argc; ++i)
91450 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
91451 +
91452 + if (TARGET_64BIT == 0)
91453 + return 0;
91454 +
91455 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
91456 +
91457 + return 0;
91458 +}
91459 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
91460 new file mode 100644
91461 index 0000000..414fe5e
91462 --- /dev/null
91463 +++ b/tools/gcc/colorize_plugin.c
91464 @@ -0,0 +1,151 @@
91465 +/*
91466 + * Copyright 2012-2013 by PaX Team <pageexec@freemail.hu>
91467 + * Licensed under the GPL v2
91468 + *
91469 + * Note: the choice of the license means that the compilation process is
91470 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
91471 + * but for the kernel it doesn't matter since it doesn't link against
91472 + * any of the gcc libraries
91473 + *
91474 + * gcc plugin to colorize diagnostic output
91475 + *
91476 + */
91477 +
91478 +#include "gcc-plugin.h"
91479 +#include "config.h"
91480 +#include "system.h"
91481 +#include "coretypes.h"
91482 +#include "tree.h"
91483 +#include "tree-pass.h"
91484 +#include "flags.h"
91485 +#include "intl.h"
91486 +#include "toplev.h"
91487 +#include "plugin.h"
91488 +#include "diagnostic.h"
91489 +#include "plugin-version.h"
91490 +#include "tm.h"
91491 +
91492 +int plugin_is_GPL_compatible;
91493 +
91494 +static struct plugin_info colorize_plugin_info = {
91495 + .version = "201302112000",
91496 + .help = NULL,
91497 +};
91498 +
91499 +#define GREEN "\033[32m\033[2m"
91500 +#define LIGHTGREEN "\033[32m\033[1m"
91501 +#define YELLOW "\033[33m\033[2m"
91502 +#define LIGHTYELLOW "\033[33m\033[1m"
91503 +#define RED "\033[31m\033[2m"
91504 +#define LIGHTRED "\033[31m\033[1m"
91505 +#define BLUE "\033[34m\033[2m"
91506 +#define LIGHTBLUE "\033[34m\033[1m"
91507 +#define BRIGHT "\033[m\033[1m"
91508 +#define NORMAL "\033[m"
91509 +
91510 +static diagnostic_starter_fn old_starter;
91511 +static diagnostic_finalizer_fn old_finalizer;
91512 +
91513 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
91514 +{
91515 + const char *color;
91516 + char *newprefix;
91517 +
91518 + switch (diagnostic->kind) {
91519 + case DK_NOTE:
91520 + color = LIGHTBLUE;
91521 + break;
91522 +
91523 + case DK_PEDWARN:
91524 + case DK_WARNING:
91525 + color = LIGHTYELLOW;
91526 + break;
91527 +
91528 + case DK_ERROR:
91529 + case DK_FATAL:
91530 + case DK_ICE:
91531 + case DK_PERMERROR:
91532 + case DK_SORRY:
91533 + color = LIGHTRED;
91534 + break;
91535 +
91536 + default:
91537 + color = NORMAL;
91538 + }
91539 +
91540 + old_starter(context, diagnostic);
91541 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
91542 + return;
91543 + pp_destroy_prefix(context->printer);
91544 + pp_set_prefix(context->printer, newprefix);
91545 +}
91546 +
91547 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
91548 +{
91549 + old_finalizer(context, diagnostic);
91550 +}
91551 +
91552 +static void colorize_arm(void)
91553 +{
91554 + old_starter = diagnostic_starter(global_dc);
91555 + old_finalizer = diagnostic_finalizer(global_dc);
91556 +
91557 + diagnostic_starter(global_dc) = start_colorize;
91558 + diagnostic_finalizer(global_dc) = finalize_colorize;
91559 +}
91560 +
91561 +static unsigned int execute_colorize_rearm(void)
91562 +{
91563 + if (diagnostic_starter(global_dc) == start_colorize)
91564 + return 0;
91565 +
91566 + colorize_arm();
91567 + return 0;
91568 +}
91569 +
91570 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
91571 + .pass = {
91572 + .type = SIMPLE_IPA_PASS,
91573 + .name = "colorize_rearm",
91574 +#if BUILDING_GCC_VERSION >= 4008
91575 + .optinfo_flags = OPTGROUP_NONE,
91576 +#endif
91577 + .gate = NULL,
91578 + .execute = execute_colorize_rearm,
91579 + .sub = NULL,
91580 + .next = NULL,
91581 + .static_pass_number = 0,
91582 + .tv_id = TV_NONE,
91583 + .properties_required = 0,
91584 + .properties_provided = 0,
91585 + .properties_destroyed = 0,
91586 + .todo_flags_start = 0,
91587 + .todo_flags_finish = 0
91588 + }
91589 +};
91590 +
91591 +static void colorize_start_unit(void *gcc_data, void *user_data)
91592 +{
91593 + colorize_arm();
91594 +}
91595 +
91596 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91597 +{
91598 + const char * const plugin_name = plugin_info->base_name;
91599 + struct register_pass_info colorize_rearm_pass_info = {
91600 + .pass = &pass_ipa_colorize_rearm.pass,
91601 + .reference_pass_name = "*free_lang_data",
91602 + .ref_pass_instance_number = 1,
91603 + .pos_op = PASS_POS_INSERT_AFTER
91604 + };
91605 +
91606 + if (!plugin_default_version_check(version, &gcc_version)) {
91607 + error(G_("incompatible gcc/plugin versions"));
91608 + return 1;
91609 + }
91610 +
91611 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
91612 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
91613 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
91614 + return 0;
91615 +}
91616 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
91617 new file mode 100644
91618 index 0000000..43e86d6
91619 --- /dev/null
91620 +++ b/tools/gcc/constify_plugin.c
91621 @@ -0,0 +1,512 @@
91622 +/*
91623 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
91624 + * Copyright 2011-2013 by PaX Team <pageexec@freemail.hu>
91625 + * Licensed under the GPL v2, or (at your option) v3
91626 + *
91627 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
91628 + *
91629 + * Homepage:
91630 + * http://www.grsecurity.net/~ephox/const_plugin/
91631 + *
91632 + * Usage:
91633 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
91634 + * $ gcc -fplugin=constify_plugin.so test.c -O2
91635 + */
91636 +
91637 +#include "gcc-plugin.h"
91638 +#include "config.h"
91639 +#include "system.h"
91640 +#include "coretypes.h"
91641 +#include "tree.h"
91642 +#include "tree-pass.h"
91643 +#include "flags.h"
91644 +#include "intl.h"
91645 +#include "toplev.h"
91646 +#include "plugin.h"
91647 +#include "diagnostic.h"
91648 +#include "plugin-version.h"
91649 +#include "tm.h"
91650 +#include "function.h"
91651 +#include "basic-block.h"
91652 +#include "gimple.h"
91653 +#include "rtl.h"
91654 +#include "emit-rtl.h"
91655 +#include "tree-flow.h"
91656 +#include "target.h"
91657 +
91658 +// should come from c-tree.h if only it were installed for gcc 4.5...
91659 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
91660 +
91661 +// unused type flag in all versions 4.5-4.8
91662 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
91663 +
91664 +int plugin_is_GPL_compatible;
91665 +
91666 +static struct plugin_info const_plugin_info = {
91667 + .version = "201303070020",
91668 + .help = "no-constify\tturn off constification\n",
91669 +};
91670 +
91671 +typedef struct {
91672 + bool has_fptr_field;
91673 + bool has_writable_field;
91674 + bool has_do_const_field;
91675 + bool has_no_const_field;
91676 +} constify_info;
91677 +
91678 +static const_tree get_field_type(const_tree field)
91679 +{
91680 + return strip_array_types(TREE_TYPE(field));
91681 +}
91682 +
91683 +static bool is_fptr(const_tree field)
91684 +{
91685 + const_tree ptr = get_field_type(field);
91686 +
91687 + if (TREE_CODE(ptr) != POINTER_TYPE)
91688 + return false;
91689 +
91690 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
91691 +}
91692 +
91693 +/*
91694 + * determine whether the given structure type meets the requirements for automatic constification,
91695 + * including the constification attributes on nested structure types
91696 + */
91697 +static void constifiable(const_tree node, constify_info *cinfo)
91698 +{
91699 + const_tree field;
91700 +
91701 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
91702 +
91703 + // e.g., pointer to structure fields while still constructing the structure type
91704 + if (TYPE_FIELDS(node) == NULL_TREE)
91705 + return;
91706 +
91707 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
91708 + const_tree type = get_field_type(field);
91709 + enum tree_code code = TREE_CODE(type);
91710 +
91711 + if (node == type)
91712 + continue;
91713 +
91714 + if (is_fptr(field))
91715 + cinfo->has_fptr_field = true;
91716 + else if (!TREE_READONLY(field))
91717 + cinfo->has_writable_field = true;
91718 +
91719 + if (code == RECORD_TYPE || code == UNION_TYPE) {
91720 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
91721 + cinfo->has_do_const_field = true;
91722 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
91723 + cinfo->has_no_const_field = true;
91724 + else
91725 + constifiable(type, cinfo);
91726 + }
91727 + }
91728 +}
91729 +
91730 +static bool constified(const_tree node)
91731 +{
91732 + constify_info cinfo = {
91733 + .has_fptr_field = false,
91734 + .has_writable_field = false,
91735 + .has_do_const_field = false,
91736 + .has_no_const_field = false
91737 + };
91738 +
91739 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
91740 +
91741 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
91742 + gcc_assert(!TYPE_READONLY(node));
91743 + return false;
91744 + }
91745 +
91746 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
91747 + gcc_assert(TYPE_READONLY(node));
91748 + return true;
91749 + }
91750 +
91751 + constifiable(node, &cinfo);
91752 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
91753 + return false;
91754 +
91755 + return TYPE_READONLY(node);
91756 +}
91757 +
91758 +static void deconstify_tree(tree node);
91759 +
91760 +static void deconstify_type(tree type)
91761 +{
91762 + tree field;
91763 +
91764 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
91765 +
91766 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
91767 + const_tree fieldtype = get_field_type(field);
91768 +
91769 + // special case handling of simple ptr-to-same-array-type members
91770 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
91771 + const_tree ptrtype = TREE_TYPE(TREE_TYPE(field));
91772 +
91773 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
91774 + continue;
91775 + if (TREE_TYPE(TREE_TYPE(field)) == type)
91776 + continue;
91777 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
91778 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
91779 + TREE_TYPE(TREE_TYPE(field)) = type;
91780 + }
91781 + continue;
91782 + }
91783 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
91784 + continue;
91785 + if (!constified(fieldtype))
91786 + continue;
91787 +
91788 + deconstify_tree(field);
91789 + TREE_READONLY(field) = 0;
91790 + }
91791 + TYPE_READONLY(type) = 0;
91792 + C_TYPE_FIELDS_READONLY(type) = 0;
91793 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
91794 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
91795 +}
91796 +
91797 +static void deconstify_tree(tree node)
91798 +{
91799 + tree old_type, new_type, field;
91800 +
91801 + old_type = TREE_TYPE(node);
91802 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
91803 + node = TREE_TYPE(node) = copy_node(old_type);
91804 + old_type = TREE_TYPE(old_type);
91805 + }
91806 +
91807 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
91808 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
91809 +
91810 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
91811 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
91812 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
91813 + DECL_FIELD_CONTEXT(field) = new_type;
91814 +
91815 + deconstify_type(new_type);
91816 +
91817 + TREE_TYPE(node) = new_type;
91818 +}
91819 +
91820 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
91821 +{
91822 + tree type;
91823 + constify_info cinfo = {
91824 + .has_fptr_field = false,
91825 + .has_writable_field = false,
91826 + .has_do_const_field = false,
91827 + .has_no_const_field = false
91828 + };
91829 +
91830 + *no_add_attrs = true;
91831 + if (TREE_CODE(*node) == FUNCTION_DECL) {
91832 + error("%qE attribute does not apply to functions", name);
91833 + return NULL_TREE;
91834 + }
91835 +
91836 + if (TREE_CODE(*node) == PARM_DECL) {
91837 + error("%qE attribute does not apply to function parameters", name);
91838 + return NULL_TREE;
91839 + }
91840 +
91841 + if (TREE_CODE(*node) == VAR_DECL) {
91842 + error("%qE attribute does not apply to variables", name);
91843 + return NULL_TREE;
91844 + }
91845 +
91846 + if (TYPE_P(*node)) {
91847 + *no_add_attrs = false;
91848 + type = *node;
91849 + } else {
91850 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
91851 + type = TREE_TYPE(*node);
91852 + }
91853 +
91854 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
91855 + error("%qE attribute applies to struct and union types only", name);
91856 + return NULL_TREE;
91857 + }
91858 +
91859 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
91860 + error("%qE attribute is already applied to the type", name);
91861 + return NULL_TREE;
91862 + }
91863 +
91864 + if (TYPE_P(*node)) {
91865 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
91866 + error("%qE attribute is incompatible with 'do_const'", name);
91867 + return NULL_TREE;
91868 + }
91869 +
91870 + constifiable(type, &cinfo);
91871 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
91872 + deconstify_tree(*node);
91873 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
91874 + return NULL_TREE;
91875 + }
91876 +
91877 + error("%qE attribute used on type that is not constified", name);
91878 + return NULL_TREE;
91879 +}
91880 +
91881 +static void constify_type(tree type)
91882 +{
91883 + TYPE_READONLY(type) = 1;
91884 + C_TYPE_FIELDS_READONLY(type) = 1;
91885 + TYPE_CONSTIFY_VISITED(type) = 1;
91886 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
91887 +}
91888 +
91889 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
91890 +{
91891 + *no_add_attrs = true;
91892 + if (!TYPE_P(*node)) {
91893 + error("%qE attribute applies to types only", name);
91894 + return NULL_TREE;
91895 + }
91896 +
91897 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
91898 + error("%qE attribute applies to struct and union types only", name);
91899 + return NULL_TREE;
91900 + }
91901 +
91902 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
91903 + error("%qE attribute is already applied to the type", name);
91904 + return NULL_TREE;
91905 + }
91906 +
91907 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
91908 + error("%qE attribute is incompatible with 'no_const'", name);
91909 + return NULL_TREE;
91910 + }
91911 +
91912 + *no_add_attrs = false;
91913 + return NULL_TREE;
91914 +}
91915 +
91916 +static struct attribute_spec no_const_attr = {
91917 + .name = "no_const",
91918 + .min_length = 0,
91919 + .max_length = 0,
91920 + .decl_required = false,
91921 + .type_required = false,
91922 + .function_type_required = false,
91923 + .handler = handle_no_const_attribute,
91924 +#if BUILDING_GCC_VERSION >= 4007
91925 + .affects_type_identity = true
91926 +#endif
91927 +};
91928 +
91929 +static struct attribute_spec do_const_attr = {
91930 + .name = "do_const",
91931 + .min_length = 0,
91932 + .max_length = 0,
91933 + .decl_required = false,
91934 + .type_required = false,
91935 + .function_type_required = false,
91936 + .handler = handle_do_const_attribute,
91937 +#if BUILDING_GCC_VERSION >= 4007
91938 + .affects_type_identity = true
91939 +#endif
91940 +};
91941 +
91942 +static void register_attributes(void *event_data, void *data)
91943 +{
91944 + register_attribute(&no_const_attr);
91945 + register_attribute(&do_const_attr);
91946 +}
91947 +
91948 +static void finish_type(void *event_data, void *data)
91949 +{
91950 + tree type = (tree)event_data;
91951 + constify_info cinfo = {
91952 + .has_fptr_field = false,
91953 + .has_writable_field = false,
91954 + .has_do_const_field = false,
91955 + .has_no_const_field = false
91956 + };
91957 +
91958 + if (type == NULL_TREE || type == error_mark_node)
91959 + return;
91960 +
91961 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
91962 + return;
91963 +
91964 + constifiable(type, &cinfo);
91965 +
91966 + if (TYPE_READONLY(type) && C_TYPE_FIELDS_READONLY(type)) {
91967 + if (!lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
91968 + return;
91969 + if (cinfo.has_writable_field)
91970 + return;
91971 + error("'do_const' attribute used on type that is%sconstified", cinfo.has_fptr_field ? " " : " not ");
91972 + return;
91973 + }
91974 +
91975 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
91976 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
91977 + deconstify_type(type);
91978 + TYPE_CONSTIFY_VISITED(type) = 1;
91979 + } else
91980 + error("'no_const' attribute used on type that is not constified");
91981 + return;
91982 + }
91983 +
91984 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
91985 + constify_type(type);
91986 + return;
91987 + }
91988 +
91989 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
91990 + constify_type(type);
91991 + return;
91992 + }
91993 +
91994 + deconstify_type(type);
91995 + TYPE_CONSTIFY_VISITED(type) = 1;
91996 +}
91997 +
91998 +static unsigned int check_local_variables(void)
91999 +{
92000 + unsigned int ret = 0;
92001 + tree var;
92002 +
92003 +#if BUILDING_GCC_VERSION == 4005
92004 + tree vars;
92005 +#else
92006 + unsigned int i;
92007 +#endif
92008 +
92009 +#if BUILDING_GCC_VERSION == 4005
92010 + for (vars = cfun->local_decls; vars; vars = TREE_CHAIN(vars)) {
92011 + var = TREE_VALUE(vars);
92012 +#else
92013 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
92014 +#endif
92015 + tree type = TREE_TYPE(var);
92016 +
92017 + gcc_assert(DECL_P(var));
92018 + if (is_global_var(var))
92019 + continue;
92020 +
92021 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
92022 + continue;
92023 +
92024 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
92025 + continue;
92026 +
92027 + if (!TYPE_CONSTIFY_VISITED(type))
92028 + continue;
92029 +
92030 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
92031 + ret = 1;
92032 + }
92033 + return ret;
92034 +}
92035 +
92036 +static struct gimple_opt_pass pass_local_variable = {
92037 + {
92038 + .type = GIMPLE_PASS,
92039 + .name = "check_local_variables",
92040 +#if BUILDING_GCC_VERSION >= 4008
92041 + .optinfo_flags = OPTGROUP_NONE,
92042 +#endif
92043 + .gate = NULL,
92044 + .execute = check_local_variables,
92045 + .sub = NULL,
92046 + .next = NULL,
92047 + .static_pass_number = 0,
92048 + .tv_id = TV_NONE,
92049 + .properties_required = 0,
92050 + .properties_provided = 0,
92051 + .properties_destroyed = 0,
92052 + .todo_flags_start = 0,
92053 + .todo_flags_finish = 0
92054 + }
92055 +};
92056 +
92057 +static struct {
92058 + const char *name;
92059 + const char *asm_op;
92060 +} sections[] = {
92061 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
92062 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
92063 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
92064 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
92065 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
92066 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
92067 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
92068 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
92069 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
92070 +};
92071 +
92072 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
92073 +
92074 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
92075 +{
92076 + size_t i;
92077 +
92078 + for (i = 0; i < ARRAY_SIZE(sections); i++)
92079 + if (!strcmp(sections[i].name, name))
92080 + return 0;
92081 + return old_section_type_flags(decl, name, reloc);
92082 +}
92083 +
92084 +static void constify_start_unit(void *gcc_data, void *user_data)
92085 +{
92086 +// size_t i;
92087 +
92088 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
92089 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
92090 +// sections[i].section = get_section(sections[i].name, 0, NULL);
92091 +
92092 + old_section_type_flags = targetm.section_type_flags;
92093 + targetm.section_type_flags = constify_section_type_flags;
92094 +}
92095 +
92096 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92097 +{
92098 + const char * const plugin_name = plugin_info->base_name;
92099 + const int argc = plugin_info->argc;
92100 + const struct plugin_argument * const argv = plugin_info->argv;
92101 + int i;
92102 + bool constify = true;
92103 +
92104 + struct register_pass_info local_variable_pass_info = {
92105 + .pass = &pass_local_variable.pass,
92106 + .reference_pass_name = "ssa",
92107 + .ref_pass_instance_number = 1,
92108 + .pos_op = PASS_POS_INSERT_BEFORE
92109 + };
92110 +
92111 + if (!plugin_default_version_check(version, &gcc_version)) {
92112 + error(G_("incompatible gcc/plugin versions"));
92113 + return 1;
92114 + }
92115 +
92116 + for (i = 0; i < argc; ++i) {
92117 + if (!(strcmp(argv[i].key, "no-constify"))) {
92118 + constify = false;
92119 + continue;
92120 + }
92121 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92122 + }
92123 +
92124 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
92125 + if (constify) {
92126 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
92127 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
92128 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
92129 + }
92130 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
92131 +
92132 + return 0;
92133 +}
92134 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
92135 new file mode 100644
92136 index 0000000..e518932
92137 --- /dev/null
92138 +++ b/tools/gcc/generate_size_overflow_hash.sh
92139 @@ -0,0 +1,94 @@
92140 +#!/bin/bash
92141 +
92142 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
92143 +
92144 +header1="size_overflow_hash.h"
92145 +database="size_overflow_hash.data"
92146 +n=65536
92147 +
92148 +usage() {
92149 +cat <<EOF
92150 +usage: $0 options
92151 +OPTIONS:
92152 + -h|--help help
92153 + -o header file
92154 + -d database file
92155 + -n hash array size
92156 +EOF
92157 + return 0
92158 +}
92159 +
92160 +while true
92161 +do
92162 + case "$1" in
92163 + -h|--help) usage && exit 0;;
92164 + -n) n=$2; shift 2;;
92165 + -o) header1="$2"; shift 2;;
92166 + -d) database="$2"; shift 2;;
92167 + --) shift 1; break ;;
92168 + *) break ;;
92169 + esac
92170 +done
92171 +
92172 +create_defines() {
92173 + for i in `seq 0 31`
92174 + do
92175 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
92176 + done
92177 + echo >> "$header1"
92178 +}
92179 +
92180 +create_structs() {
92181 + rm -f "$header1"
92182 +
92183 + create_defines
92184 +
92185 + cat "$database" | while read data
92186 + do
92187 + data_array=($data)
92188 + struct_hash_name="${data_array[0]}"
92189 + funcn="${data_array[1]}"
92190 + params="${data_array[2]}"
92191 + next="${data_array[4]}"
92192 +
92193 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
92194 +
92195 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
92196 + echo -en "\t.param\t= " >> "$header1"
92197 + line=
92198 + for param_num in ${params//-/ };
92199 + do
92200 + line="${line}PARAM"$param_num"|"
92201 + done
92202 +
92203 + echo -e "${line%?},\n};\n" >> "$header1"
92204 + done
92205 +}
92206 +
92207 +create_headers() {
92208 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
92209 +}
92210 +
92211 +create_array_elements() {
92212 + index=0
92213 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
92214 + do
92215 + data_array=($data)
92216 + i="${data_array[3]}"
92217 + hash="${data_array[0]}"
92218 + while [[ $index -lt $i ]]
92219 + do
92220 + echo -e "\t["$index"]\t= NULL," >> "$header1"
92221 + index=$(($index + 1))
92222 + done
92223 + index=$(($index + 1))
92224 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
92225 + done
92226 + echo '};' >> $header1
92227 +}
92228 +
92229 +create_structs
92230 +create_headers
92231 +create_array_elements
92232 +
92233 +exit 0
92234 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
92235 new file mode 100644
92236 index 0000000..568b360
92237 --- /dev/null
92238 +++ b/tools/gcc/kallocstat_plugin.c
92239 @@ -0,0 +1,170 @@
92240 +/*
92241 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
92242 + * Licensed under the GPL v2
92243 + *
92244 + * Note: the choice of the license means that the compilation process is
92245 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
92246 + * but for the kernel it doesn't matter since it doesn't link against
92247 + * any of the gcc libraries
92248 + *
92249 + * gcc plugin to find the distribution of k*alloc sizes
92250 + *
92251 + * TODO:
92252 + *
92253 + * BUGS:
92254 + * - none known
92255 + */
92256 +#include "gcc-plugin.h"
92257 +#include "config.h"
92258 +#include "system.h"
92259 +#include "coretypes.h"
92260 +#include "tree.h"
92261 +#include "tree-pass.h"
92262 +#include "flags.h"
92263 +#include "intl.h"
92264 +#include "toplev.h"
92265 +#include "plugin.h"
92266 +//#include "expr.h" where are you...
92267 +#include "diagnostic.h"
92268 +#include "plugin-version.h"
92269 +#include "tm.h"
92270 +#include "function.h"
92271 +#include "basic-block.h"
92272 +#include "gimple.h"
92273 +#include "rtl.h"
92274 +#include "emit-rtl.h"
92275 +
92276 +extern void print_gimple_stmt(FILE *, gimple, int, int);
92277 +
92278 +int plugin_is_GPL_compatible;
92279 +
92280 +static const char * const kalloc_functions[] = {
92281 + "__kmalloc",
92282 + "kmalloc",
92283 + "kmalloc_large",
92284 + "kmalloc_node",
92285 + "kmalloc_order",
92286 + "kmalloc_order_trace",
92287 + "kmalloc_slab",
92288 + "kzalloc",
92289 + "kzalloc_node",
92290 +};
92291 +
92292 +static struct plugin_info kallocstat_plugin_info = {
92293 + .version = "201302112000",
92294 +};
92295 +
92296 +static unsigned int execute_kallocstat(void);
92297 +
92298 +static struct gimple_opt_pass kallocstat_pass = {
92299 + .pass = {
92300 + .type = GIMPLE_PASS,
92301 + .name = "kallocstat",
92302 +#if BUILDING_GCC_VERSION >= 4008
92303 + .optinfo_flags = OPTGROUP_NONE,
92304 +#endif
92305 + .gate = NULL,
92306 + .execute = execute_kallocstat,
92307 + .sub = NULL,
92308 + .next = NULL,
92309 + .static_pass_number = 0,
92310 + .tv_id = TV_NONE,
92311 + .properties_required = 0,
92312 + .properties_provided = 0,
92313 + .properties_destroyed = 0,
92314 + .todo_flags_start = 0,
92315 + .todo_flags_finish = 0
92316 + }
92317 +};
92318 +
92319 +static bool is_kalloc(const char *fnname)
92320 +{
92321 + size_t i;
92322 +
92323 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
92324 + if (!strcmp(fnname, kalloc_functions[i]))
92325 + return true;
92326 + return false;
92327 +}
92328 +
92329 +static unsigned int execute_kallocstat(void)
92330 +{
92331 + basic_block bb;
92332 +
92333 + // 1. loop through BBs and GIMPLE statements
92334 + FOR_EACH_BB(bb) {
92335 + gimple_stmt_iterator gsi;
92336 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92337 + // gimple match:
92338 + tree fndecl, size;
92339 + gimple call_stmt;
92340 + const char *fnname;
92341 +
92342 + // is it a call
92343 + call_stmt = gsi_stmt(gsi);
92344 + if (!is_gimple_call(call_stmt))
92345 + continue;
92346 + fndecl = gimple_call_fndecl(call_stmt);
92347 + if (fndecl == NULL_TREE)
92348 + continue;
92349 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
92350 + continue;
92351 +
92352 + // is it a call to k*alloc
92353 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
92354 + if (!is_kalloc(fnname))
92355 + continue;
92356 +
92357 + // is the size arg the result of a simple const assignment
92358 + size = gimple_call_arg(call_stmt, 0);
92359 + while (true) {
92360 + gimple def_stmt;
92361 + expanded_location xloc;
92362 + size_t size_val;
92363 +
92364 + if (TREE_CODE(size) != SSA_NAME)
92365 + break;
92366 + def_stmt = SSA_NAME_DEF_STMT(size);
92367 + if (!def_stmt || !is_gimple_assign(def_stmt))
92368 + break;
92369 + if (gimple_num_ops(def_stmt) != 2)
92370 + break;
92371 + size = gimple_assign_rhs1(def_stmt);
92372 + if (!TREE_CONSTANT(size))
92373 + continue;
92374 + xloc = expand_location(gimple_location(def_stmt));
92375 + if (!xloc.file)
92376 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
92377 + size_val = TREE_INT_CST_LOW(size);
92378 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
92379 + break;
92380 + }
92381 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
92382 +//debug_tree(gimple_call_fn(call_stmt));
92383 +//print_node(stderr, "pax", fndecl, 4);
92384 + }
92385 + }
92386 +
92387 + return 0;
92388 +}
92389 +
92390 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92391 +{
92392 + const char * const plugin_name = plugin_info->base_name;
92393 + struct register_pass_info kallocstat_pass_info = {
92394 + .pass = &kallocstat_pass.pass,
92395 + .reference_pass_name = "ssa",
92396 + .ref_pass_instance_number = 1,
92397 + .pos_op = PASS_POS_INSERT_AFTER
92398 + };
92399 +
92400 + if (!plugin_default_version_check(version, &gcc_version)) {
92401 + error(G_("incompatible gcc/plugin versions"));
92402 + return 1;
92403 + }
92404 +
92405 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
92406 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
92407 +
92408 + return 0;
92409 +}
92410 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
92411 new file mode 100644
92412 index 0000000..0408e06
92413 --- /dev/null
92414 +++ b/tools/gcc/kernexec_plugin.c
92415 @@ -0,0 +1,465 @@
92416 +/*
92417 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
92418 + * Licensed under the GPL v2
92419 + *
92420 + * Note: the choice of the license means that the compilation process is
92421 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
92422 + * but for the kernel it doesn't matter since it doesn't link against
92423 + * any of the gcc libraries
92424 + *
92425 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
92426 + *
92427 + * TODO:
92428 + *
92429 + * BUGS:
92430 + * - none known
92431 + */
92432 +#include "gcc-plugin.h"
92433 +#include "config.h"
92434 +#include "system.h"
92435 +#include "coretypes.h"
92436 +#include "tree.h"
92437 +#include "tree-pass.h"
92438 +#include "flags.h"
92439 +#include "intl.h"
92440 +#include "toplev.h"
92441 +#include "plugin.h"
92442 +//#include "expr.h" where are you...
92443 +#include "diagnostic.h"
92444 +#include "plugin-version.h"
92445 +#include "tm.h"
92446 +#include "function.h"
92447 +#include "basic-block.h"
92448 +#include "gimple.h"
92449 +#include "rtl.h"
92450 +#include "emit-rtl.h"
92451 +#include "tree-flow.h"
92452 +
92453 +extern void print_gimple_stmt(FILE *, gimple, int, int);
92454 +extern rtx emit_move_insn(rtx x, rtx y);
92455 +
92456 +#if BUILDING_GCC_VERSION <= 4006
92457 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
92458 +#endif
92459 +
92460 +#if BUILDING_GCC_VERSION >= 4008
92461 +#define TODO_dump_func 0
92462 +#endif
92463 +
92464 +int plugin_is_GPL_compatible;
92465 +
92466 +static struct plugin_info kernexec_plugin_info = {
92467 + .version = "201302112000",
92468 + .help = "method=[bts|or]\tinstrumentation method\n"
92469 +};
92470 +
92471 +static unsigned int execute_kernexec_reload(void);
92472 +static unsigned int execute_kernexec_fptr(void);
92473 +static unsigned int execute_kernexec_retaddr(void);
92474 +static bool kernexec_cmodel_check(void);
92475 +
92476 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
92477 +static void (*kernexec_instrument_retaddr)(rtx);
92478 +
92479 +static struct gimple_opt_pass kernexec_reload_pass = {
92480 + .pass = {
92481 + .type = GIMPLE_PASS,
92482 + .name = "kernexec_reload",
92483 +#if BUILDING_GCC_VERSION >= 4008
92484 + .optinfo_flags = OPTGROUP_NONE,
92485 +#endif
92486 + .gate = kernexec_cmodel_check,
92487 + .execute = execute_kernexec_reload,
92488 + .sub = NULL,
92489 + .next = NULL,
92490 + .static_pass_number = 0,
92491 + .tv_id = TV_NONE,
92492 + .properties_required = 0,
92493 + .properties_provided = 0,
92494 + .properties_destroyed = 0,
92495 + .todo_flags_start = 0,
92496 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
92497 + }
92498 +};
92499 +
92500 +static struct gimple_opt_pass kernexec_fptr_pass = {
92501 + .pass = {
92502 + .type = GIMPLE_PASS,
92503 + .name = "kernexec_fptr",
92504 +#if BUILDING_GCC_VERSION >= 4008
92505 + .optinfo_flags = OPTGROUP_NONE,
92506 +#endif
92507 + .gate = kernexec_cmodel_check,
92508 + .execute = execute_kernexec_fptr,
92509 + .sub = NULL,
92510 + .next = NULL,
92511 + .static_pass_number = 0,
92512 + .tv_id = TV_NONE,
92513 + .properties_required = 0,
92514 + .properties_provided = 0,
92515 + .properties_destroyed = 0,
92516 + .todo_flags_start = 0,
92517 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
92518 + }
92519 +};
92520 +
92521 +static struct rtl_opt_pass kernexec_retaddr_pass = {
92522 + .pass = {
92523 + .type = RTL_PASS,
92524 + .name = "kernexec_retaddr",
92525 +#if BUILDING_GCC_VERSION >= 4008
92526 + .optinfo_flags = OPTGROUP_NONE,
92527 +#endif
92528 + .gate = kernexec_cmodel_check,
92529 + .execute = execute_kernexec_retaddr,
92530 + .sub = NULL,
92531 + .next = NULL,
92532 + .static_pass_number = 0,
92533 + .tv_id = TV_NONE,
92534 + .properties_required = 0,
92535 + .properties_provided = 0,
92536 + .properties_destroyed = 0,
92537 + .todo_flags_start = 0,
92538 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
92539 + }
92540 +};
92541 +
92542 +static bool kernexec_cmodel_check(void)
92543 +{
92544 + tree section;
92545 +
92546 + if (ix86_cmodel != CM_KERNEL)
92547 + return false;
92548 +
92549 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
92550 + if (!section || !TREE_VALUE(section))
92551 + return true;
92552 +
92553 + section = TREE_VALUE(TREE_VALUE(section));
92554 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
92555 + return true;
92556 +
92557 + return false;
92558 +}
92559 +
92560 +/*
92561 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
92562 + */
92563 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
92564 +{
92565 + gimple asm_movabs_stmt;
92566 +
92567 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
92568 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
92569 + gimple_asm_set_volatile(asm_movabs_stmt, true);
92570 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
92571 + update_stmt(asm_movabs_stmt);
92572 +}
92573 +
92574 +/*
92575 + * find all asm() stmts that clobber r10 and add a reload of r10
92576 + */
92577 +static unsigned int execute_kernexec_reload(void)
92578 +{
92579 + basic_block bb;
92580 +
92581 + // 1. loop through BBs and GIMPLE statements
92582 + FOR_EACH_BB(bb) {
92583 + gimple_stmt_iterator gsi;
92584 +
92585 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92586 + // gimple match: __asm__ ("" : : : "r10");
92587 + gimple asm_stmt;
92588 + size_t nclobbers;
92589 +
92590 + // is it an asm ...
92591 + asm_stmt = gsi_stmt(gsi);
92592 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
92593 + continue;
92594 +
92595 + // ... clobbering r10
92596 + nclobbers = gimple_asm_nclobbers(asm_stmt);
92597 + while (nclobbers--) {
92598 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
92599 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
92600 + continue;
92601 + kernexec_reload_fptr_mask(&gsi);
92602 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
92603 + break;
92604 + }
92605 + }
92606 + }
92607 +
92608 + return 0;
92609 +}
92610 +
92611 +/*
92612 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
92613 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
92614 + */
92615 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
92616 +{
92617 + gimple assign_intptr, assign_new_fptr, call_stmt;
92618 + tree intptr, old_fptr, new_fptr, kernexec_mask;
92619 +
92620 + call_stmt = gsi_stmt(*gsi);
92621 + old_fptr = gimple_call_fn(call_stmt);
92622 +
92623 + // create temporary unsigned long variable used for bitops and cast fptr to it
92624 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
92625 +#if BUILDING_GCC_VERSION <= 4007
92626 + add_referenced_var(intptr);
92627 + mark_sym_for_renaming(intptr);
92628 +#endif
92629 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
92630 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
92631 + update_stmt(assign_intptr);
92632 +
92633 + // apply logical or to temporary unsigned long and bitmask
92634 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
92635 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
92636 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
92637 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
92638 + update_stmt(assign_intptr);
92639 +
92640 + // cast temporary unsigned long back to a temporary fptr variable
92641 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
92642 +#if BUILDING_GCC_VERSION <= 4007
92643 + add_referenced_var(new_fptr);
92644 + mark_sym_for_renaming(new_fptr);
92645 +#endif
92646 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
92647 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
92648 + update_stmt(assign_new_fptr);
92649 +
92650 + // replace call stmt fn with the new fptr
92651 + gimple_call_set_fn(call_stmt, new_fptr);
92652 + update_stmt(call_stmt);
92653 +}
92654 +
92655 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
92656 +{
92657 + gimple asm_or_stmt, call_stmt;
92658 + tree old_fptr, new_fptr, input, output;
92659 +#if BUILDING_GCC_VERSION <= 4007
92660 + VEC(tree, gc) *inputs = NULL;
92661 + VEC(tree, gc) *outputs = NULL;
92662 +#else
92663 + vec<tree, va_gc> *inputs = NULL;
92664 + vec<tree, va_gc> *outputs = NULL;
92665 +#endif
92666 +
92667 + call_stmt = gsi_stmt(*gsi);
92668 + old_fptr = gimple_call_fn(call_stmt);
92669 +
92670 + // create temporary fptr variable
92671 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
92672 +#if BUILDING_GCC_VERSION <= 4007
92673 + add_referenced_var(new_fptr);
92674 + mark_sym_for_renaming(new_fptr);
92675 +#endif
92676 +
92677 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
92678 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
92679 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
92680 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
92681 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
92682 +#if BUILDING_GCC_VERSION <= 4007
92683 + VEC_safe_push(tree, gc, inputs, input);
92684 + VEC_safe_push(tree, gc, outputs, output);
92685 +#else
92686 + vec_safe_push(inputs, input);
92687 + vec_safe_push(outputs, output);
92688 +#endif
92689 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
92690 + gimple_asm_set_volatile(asm_or_stmt, true);
92691 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
92692 + update_stmt(asm_or_stmt);
92693 +
92694 + // replace call stmt fn with the new fptr
92695 + gimple_call_set_fn(call_stmt, new_fptr);
92696 + update_stmt(call_stmt);
92697 +}
92698 +
92699 +/*
92700 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
92701 + */
92702 +static unsigned int execute_kernexec_fptr(void)
92703 +{
92704 + basic_block bb;
92705 +
92706 + // 1. loop through BBs and GIMPLE statements
92707 + FOR_EACH_BB(bb) {
92708 + gimple_stmt_iterator gsi;
92709 +
92710 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92711 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
92712 + tree fn;
92713 + gimple call_stmt;
92714 +
92715 + // is it a call ...
92716 + call_stmt = gsi_stmt(gsi);
92717 + if (!is_gimple_call(call_stmt))
92718 + continue;
92719 + fn = gimple_call_fn(call_stmt);
92720 + if (TREE_CODE(fn) == ADDR_EXPR)
92721 + continue;
92722 + if (TREE_CODE(fn) != SSA_NAME)
92723 + gcc_unreachable();
92724 +
92725 + // ... through a function pointer
92726 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
92727 + fn = SSA_NAME_VAR(fn);
92728 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
92729 + debug_tree(fn);
92730 + gcc_unreachable();
92731 + }
92732 + }
92733 + fn = TREE_TYPE(fn);
92734 + if (TREE_CODE(fn) != POINTER_TYPE)
92735 + continue;
92736 + fn = TREE_TYPE(fn);
92737 + if (TREE_CODE(fn) != FUNCTION_TYPE)
92738 + continue;
92739 +
92740 + kernexec_instrument_fptr(&gsi);
92741 +
92742 +//debug_tree(gimple_call_fn(call_stmt));
92743 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
92744 + }
92745 + }
92746 +
92747 + return 0;
92748 +}
92749 +
92750 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
92751 +static void kernexec_instrument_retaddr_bts(rtx insn)
92752 +{
92753 + rtx btsq;
92754 + rtvec argvec, constraintvec, labelvec;
92755 + int line;
92756 +
92757 + // create asm volatile("btsq $63,(%%rsp)":::)
92758 + argvec = rtvec_alloc(0);
92759 + constraintvec = rtvec_alloc(0);
92760 + labelvec = rtvec_alloc(0);
92761 + line = expand_location(RTL_LOCATION(insn)).line;
92762 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
92763 + MEM_VOLATILE_P(btsq) = 1;
92764 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
92765 + emit_insn_before(btsq, insn);
92766 +}
92767 +
92768 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
92769 +static void kernexec_instrument_retaddr_or(rtx insn)
92770 +{
92771 + rtx orq;
92772 + rtvec argvec, constraintvec, labelvec;
92773 + int line;
92774 +
92775 + // create asm volatile("orq %%r10,(%%rsp)":::)
92776 + argvec = rtvec_alloc(0);
92777 + constraintvec = rtvec_alloc(0);
92778 + labelvec = rtvec_alloc(0);
92779 + line = expand_location(RTL_LOCATION(insn)).line;
92780 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
92781 + MEM_VOLATILE_P(orq) = 1;
92782 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
92783 + emit_insn_before(orq, insn);
92784 +}
92785 +
92786 +/*
92787 + * find all asm level function returns and forcibly set the highest bit of the return address
92788 + */
92789 +static unsigned int execute_kernexec_retaddr(void)
92790 +{
92791 + rtx insn;
92792 +
92793 + // 1. find function returns
92794 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
92795 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
92796 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
92797 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
92798 + rtx body;
92799 +
92800 + // is it a retn
92801 + if (!JUMP_P(insn))
92802 + continue;
92803 + body = PATTERN(insn);
92804 + if (GET_CODE(body) == PARALLEL)
92805 + body = XVECEXP(body, 0, 0);
92806 + if (!ANY_RETURN_P(body))
92807 + continue;
92808 + kernexec_instrument_retaddr(insn);
92809 + }
92810 +
92811 +// print_simple_rtl(stderr, get_insns());
92812 +// print_rtl(stderr, get_insns());
92813 +
92814 + return 0;
92815 +}
92816 +
92817 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92818 +{
92819 + const char * const plugin_name = plugin_info->base_name;
92820 + const int argc = plugin_info->argc;
92821 + const struct plugin_argument * const argv = plugin_info->argv;
92822 + int i;
92823 + struct register_pass_info kernexec_reload_pass_info = {
92824 + .pass = &kernexec_reload_pass.pass,
92825 + .reference_pass_name = "ssa",
92826 + .ref_pass_instance_number = 1,
92827 + .pos_op = PASS_POS_INSERT_AFTER
92828 + };
92829 + struct register_pass_info kernexec_fptr_pass_info = {
92830 + .pass = &kernexec_fptr_pass.pass,
92831 + .reference_pass_name = "ssa",
92832 + .ref_pass_instance_number = 1,
92833 + .pos_op = PASS_POS_INSERT_AFTER
92834 + };
92835 + struct register_pass_info kernexec_retaddr_pass_info = {
92836 + .pass = &kernexec_retaddr_pass.pass,
92837 + .reference_pass_name = "pro_and_epilogue",
92838 + .ref_pass_instance_number = 1,
92839 + .pos_op = PASS_POS_INSERT_AFTER
92840 + };
92841 +
92842 + if (!plugin_default_version_check(version, &gcc_version)) {
92843 + error(G_("incompatible gcc/plugin versions"));
92844 + return 1;
92845 + }
92846 +
92847 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
92848 +
92849 + if (TARGET_64BIT == 0)
92850 + return 0;
92851 +
92852 + for (i = 0; i < argc; ++i) {
92853 + if (!strcmp(argv[i].key, "method")) {
92854 + if (!argv[i].value) {
92855 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92856 + continue;
92857 + }
92858 + if (!strcmp(argv[i].value, "bts")) {
92859 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
92860 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
92861 + } else if (!strcmp(argv[i].value, "or")) {
92862 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
92863 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
92864 + fix_register("r10", 1, 1);
92865 + } else
92866 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
92867 + continue;
92868 + }
92869 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92870 + }
92871 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
92872 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
92873 +
92874 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
92875 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
92876 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
92877 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
92878 +
92879 + return 0;
92880 +}
92881 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
92882 new file mode 100644
92883 index 0000000..b5395ba
92884 --- /dev/null
92885 +++ b/tools/gcc/latent_entropy_plugin.c
92886 @@ -0,0 +1,327 @@
92887 +/*
92888 + * Copyright 2012-2013 by the PaX Team <pageexec@freemail.hu>
92889 + * Licensed under the GPL v2
92890 + *
92891 + * Note: the choice of the license means that the compilation process is
92892 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
92893 + * but for the kernel it doesn't matter since it doesn't link against
92894 + * any of the gcc libraries
92895 + *
92896 + * gcc plugin to help generate a little bit of entropy from program state,
92897 + * used during boot in the kernel
92898 + *
92899 + * TODO:
92900 + * - add ipa pass to identify not explicitly marked candidate functions
92901 + * - mix in more program state (function arguments/return values, loop variables, etc)
92902 + * - more instrumentation control via attribute parameters
92903 + *
92904 + * BUGS:
92905 + * - LTO needs -flto-partition=none for now
92906 + */
92907 +#include "gcc-plugin.h"
92908 +#include "config.h"
92909 +#include "system.h"
92910 +#include "coretypes.h"
92911 +#include "tree.h"
92912 +#include "tree-pass.h"
92913 +#include "flags.h"
92914 +#include "intl.h"
92915 +#include "toplev.h"
92916 +#include "plugin.h"
92917 +//#include "expr.h" where are you...
92918 +#include "diagnostic.h"
92919 +#include "plugin-version.h"
92920 +#include "tm.h"
92921 +#include "function.h"
92922 +#include "basic-block.h"
92923 +#include "gimple.h"
92924 +#include "rtl.h"
92925 +#include "emit-rtl.h"
92926 +#include "tree-flow.h"
92927 +#include "langhooks.h"
92928 +
92929 +#if BUILDING_GCC_VERSION >= 4008
92930 +#define TODO_dump_func 0
92931 +#endif
92932 +
92933 +int plugin_is_GPL_compatible;
92934 +
92935 +static tree latent_entropy_decl;
92936 +
92937 +static struct plugin_info latent_entropy_plugin_info = {
92938 + .version = "201303102320",
92939 + .help = NULL
92940 +};
92941 +
92942 +static unsigned int execute_latent_entropy(void);
92943 +static bool gate_latent_entropy(void);
92944 +
92945 +static struct gimple_opt_pass latent_entropy_pass = {
92946 + .pass = {
92947 + .type = GIMPLE_PASS,
92948 + .name = "latent_entropy",
92949 +#if BUILDING_GCC_VERSION >= 4008
92950 + .optinfo_flags = OPTGROUP_NONE,
92951 +#endif
92952 + .gate = gate_latent_entropy,
92953 + .execute = execute_latent_entropy,
92954 + .sub = NULL,
92955 + .next = NULL,
92956 + .static_pass_number = 0,
92957 + .tv_id = TV_NONE,
92958 + .properties_required = PROP_gimple_leh | PROP_cfg,
92959 + .properties_provided = 0,
92960 + .properties_destroyed = 0,
92961 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
92962 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
92963 + }
92964 +};
92965 +
92966 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
92967 +{
92968 + if (TREE_CODE(*node) != FUNCTION_DECL) {
92969 + *no_add_attrs = true;
92970 + error("%qE attribute only applies to functions", name);
92971 + }
92972 + return NULL_TREE;
92973 +}
92974 +
92975 +static struct attribute_spec latent_entropy_attr = {
92976 + .name = "latent_entropy",
92977 + .min_length = 0,
92978 + .max_length = 0,
92979 + .decl_required = true,
92980 + .type_required = false,
92981 + .function_type_required = false,
92982 + .handler = handle_latent_entropy_attribute,
92983 +#if BUILDING_GCC_VERSION >= 4007
92984 + .affects_type_identity = false
92985 +#endif
92986 +};
92987 +
92988 +static void register_attributes(void *event_data, void *data)
92989 +{
92990 + register_attribute(&latent_entropy_attr);
92991 +}
92992 +
92993 +static bool gate_latent_entropy(void)
92994 +{
92995 + tree latent_entropy_attr;
92996 +
92997 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
92998 + return latent_entropy_attr != NULL_TREE;
92999 +}
93000 +
93001 +static unsigned HOST_WIDE_INT seed;
93002 +static unsigned HOST_WIDE_INT get_random_const(void)
93003 +{
93004 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
93005 + return seed;
93006 +}
93007 +
93008 +static enum tree_code get_op(tree *rhs)
93009 +{
93010 + static enum tree_code op;
93011 + unsigned HOST_WIDE_INT random_const;
93012 +
93013 + random_const = get_random_const();
93014 +
93015 + switch (op) {
93016 + case BIT_XOR_EXPR:
93017 + op = PLUS_EXPR;
93018 + break;
93019 +
93020 + case PLUS_EXPR:
93021 + if (rhs) {
93022 + op = LROTATE_EXPR;
93023 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
93024 + break;
93025 + }
93026 +
93027 + case LROTATE_EXPR:
93028 + default:
93029 + op = BIT_XOR_EXPR;
93030 + break;
93031 + }
93032 + if (rhs)
93033 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
93034 + return op;
93035 +}
93036 +
93037 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
93038 +{
93039 + gimple_stmt_iterator gsi;
93040 + gimple assign;
93041 + tree addxorrol, rhs;
93042 + enum tree_code op;
93043 +
93044 + op = get_op(&rhs);
93045 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
93046 + assign = gimple_build_assign(local_entropy, addxorrol);
93047 +#if BUILDING_GCC_VERSION <= 4007
93048 + find_referenced_vars_in(assign);
93049 +#endif
93050 +//debug_bb(bb);
93051 + gsi = gsi_after_labels(bb);
93052 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
93053 + update_stmt(assign);
93054 +}
93055 +
93056 +static void perturb_latent_entropy(basic_block bb, tree rhs)
93057 +{
93058 + gimple_stmt_iterator gsi;
93059 + gimple assign;
93060 + tree addxorrol, temp;
93061 +
93062 + // 1. create temporary copy of latent_entropy
93063 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
93064 +#if BUILDING_GCC_VERSION <= 4007
93065 + add_referenced_var(temp);
93066 + mark_sym_for_renaming(temp);
93067 +#endif
93068 +
93069 + // 2. read...
93070 + assign = gimple_build_assign(temp, latent_entropy_decl);
93071 +#if BUILDING_GCC_VERSION <= 4007
93072 + find_referenced_vars_in(assign);
93073 +#endif
93074 + gsi = gsi_after_labels(bb);
93075 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
93076 + update_stmt(assign);
93077 +
93078 + // 3. ...modify...
93079 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
93080 + assign = gimple_build_assign(temp, addxorrol);
93081 +#if BUILDING_GCC_VERSION <= 4007
93082 + find_referenced_vars_in(assign);
93083 +#endif
93084 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
93085 + update_stmt(assign);
93086 +
93087 + // 4. ...write latent_entropy
93088 + assign = gimple_build_assign(latent_entropy_decl, temp);
93089 +#if BUILDING_GCC_VERSION <= 4007
93090 + find_referenced_vars_in(assign);
93091 +#endif
93092 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
93093 + update_stmt(assign);
93094 +}
93095 +
93096 +static unsigned int execute_latent_entropy(void)
93097 +{
93098 + basic_block bb;
93099 + gimple assign;
93100 + gimple_stmt_iterator gsi;
93101 + tree local_entropy;
93102 +
93103 + if (!latent_entropy_decl) {
93104 + struct varpool_node *node;
93105 +
93106 +#if BUILDING_GCC_VERSION <= 4007
93107 + for (node = varpool_nodes; node; node = node->next) {
93108 + tree var = node->decl;
93109 +#else
93110 + FOR_EACH_VARIABLE(node) {
93111 + tree var = node->symbol.decl;
93112 +#endif
93113 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
93114 + continue;
93115 + latent_entropy_decl = var;
93116 +// debug_tree(var);
93117 + break;
93118 + }
93119 + if (!latent_entropy_decl) {
93120 +// debug_tree(current_function_decl);
93121 + return 0;
93122 + }
93123 + }
93124 +
93125 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
93126 +
93127 + // 1. create local entropy variable
93128 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
93129 +#if BUILDING_GCC_VERSION <= 4007
93130 + add_referenced_var(local_entropy);
93131 + mark_sym_for_renaming(local_entropy);
93132 +#endif
93133 +
93134 + // 2. initialize local entropy variable
93135 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
93136 + if (dom_info_available_p(CDI_DOMINATORS))
93137 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
93138 + gsi = gsi_start_bb(bb);
93139 +
93140 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
93141 +// gimple_set_location(assign, loc);
93142 +#if BUILDING_GCC_VERSION <= 4007
93143 + find_referenced_vars_in(assign);
93144 +#endif
93145 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
93146 + update_stmt(assign);
93147 + bb = bb->next_bb;
93148 +
93149 + // 3. instrument each BB with an operation on the local entropy variable
93150 + while (bb != EXIT_BLOCK_PTR) {
93151 + perturb_local_entropy(bb, local_entropy);
93152 + bb = bb->next_bb;
93153 + };
93154 +
93155 + // 4. mix local entropy into the global entropy variable
93156 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
93157 + return 0;
93158 +}
93159 +
93160 +static void start_unit_callback(void *gcc_data, void *user_data)
93161 +{
93162 + tree latent_entropy_type;
93163 +
93164 +#if BUILDING_GCC_VERSION >= 4007
93165 + seed = get_random_seed(false);
93166 +#else
93167 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
93168 + seed *= seed;
93169 +#endif
93170 +
93171 + if (in_lto_p)
93172 + return;
93173 +
93174 + // extern volatile u64 latent_entropy
93175 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
93176 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
93177 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
93178 +
93179 + TREE_STATIC(latent_entropy_decl) = 1;
93180 + TREE_PUBLIC(latent_entropy_decl) = 1;
93181 + TREE_USED(latent_entropy_decl) = 1;
93182 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
93183 + DECL_EXTERNAL(latent_entropy_decl) = 1;
93184 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
93185 + DECL_INITIAL(latent_entropy_decl) = NULL;
93186 + lang_hooks.decls.pushdecl(latent_entropy_decl);
93187 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
93188 +// varpool_finalize_decl(latent_entropy_decl);
93189 +// varpool_mark_needed_node(latent_entropy_decl);
93190 +}
93191 +
93192 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
93193 +{
93194 + const char * const plugin_name = plugin_info->base_name;
93195 + struct register_pass_info latent_entropy_pass_info = {
93196 + .pass = &latent_entropy_pass.pass,
93197 + .reference_pass_name = "optimized",
93198 + .ref_pass_instance_number = 1,
93199 + .pos_op = PASS_POS_INSERT_BEFORE
93200 + };
93201 +
93202 + if (!plugin_default_version_check(version, &gcc_version)) {
93203 + error(G_("incompatible gcc/plugin versions"));
93204 + return 1;
93205 + }
93206 +
93207 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
93208 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
93209 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
93210 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
93211 +
93212 + return 0;
93213 +}
93214 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
93215 new file mode 100644
93216 index 0000000..5921fd7
93217 --- /dev/null
93218 +++ b/tools/gcc/size_overflow_hash.data
93219 @@ -0,0 +1,3713 @@
93220 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
93221 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
93222 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
93223 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
93224 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
93225 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
93226 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
93227 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
93228 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
93229 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
93230 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
93231 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
93232 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
93233 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
93234 +create_log_8225 create_log 2 8225 NULL
93235 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
93236 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
93237 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
93238 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
93239 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
93240 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
93241 +padzero_55 padzero 1 55 &sel_read_policyvers_55
93242 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
93243 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
93244 +read_file_blob_57406 read_file_blob 3 57406 NULL
93245 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
93246 +enclosure_register_57412 enclosure_register 3 57412 NULL
93247 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
93248 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
93249 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
93250 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
93251 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
93252 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
93253 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
93254 +init_cdev_8274 init_cdev 1 8274 NULL
93255 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
93256 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
93257 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
93258 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
93259 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
93260 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
93261 +load_msg_95 load_msg 2 95 NULL
93262 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
93263 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
93264 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
93265 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
93266 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
93267 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
93268 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
93269 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
93270 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
93271 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
93272 +send_midi_async_57463 send_midi_async 3 57463 NULL
93273 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
93274 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
93275 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
93276 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
93277 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
93278 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
93279 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
93280 +init_q_132 init_q 4 132 NULL
93281 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
93282 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
93283 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
93284 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
93285 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
93286 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
93287 +uio_read_49300 uio_read 3 49300 NULL
93288 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
93289 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
93290 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
93291 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
93292 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
93293 +play_iframe_8219 play_iframe 3 8219 NULL
93294 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
93295 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
93296 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
93297 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
93298 +init_tag_map_57515 init_tag_map 3 57515 NULL
93299 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
93300 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
93301 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
93302 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
93303 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
93304 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
93305 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
93306 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
93307 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
93308 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
93309 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
93310 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
93311 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
93312 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
93313 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
93314 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
93315 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
93316 +cache_read_24790 cache_read 3 24790 NULL
93317 +px_raw_event_49371 px_raw_event 4 49371 NULL
93318 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
93319 +compat_filldir_32999 compat_filldir 3 32999 NULL
93320 +hci_si_event_1404 hci_si_event 3 1404 NULL
93321 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
93322 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
93323 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
93324 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
93325 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
93326 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
93327 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
93328 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
93329 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
93330 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
93331 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
93332 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
93333 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
93334 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
93335 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
93336 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
93337 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
93338 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
93339 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
93340 +mem_read_57631 mem_read 3 57631 NULL
93341 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
93342 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
93343 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
93344 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
93345 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
93346 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
93347 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
93348 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
93349 +queues_read_24877 queues_read 3 24877 NULL
93350 +__fprog_create_41263 __fprog_create 2 41263 NULL
93351 +syslog_print_307 syslog_print 2 307 NULL
93352 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
93353 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
93354 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
93355 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
93356 +r3964_write_57662 r3964_write 4 57662 NULL
93357 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
93358 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
93359 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
93360 +alloc_context_41283 alloc_context 1 41283 NULL
93361 +__lgwrite_57669 __lgwrite 4 57669 NULL
93362 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
93363 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
93364 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
93365 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
93366 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
93367 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
93368 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
93369 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
93370 +write_node_33121 write_node 4 33121 NULL
93371 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
93372 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
93373 +profile_remove_8556 profile_remove 3 8556 NULL
93374 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
93375 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
93376 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
93377 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
93378 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
93379 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
93380 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
93381 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
93382 +tower_write_8580 tower_write 3 8580 NULL
93383 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
93384 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
93385 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
93386 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
93387 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
93388 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
93389 +smk_write_access_49561 smk_write_access 3 49561 NULL
93390 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
93391 +kmp_init_41373 kmp_init 2 41373 NULL
93392 +context_alloc_24645 context_alloc 3 24645 NULL
93393 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
93394 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
93395 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
93396 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
93397 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
93398 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
93399 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
93400 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
93401 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
93402 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
93403 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
93404 +pp_read_33210 pp_read 3 33210 NULL
93405 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
93406 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
93407 +ivtv_read_57796 ivtv_read 3 57796 NULL
93408 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
93409 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
93410 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
93411 +heap_init_49617 heap_init 2 49617 NULL
93412 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
93413 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
93414 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
93415 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
93416 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
93417 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
93418 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
93419 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
93420 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
93421 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
93422 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
93423 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
93424 +st_write_16874 st_write 3 16874 NULL
93425 +copy_to_user_57835 copy_to_user 3 57835 NULL
93426 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
93427 +pidlist_resize_496 pidlist_resize 2 496 NULL
93428 +flash_read_57843 flash_read 3 57843 NULL
93429 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
93430 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
93431 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
93432 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
93433 +arcfb_write_8702 arcfb_write 3 8702 NULL
93434 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
93435 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
93436 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
93437 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
93438 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
93439 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
93440 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
93441 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
93442 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
93443 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
93444 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
93445 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
93446 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
93447 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
93448 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
93449 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
93450 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
93451 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
93452 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
93453 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
93454 +devres_alloc_551 devres_alloc 2 551 NULL
93455 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
93456 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
93457 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
93458 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
93459 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
93460 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
93461 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
93462 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
93463 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
93464 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
93465 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
93466 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
93467 +sys_prctl_8766 sys_prctl 4 8766 NULL
93468 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
93469 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
93470 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
93471 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
93472 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
93473 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
93474 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
93475 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
93476 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
93477 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
93478 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
93479 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
93480 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
93481 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
93482 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
93483 +gserial_setup_41558 gserial_setup 2 41558 NULL
93484 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
93485 +rx_57944 rx 4 57944 NULL
93486 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
93487 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
93488 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
93489 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
93490 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
93491 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
93492 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
93493 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
93494 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
93495 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
93496 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
93497 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
93498 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
93499 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
93500 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
93501 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
93502 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
93503 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
93504 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
93505 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
93506 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
93507 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
93508 +a2mp_send_41615 a2mp_send 4 41615 NULL
93509 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
93510 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
93511 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
93512 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
93513 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
93514 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
93515 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
93516 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
93517 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
93518 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
93519 +add_uuid_49831 add_uuid 4 49831 NULL
93520 +send_pages_8872 send_pages 3 8872 NULL
93521 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
93522 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
93523 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
93524 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
93525 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
93526 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
93527 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
93528 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
93529 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
93530 +vfs_writev_25278 vfs_writev 3 25278 NULL
93531 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
93532 +alloc_async_14208 alloc_async 1 14208 NULL
93533 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
93534 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
93535 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
93536 +create_entry_33479 create_entry 2 33479 NULL
93537 +mce_async_out_58056 mce_async_out 3 58056 NULL
93538 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
93539 +sys_preadv_17100 sys_preadv 3 17100 NULL
93540 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
93541 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
93542 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
93543 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
93544 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
93545 +res_counter_read_33499 res_counter_read 4 33499 NULL
93546 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
93547 +cm4040_write_58079 cm4040_write 3 58079 NULL
93548 +fb_read_33506 fb_read 3 33506 NULL
93549 +help_25316 help 5 25316 NULL nohasharray
93550 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
93551 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
93552 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
93553 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
93554 +ddp_set_map_751 ddp_set_map 4 751 NULL
93555 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
93556 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
93557 +dvb_video_write_754 dvb_video_write 3 754 NULL
93558 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
93559 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
93560 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
93561 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
93562 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
93563 +udi_log_event_58105 udi_log_event 3 58105 NULL
93564 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
93565 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
93566 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
93567 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
93568 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
93569 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
93570 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
93571 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
93572 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
93573 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
93574 +vol_cdev_read_8968 vol_cdev_read 3 8968 NULL nohasharray
93575 +seq_open_net_8968 seq_open_net 4 8968 &vol_cdev_read_8968
93576 +sep_read_17161 sep_read 3 17161 NULL
93577 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
93578 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
93579 +dup_array_33551 dup_array 3 33551 NULL
93580 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
93581 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
93582 +fillonedir_41746 fillonedir 3 41746 NULL
93583 +init_bch_64130 init_bch 1-2 64130 NULL
93584 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
93585 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
93586 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
93587 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
93588 +savemem_58129 savemem 3 58129 NULL
93589 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
93590 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
93591 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
93592 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
93593 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
93594 +if_writecmd_815 if_writecmd 2 815 NULL
93595 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
93596 +read_fifo_826 read_fifo 3 826 NULL
93597 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
93598 +scsi_execute_33596 scsi_execute 5 33596 NULL
93599 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
93600 +ms_rw_17220 ms_rw 3-4 17220 NULL
93601 +read_tree_block_841 read_tree_block 3 841 NULL
93602 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
93603 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
93604 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
93605 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
93606 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
93607 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
93608 +um_idi_read_850 um_idi_read 3 850 NULL
93609 +__module_alloc_50004 __module_alloc 1 50004 NULL
93610 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
93611 +ts_read_44687 ts_read 3 44687 NULL
93612 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
93613 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
93614 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
93615 +provide_user_output_41105 provide_user_output 3 41105 NULL
93616 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
93617 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
93618 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
93619 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
93620 +alloc_ep_17269 alloc_ep 1 17269 NULL
93621 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
93622 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
93623 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
93624 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
93625 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
93626 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
93627 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
93628 +create_queues_9088 create_queues 2-3 9088 NULL
93629 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
93630 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
93631 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
93632 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
93633 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
93634 +read_file_debug_58256 read_file_debug 3 58256 NULL
93635 +skb_pad_17302 skb_pad 2 17302 NULL
93636 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
93637 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
93638 +profile_load_58267 profile_load 3 58267 NULL
93639 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
93640 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
93641 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
93642 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
93643 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
93644 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
93645 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
93646 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
93647 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
93648 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
93649 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
93650 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
93651 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
93652 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
93653 +get_packet_41914 get_packet 3 41914 NULL
93654 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
93655 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
93656 +read_file_slot_50111 read_file_slot 3 50111 NULL
93657 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
93658 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
93659 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
93660 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
93661 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
93662 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
93663 +copy_items_50140 copy_items 6 50140 NULL
93664 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
93665 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
93666 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
93667 +map_addr_56144 map_addr 7 56144 NULL
93668 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
93669 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
93670 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
93671 +portnames_read_41958 portnames_read 3 41958 NULL
93672 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
93673 +hashtab_create_33769 hashtab_create 3 33769 NULL
93674 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
93675 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
93676 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
93677 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
93678 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
93679 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
93680 +odev_update_50169 odev_update 2 50169 NULL
93681 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
93682 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
93683 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
93684 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
93685 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
93686 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
93687 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
93688 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
93689 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
93690 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
93691 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
93692 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
93693 +lguest_map_42008 lguest_map 1-2 42008 NULL
93694 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
93695 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
93696 +pool_allocate_42012 pool_allocate 3 42012 NULL
93697 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
93698 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
93699 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
93700 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
93701 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
93702 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
93703 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
93704 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
93705 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
93706 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
93707 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
93708 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
93709 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
93710 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
93711 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
93712 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
93713 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
93714 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
93715 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
93716 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
93717 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
93718 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
93719 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
93720 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
93721 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
93722 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
93723 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
93724 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
93725 +config_proc_write_33878 config_proc_write 3 33878 NULL
93726 +capabilities_read_58457 capabilities_read 3 58457 NULL
93727 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
93728 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
93729 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
93730 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
93731 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
93732 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
93733 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
93734 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
93735 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
93736 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
93737 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
93738 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
93739 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
93740 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
93741 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
93742 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
93743 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
93744 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
93745 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
93746 +vme_user_write_15587 vme_user_write 3 15587 NULL
93747 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
93748 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
93749 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
93750 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
93751 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
93752 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
93753 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
93754 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
93755 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
93756 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
93757 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
93758 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
93759 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
93760 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
93761 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
93762 +read_9397 read 3 9397 NULL
93763 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
93764 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
93765 +printer_write_60276 printer_write 3 60276 NULL
93766 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
93767 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
93768 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
93769 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
93770 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
93771 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
93772 +osst_execute_17607 osst_execute 7-6 17607 NULL
93773 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
93774 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
93775 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
93776 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
93777 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
93778 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
93779 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
93780 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
93781 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
93782 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
93783 +xip_file_read_58592 xip_file_read 3 58592 NULL
93784 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
93785 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
93786 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
93787 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
93788 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
93789 +ppp_write_34034 ppp_write 3 34034 NULL
93790 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
93791 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
93792 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
93793 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
93794 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
93795 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
93796 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
93797 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
93798 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
93799 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
93800 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
93801 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
93802 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
93803 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
93804 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
93805 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
93806 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
93807 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
93808 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
93809 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
93810 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
93811 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
93812 +lp_write_9511 lp_write 3 9511 NULL
93813 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
93814 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
93815 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
93816 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
93817 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
93818 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
93819 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
93820 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
93821 +read_file_dma_9530 read_file_dma 3 9530 NULL
93822 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
93823 +rcname_read_25919 rcname_read 3 25919 NULL
93824 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
93825 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
93826 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
93827 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
93828 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
93829 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
93830 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
93831 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
93832 +key_flags_read_25931 key_flags_read 3 25931 NULL
93833 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
93834 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
93835 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
93836 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
93837 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
93838 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
93839 +fw_node_create_9559 fw_node_create 2 9559 NULL
93840 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
93841 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
93842 +kobj_map_9566 kobj_map 2-3 9566 NULL
93843 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
93844 +acpi_map_58725 acpi_map 1-2 58725 NULL
93845 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
93846 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
93847 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
93848 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
93849 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
93850 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
93851 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
93852 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
93853 +file_read_actor_1401 file_read_actor 4 1401 NULL
93854 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
93855 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
93856 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
93857 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
93858 +do_sync_9604 do_sync 1 9604 NULL
93859 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
93860 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
93861 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
93862 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
93863 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
93864 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
93865 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
93866 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
93867 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
93868 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
93869 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
93870 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
93871 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
93872 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
93873 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
93874 +sge_rx_50594 sge_rx 3 50594 NULL
93875 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
93876 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
93877 +skb_padto_50759 skb_padto 2 50759 NULL
93878 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
93879 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
93880 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
93881 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
93882 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
93883 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
93884 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
93885 +ep_read_58813 ep_read 3 58813 NULL
93886 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
93887 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
93888 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
93889 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
93890 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
93891 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
93892 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
93893 +dns_query_9676 dns_query 3 9676 NULL
93894 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
93895 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
93896 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
93897 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
93898 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
93899 +command_write_58841 command_write 3 58841 NULL
93900 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
93901 +dev_config_8506 dev_config 3 8506 NULL
93902 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
93903 +sys_readv_50664 sys_readv 3 50664 NULL
93904 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
93905 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
93906 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
93907 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
93908 +recover_head_17904 recover_head 3 17904 NULL
93909 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
93910 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
93911 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
93912 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
93913 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
93914 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
93915 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
93916 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
93917 +skb_cow_26138 skb_cow 2 26138 NULL
93918 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
93919 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
93920 +do_sigpending_9766 do_sigpending 2 9766 NULL
93921 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
93922 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
93923 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
93924 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
93925 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
93926 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
93927 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
93928 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
93929 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
93930 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
93931 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
93932 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
93933 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
93934 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
93935 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
93936 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
93937 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
93938 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
93939 +get_registers_26187 get_registers 3 26187 NULL
93940 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
93941 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
93942 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
93943 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
93944 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
93945 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
93946 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
93947 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
93948 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
93949 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
93950 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
93951 +mce_write_26201 mce_write 3 26201 NULL
93952 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
93953 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
93954 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
93955 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
93956 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
93957 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
93958 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
93959 +tpm_write_50798 tpm_write 3 50798 NULL
93960 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
93961 +tun_do_read_50800 tun_do_read 4 50800 NULL
93962 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
93963 +write_flush_50803 write_flush 3 50803 NULL
93964 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
93965 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
93966 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
93967 +dvb_play_50814 dvb_play 3 50814 NULL
93968 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
93969 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
93970 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
93971 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
93972 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
93973 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
93974 +dma_attach_50831 dma_attach 6-7 50831 NULL
93975 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
93976 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
93977 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
93978 +packet_came_18072 packet_came 3 18072 NULL
93979 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
93980 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
93981 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
93982 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
93983 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
93984 +get_vm_area_18080 get_vm_area 1 18080 NULL
93985 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
93986 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
93987 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
93988 +self_check_write_50856 self_check_write 5 50856 NULL
93989 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
93990 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
93991 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
93992 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
93993 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
93994 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
93995 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
93996 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
93997 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
93998 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
93999 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
94000 +vb2_read_42703 vb2_read 3 42703 NULL
94001 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
94002 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
94003 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
94004 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
94005 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
94006 +read_file_misc_9948 read_file_misc 3 9948 NULL
94007 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
94008 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
94009 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
94010 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
94011 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
94012 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
94013 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
94014 +cosa_write_1774 cosa_write 3 1774 NULL
94015 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
94016 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
94017 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
94018 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
94019 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
94020 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
94021 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
94022 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
94023 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
94024 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
94025 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
94026 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
94027 +mld_newpack_50950 mld_newpack 2 50950 NULL
94028 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
94029 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
94030 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
94031 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
94032 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
94033 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
94034 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
94035 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
94036 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
94037 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
94038 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
94039 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
94040 +handle_request_10024 handle_request 9 10024 NULL
94041 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
94042 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
94043 +timeout_write_50991 timeout_write 3 50991 NULL
94044 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
94045 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
94046 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
94047 +proc_write_51003 proc_write 3 51003 NULL
94048 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
94049 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
94050 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
94051 +set_arg_42824 set_arg 3 42824 NULL
94052 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
94053 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
94054 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
94055 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
94056 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
94057 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
94058 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
94059 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
94060 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
94061 +dt3155_read_59226 dt3155_read 3 59226 NULL
94062 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
94063 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
94064 +dump_midi_51040 dump_midi 3 51040 NULL
94065 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
94066 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
94067 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
94068 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
94069 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
94070 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
94071 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
94072 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
94073 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
94074 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
94075 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
94076 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
94077 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
94078 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
94079 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
94080 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
94081 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
94082 +read_vmcore_26501 read_vmcore 3 26501 NULL
94083 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
94084 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
94085 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
94086 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
94087 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
94088 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
94089 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
94090 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
94091 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
94092 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
94093 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
94094 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
94095 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
94096 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
94097 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
94098 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
94099 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
94100 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
94101 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
94102 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
94103 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
94104 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
94105 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
94106 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
94107 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
94108 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
94109 +fd_copyout_59323 fd_copyout 3 59323 NULL
94110 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
94111 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
94112 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
94113 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
94114 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
94115 +solos_param_store_34755 solos_param_store 4 34755 NULL
94116 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
94117 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
94118 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
94119 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
94120 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
94121 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
94122 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
94123 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
94124 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
94125 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
94126 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
94127 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
94128 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
94129 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
94130 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
94131 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
94132 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
94133 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
94134 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
94135 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
94136 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
94137 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
94138 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
94139 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
94140 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
94141 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
94142 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
94143 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
94144 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
94145 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
94146 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
94147 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
94148 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
94149 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
94150 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
94151 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
94152 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
94153 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
94154 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
94155 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
94156 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
94157 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
94158 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
94159 +tipc_send_51238 tipc_send 4 51238 NULL
94160 +drm_property_create_51239 drm_property_create 4 51239 NULL
94161 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
94162 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
94163 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
94164 +audit_expand_2098 audit_expand 2 2098 NULL
94165 +st_read_51251 st_read 3 51251 NULL
94166 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
94167 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
94168 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
94169 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
94170 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
94171 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
94172 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
94173 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
94174 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
94175 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
94176 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
94177 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
94178 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
94179 +c4_add_card_54968 c4_add_card 3 54968 NULL
94180 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
94181 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
94182 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
94183 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
94184 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
94185 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
94186 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
94187 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
94188 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
94189 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
94190 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
94191 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
94192 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
94193 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
94194 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
94195 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
94196 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
94197 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
94198 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
94199 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
94200 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
94201 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
94202 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
94203 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
94204 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
94205 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
94206 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
94207 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
94208 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
94209 +debug_output_18575 debug_output 3 18575 NULL
94210 +Realloc_34961 Realloc 2 34961 NULL
94211 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
94212 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
94213 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
94214 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
94215 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
94216 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
94217 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
94218 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
94219 +vhci_write_2224 vhci_write 3 2224 NULL
94220 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
94221 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
94222 +rb_alloc_3102 rb_alloc 1 3102 NULL
94223 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
94224 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
94225 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
94226 +write_pbl_59583 write_pbl 4 59583 NULL
94227 +from_buffer_18625 from_buffer 3 18625 NULL
94228 +uio_write_43202 uio_write 3 43202 NULL
94229 +memdup_user_59590 memdup_user 2 59590 NULL
94230 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
94231 +iso_callback_43208 iso_callback 3 43208 NULL
94232 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
94233 +smk_write_load_26829 smk_write_load 3 26829 NULL
94234 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
94235 +do_update_counters_2259 do_update_counters 4 2259 NULL
94236 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
94237 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
94238 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
94239 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
94240 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
94241 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
94242 +mtrr_write_59622 mtrr_write 3 59622 NULL
94243 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
94244 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
94245 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
94246 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
94247 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
94248 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
94249 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
94250 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
94251 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
94252 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
94253 +fixup_leb_43256 fixup_leb 3 43256 NULL
94254 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
94255 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
94256 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
94257 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
94258 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
94259 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
94260 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
94261 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
94262 +evtchn_write_43278 evtchn_write 3 43278 NULL
94263 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
94264 +store_ifalias_35088 store_ifalias 4 35088 NULL
94265 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
94266 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
94267 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
94268 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
94269 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
94270 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
94271 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
94272 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
94273 +capi_write_35104 capi_write 3 35104 NULL nohasharray
94274 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
94275 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
94276 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
94277 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
94278 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
94279 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
94280 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
94281 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
94282 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
94283 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
94284 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
94285 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
94286 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
94287 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
94288 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
94289 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
94290 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
94291 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
94292 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
94293 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
94294 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
94295 +do_trimming_26952 do_trimming 3 26952 NULL
94296 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
94297 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
94298 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
94299 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
94300 +alloc_buf_34532 alloc_buf 1 34532 NULL
94301 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
94302 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
94303 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
94304 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
94305 +otp_read_10594 otp_read 2-4-5 10594 NULL
94306 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
94307 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
94308 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
94309 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
94310 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
94311 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
94312 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
94313 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
94314 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
94315 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
94316 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
94317 +venus_remove_59781 venus_remove 4 59781 NULL
94318 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
94319 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
94320 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
94321 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
94322 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
94323 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
94324 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
94325 +xenfb_write_43412 xenfb_write 3 43412 NULL
94326 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
94327 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
94328 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
94329 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
94330 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
94331 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
94332 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 &__alloc_bootmem_low_43423
94333 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
94334 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
94335 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
94336 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
94337 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
94338 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
94339 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
94340 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
94341 +cmd_complete_51629 cmd_complete 6 51629 NULL
94342 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
94343 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
94344 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
94345 +set_fd_set_35249 set_fd_set 1 35249 NULL
94346 +wiphy_new_2482 wiphy_new 2 2482 NULL
94347 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
94348 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
94349 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
94350 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
94351 +tcp_push_10680 tcp_push 3 10680 NULL
94352 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
94353 +c101_run_37279 c101_run 2 37279 NULL
94354 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
94355 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
94356 +tun_put_user_59849 tun_put_user 4 59849 NULL
94357 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
94358 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
94359 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
94360 +dm_write_2513 dm_write 3 2513 NULL
94361 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
94362 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
94363 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
94364 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
94365 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
94366 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
94367 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
94368 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
94369 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
94370 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
94371 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
94372 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
94373 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
94374 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
94375 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
94376 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
94377 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
94378 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
94379 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
94380 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
94381 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
94382 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
94383 +sel_write_access_51704 sel_write_access 3 51704 NULL
94384 +sys_syslog_10746 sys_syslog 3 10746 NULL
94385 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
94386 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
94387 +do_readlink_43518 do_readlink 2 43518 NULL
94388 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
94389 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
94390 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
94391 +read_file_reset_52310 read_file_reset 3 52310 NULL
94392 +pms_capture_27142 pms_capture 4 27142 NULL
94393 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
94394 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
94395 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
94396 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
94397 +msg_set_51725 msg_set 3 51725 NULL
94398 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
94399 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
94400 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
94401 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
94402 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
94403 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
94404 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
94405 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
94406 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
94407 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
94408 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
94409 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
94410 +sys_bind_10799 sys_bind 3 10799 NULL
94411 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
94412 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
94413 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
94414 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
94415 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
94416 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
94417 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
94418 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
94419 +send_command_10832 send_command 4 10832 NULL
94420 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
94421 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
94422 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
94423 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
94424 +proc_read_43614 proc_read 3 43614 NULL
94425 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
94426 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
94427 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
94428 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
94429 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
94430 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
94431 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
94432 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
94433 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
94434 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
94435 +vmalloc_15464 vmalloc 1 15464 NULL
94436 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
94437 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
94438 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
94439 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
94440 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
94441 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
94442 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
94443 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
94444 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
94445 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
94446 +adu_write_30487 adu_write 3 30487 NULL
94447 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
94448 +get_scq_10897 get_scq 2 10897 NULL
94449 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
94450 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
94451 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
94452 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
94453 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
94454 +load_module_60056 load_module 2 60056 NULL nohasharray
94455 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
94456 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
94457 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
94458 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
94459 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
94460 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
94461 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
94462 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
94463 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
94464 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
94465 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
94466 +user_read_51881 user_read 3 51881 NULL
94467 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
94468 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
94469 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
94470 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
94471 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
94472 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
94473 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
94474 +async_setkey_35521 async_setkey 3 35521 NULL
94475 +set_dev_class_39645 set_dev_class 4 39645 NULL nohasharray
94476 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 &set_dev_class_39645
94477 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
94478 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
94479 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
94480 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
94481 +add_tty_40055 add_tty 1 40055 NULL nohasharray
94482 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
94483 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
94484 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
94485 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
94486 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
94487 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
94488 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
94489 +alloc_context_3194 alloc_context 1 3194 NULL
94490 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
94491 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
94492 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
94493 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
94494 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
94495 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
94496 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
94497 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
94498 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
94499 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
94500 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
94501 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
94502 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
94503 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
94504 +init_state_60165 init_state 2 60165 NULL
94505 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
94506 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
94507 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
94508 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
94509 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
94510 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
94511 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
94512 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
94513 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
94514 +calc_hmac_32010 calc_hmac 3 32010 NULL
94515 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
94516 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
94517 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
94518 +kernel_readv_35617 kernel_readv 3 35617 NULL
94519 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
94520 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
94521 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
94522 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
94523 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
94524 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
94525 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
94526 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
94527 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
94528 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
94529 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
94530 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
94531 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
94532 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
94533 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
94534 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
94535 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
94536 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
94537 +store_debug_level_35652 store_debug_level 3 35652 NULL
94538 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
94539 +read_flush_43851 read_flush 3 43851 NULL
94540 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
94541 +cmm_write_2896 cmm_write 3 2896 NULL
94542 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
94543 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
94544 +tunables_write_59563 tunables_write 3 59563 NULL
94545 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
94546 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
94547 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
94548 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
94549 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
94550 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
94551 +dm_table_create_35687 dm_table_create 3 35687 NULL
94552 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
94553 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
94554 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
94555 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
94556 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
94557 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
94558 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
94559 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
94560 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
94561 +debug_read_19322 debug_read 3 19322 NULL
94562 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
94563 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
94564 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
94565 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
94566 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
94567 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
94568 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
94569 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
94570 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
94571 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
94572 +doc_probe_23285 doc_probe 1 23285 NULL
94573 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
94574 +SendString_43928 SendString 3 43928 NULL
94575 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
94576 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
94577 +retry_count_read_52129 retry_count_read 3 52129 NULL
94578 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
94579 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
94580 +read_zero_19366 read_zero 3 19366 NULL
94581 +bch_alloc_4593 bch_alloc 1 4593 NULL
94582 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
94583 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
94584 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
94585 +raid5_resize_63306 raid5_resize 2 63306 NULL
94586 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
94587 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
94588 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
94589 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
94590 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
94591 +depth_write_3021 depth_write 3 3021 NULL
94592 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
94593 +read_file_stations_35795 read_file_stations 3 35795 NULL
94594 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
94595 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
94596 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
94597 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
94598 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
94599 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
94600 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
94601 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
94602 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
94603 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
94604 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
94605 +driver_names_read_60399 driver_names_read 3 60399 NULL
94606 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
94607 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
94608 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
94609 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
94610 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
94611 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
94612 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
94613 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
94614 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
94615 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
94616 +rx_data_60442 rx_data 4 60442 NULL
94617 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
94618 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
94619 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
94620 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
94621 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
94622 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
94623 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
94624 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
94625 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
94626 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
94627 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
94628 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
94629 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
94630 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
94631 +construct_key_11329 construct_key 3 11329 NULL
94632 +evm_write_key_27715 evm_write_key 3 27715 NULL
94633 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
94634 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
94635 +filldir_55137 filldir 3 55137 NULL
94636 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
94637 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
94638 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
94639 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
94640 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
94641 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
94642 +sel_write_create_11353 sel_write_create 3 11353 NULL
94643 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
94644 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
94645 +hwflags_read_52318 hwflags_read 3 52318 NULL
94646 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
94647 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
94648 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
94649 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
94650 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
94651 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
94652 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
94653 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
94654 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
94655 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
94656 +nfsd_read_19568 nfsd_read 5 19568 NULL
94657 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
94658 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
94659 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
94660 +kcalloc_27770 kcalloc 1-2 27770 NULL
94661 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
94662 +bm_status_read_19583 bm_status_read 3 19583 NULL
94663 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
94664 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
94665 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
94666 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
94667 +acl_alloc_35979 acl_alloc 1 35979 NULL
94668 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
94669 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
94670 +str_to_user_11411 str_to_user 2 11411 NULL
94671 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
94672 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
94673 +trace_options_read_11419 trace_options_read 3 11419 NULL
94674 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
94675 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
94676 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
94677 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
94678 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
94679 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
94680 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
94681 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
94682 +console_store_36007 console_store 4 36007 NULL
94683 +bttv_read_11432 bttv_read 3 11432 NULL
94684 +key_key_read_3241 key_key_read 3 3241 NULL
94685 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
94686 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
94687 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
94688 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
94689 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
94690 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
94691 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
94692 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
94693 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
94694 +um_idi_write_18293 um_idi_write 3 18293 NULL
94695 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
94696 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
94697 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
94698 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
94699 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
94700 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
94701 +sys_init_module_36047 sys_init_module 2 36047 NULL
94702 +read_profile_27859 read_profile 3 27859 NULL
94703 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
94704 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
94705 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
94706 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
94707 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
94708 +refill_pool_19477 refill_pool 2 19477 NULL
94709 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
94710 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
94711 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
94712 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
94713 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
94714 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
94715 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
94716 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
94717 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
94718 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
94719 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
94720 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
94721 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
94722 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
94723 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
94724 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
94725 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
94726 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
94727 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
94728 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
94729 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
94730 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
94731 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
94732 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
94733 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
94734 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
94735 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
94736 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
94737 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
94738 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
94739 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
94740 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
94741 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
94742 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
94743 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
94744 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
94745 +init_data_container_60709 init_data_container 1 60709 NULL
94746 +p9_client_read_19750 p9_client_read 5 19750 NULL
94747 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
94748 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
94749 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
94750 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
94751 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
94752 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
94753 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
94754 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
94755 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
94756 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
94757 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
94758 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
94759 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
94760 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
94761 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
94762 +send_stream_3397 send_stream 4 3397 NULL
94763 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
94764 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
94765 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
94766 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
94767 +msix_map_region_3411 msix_map_region 3 3411 NULL
94768 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
94769 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
94770 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
94771 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
94772 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
94773 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
94774 +opticon_write_60775 opticon_write 4 60775 NULL
94775 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
94776 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
94777 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
94778 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
94779 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
94780 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
94781 +vip_read_19832 vip_read 3 19832 NULL
94782 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
94783 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
94784 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
94785 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
94786 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
94787 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
94788 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
94789 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
94790 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
94791 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
94792 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
94793 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
94794 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
94795 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
94796 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
94797 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
94798 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
94799 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
94800 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
94801 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
94802 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
94803 +split_11691 split 2 11691 NULL
94804 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
94805 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
94806 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
94807 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
94808 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
94809 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
94810 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
94811 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
94812 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
94813 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
94814 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
94815 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
94816 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
94817 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
94818 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
94819 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
94820 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
94821 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
94822 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
94823 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
94824 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
94825 +spidev_write_44510 spidev_write 3 44510 NULL
94826 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
94827 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
94828 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
94829 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
94830 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
94831 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
94832 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
94833 +kone_receive_4690 kone_receive 4 4690 NULL
94834 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
94835 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
94836 +evtchn_read_3569 evtchn_read 3 3569 NULL
94837 +video_read_28148 video_read 3 28148 NULL
94838 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
94839 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
94840 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
94841 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
94842 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
94843 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
94844 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
94845 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
94846 +vc_resize_3585 vc_resize 2-3 3585 NULL
94847 +gluebi_write_27905 gluebi_write 3 27905 NULL
94848 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
94849 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
94850 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
94851 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
94852 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
94853 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
94854 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
94855 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
94856 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
94857 +pti_char_write_60960 pti_char_write 3 60960 NULL
94858 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
94859 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
94860 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
94861 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
94862 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
94863 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
94864 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
94865 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
94866 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
94867 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
94868 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
94869 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
94870 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
94871 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
94872 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
94873 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
94874 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
94875 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
94876 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
94877 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
94878 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
94879 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
94880 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
94881 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
94882 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
94883 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
94884 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
94885 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
94886 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
94887 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
94888 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
94889 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
94890 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
94891 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
94892 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
94893 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
94894 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
94895 +symtab_init_61050 symtab_init 2 61050 NULL
94896 +team_options_register_20091 team_options_register 3 20091 NULL
94897 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
94898 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
94899 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
94900 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
94901 +mpi_resize_44674 mpi_resize 2 44674 NULL
94902 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
94903 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
94904 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
94905 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
94906 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
94907 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
94908 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
94909 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
94910 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
94911 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
94912 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
94913 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
94914 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
94915 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
94916 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
94917 +pms_read_53873 pms_read 3 53873 NULL
94918 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
94919 +get_derived_key_61100 get_derived_key 4 61100 NULL
94920 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
94921 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
94922 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
94923 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
94924 +dm_read_15674 dm_read 3 15674 NULL
94925 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
94926 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
94927 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
94928 +kone_send_63435 kone_send 4 63435 NULL
94929 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
94930 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
94931 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
94932 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
94933 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
94934 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
94935 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
94936 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
94937 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
94938 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
94939 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
94940 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
94941 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
94942 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
94943 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
94944 +send_packet_52960 send_packet 4 52960 NULL
94945 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
94946 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
94947 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
94948 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
94949 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
94950 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
94951 +put_cmsg_36589 put_cmsg 4 36589 NULL
94952 +__vmalloc_61168 __vmalloc 1 61168 NULL
94953 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
94954 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
94955 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
94956 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
94957 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
94958 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
94959 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
94960 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
94961 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
94962 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
94963 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
94964 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
94965 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
94966 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
94967 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
94968 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
94969 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
94970 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
94971 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
94972 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
94973 +get_fd_set_3866 get_fd_set 1 3866 NULL
94974 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
94975 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
94976 +unlink_queued_645 unlink_queued 3-4 645 NULL
94977 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
94978 +sisusb_write_44834 sisusb_write 3 44834 NULL
94979 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
94980 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
94981 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
94982 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
94983 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
94984 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
94985 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
94986 +nvram_write_3894 nvram_write 3 3894 NULL
94987 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
94988 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
94989 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
94990 +vcs_write_3910 vcs_write 3 3910 NULL
94991 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
94992 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
94993 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
94994 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
94995 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
94996 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
94997 +do_tty_write_44896 do_tty_write 5 44896 NULL
94998 +set_powered_12129 set_powered 4 12129 NULL
94999 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
95000 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
95001 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
95002 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
95003 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
95004 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
95005 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
95006 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
95007 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
95008 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
95009 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
95010 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
95011 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
95012 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
95013 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
95014 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
95015 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
95016 +gather_array_56641 gather_array 3 56641 NULL
95017 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
95018 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
95019 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
95020 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
95021 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
95022 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
95023 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
95024 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
95025 +do_add_counters_3992 do_add_counters 3 3992 NULL
95026 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
95027 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
95028 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
95029 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
95030 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
95031 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
95032 +mei_write_4005 mei_write 3 4005 NULL
95033 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
95034 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
95035 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
95036 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
95037 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
95038 +receive_copy_12216 receive_copy 3 12216 NULL
95039 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
95040 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
95041 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
95042 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
95043 +change_xattr_61390 change_xattr 5 61390 NULL
95044 +find_skb_20431 find_skb 2 20431 NULL
95045 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
95046 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
95047 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
95048 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
95049 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
95050 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
95051 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
95052 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
95053 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
95054 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
95055 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
95056 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
95057 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
95058 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
95059 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
95060 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
95061 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
95062 +read_buf_20469 read_buf 2 20469 NULL
95063 +cm_write_36858 cm_write 3 36858 NULL
95064 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
95065 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
95066 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
95067 +sel_write_user_45060 sel_write_user 3 45060 NULL
95068 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
95069 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
95070 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
95071 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
95072 +fast_user_write_20494 fast_user_write 5 20494 NULL
95073 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
95074 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
95075 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
95076 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
95077 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
95078 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
95079 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
95080 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
95081 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
95082 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
95083 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
95084 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
95085 +osst_read_40237 osst_read 3 40237 NULL
95086 +tm6000_read_4151 tm6000_read 3 4151 NULL
95087 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
95088 +usbdev_read_45114 usbdev_read 3 45114 NULL
95089 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
95090 +spi_execute_28736 spi_execute 5 28736 NULL
95091 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
95092 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
95093 +get_alua_req_4166 get_alua_req 3 4166 NULL
95094 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
95095 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
95096 +venus_create_20555 venus_create 4 20555 NULL
95097 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
95098 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
95099 +receive_packet_12367 receive_packet 2 12367 NULL
95100 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
95101 +mem_write_22232 mem_write 3 22232 NULL
95102 +read_file_bool_4180 read_file_bool 3 4180 NULL
95103 +send_to_tty_45141 send_to_tty 3 45141 NULL
95104 +fops_read_40672 fops_read 3 40672 NULL
95105 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
95106 +write_leb_36957 write_leb 5 36957 NULL
95107 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
95108 +device_write_45156 device_write 3 45156 NULL
95109 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
95110 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
95111 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
95112 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
95113 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
95114 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
95115 +isp1760_register_628 isp1760_register 1-2 628 NULL
95116 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
95117 +lirc_write_20604 lirc_write 3 20604 NULL
95118 +sel_write_member_28800 sel_write_member 3 28800 NULL
95119 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
95120 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
95121 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
95122 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
95123 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
95124 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
95125 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
95126 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
95127 +setxattr_37006 setxattr 4 37006 NULL
95128 +add_child_45201 add_child 4 45201 NULL
95129 +seq_open_private_61589 seq_open_private 3 61589 NULL
95130 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
95131 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
95132 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
95133 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
95134 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
95135 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
95136 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
95137 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
95138 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
95139 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
95140 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
95141 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
95142 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
95143 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
95144 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
95145 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
95146 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
95147 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
95148 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
95149 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
95150 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
95151 +resize_stripes_61650 resize_stripes 2 61650 NULL
95152 +n2_run_53459 n2_run 3 53459 NULL
95153 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
95154 +parse_command_37079 parse_command 2 37079 NULL
95155 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
95156 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
95157 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
95158 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
95159 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
95160 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
95161 +insert_one_name_61668 insert_one_name 7 61668 NULL
95162 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
95163 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
95164 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
95165 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
95166 +lock_loop_61681 lock_loop 1 61681 NULL
95167 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
95168 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
95169 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
95170 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
95171 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
95172 +push_rx_28939 push_rx 3 28939 NULL
95173 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
95174 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
95175 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
95176 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
95177 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
95178 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
95179 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
95180 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
95181 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
95182 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
95183 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
95184 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
95185 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
95186 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
95187 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
95188 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
95189 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
95190 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
95191 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
95192 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
95193 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
95194 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
95195 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
95196 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
95197 +bin_uuid_28999 bin_uuid 3 28999 NULL
95198 +sys_sendto_20809 sys_sendto 6 20809 NULL
95199 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
95200 +set_registers_53582 set_registers 3 53582 NULL
95201 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
95202 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
95203 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
95204 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
95205 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
95206 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
95207 +keymap_store_45406 keymap_store 4 45406 NULL
95208 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
95209 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
95210 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
95211 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
95212 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
95213 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
95214 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
95215 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
95216 +__do_replace_37227 __do_replace 5 37227 NULL
95217 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
95218 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
95219 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
95220 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
95221 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
95222 +tso_fragment_29050 tso_fragment 3 29050 NULL
95223 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
95224 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
95225 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
95226 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
95227 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
95228 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
95229 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
95230 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
95231 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
95232 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
95233 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
95234 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
95235 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
95236 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
95237 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
95238 +set_link_security_4502 set_link_security 4 4502 NULL
95239 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
95240 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
95241 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
95242 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
95243 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
95244 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
95245 +mmio_read_40348 mmio_read 4 40348 NULL
95246 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
95247 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
95248 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
95249 +ivtv_write_12721 ivtv_write 3 12721 NULL
95250 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
95251 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
95252 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
95253 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
95254 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
95255 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
95256 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
95257 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
95258 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
95259 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
95260 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
95261 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
95262 +send_msg_37323 send_msg 4 37323 NULL
95263 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
95264 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
95265 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
95266 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
95267 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
95268 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
95269 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
95270 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
95271 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
95272 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
95273 +reshape_ring_29147 reshape_ring 2 29147 NULL
95274 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
95275 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
95276 +copy_macs_45534 copy_macs 4 45534 NULL
95277 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
95278 +listxattr_12769 listxattr 3 12769 NULL
95279 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
95280 +wdm_write_53735 wdm_write 3 53735 NULL
95281 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
95282 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
95283 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
95284 +mempool_create_29437 mempool_create 1 29437 NULL
95285 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
95286 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
95287 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
95288 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
95289 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
95290 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
95291 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
95292 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
95293 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
95294 +mgmt_event_12810 mgmt_event 4 12810 NULL
95295 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
95296 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
95297 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
95298 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
95299 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
95300 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
95301 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
95302 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
95303 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
95304 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
95305 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
95306 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
95307 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
95308 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
95309 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
95310 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
95311 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
95312 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
95313 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
95314 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
95315 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
95316 +recover_peb_29238 recover_peb 6-7 29238 NULL
95317 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
95318 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
95319 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
95320 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
95321 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
95322 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
95323 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
95324 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
95325 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
95326 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
95327 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
95328 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
95329 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
95330 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
95331 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
95332 +do_pselect_62061 do_pselect 1 62061 NULL
95333 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
95334 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
95335 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
95336 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
95337 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
95338 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
95339 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
95340 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
95341 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
95342 +sg_read_25799 sg_read 3 25799 NULL
95343 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
95344 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
95345 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
95346 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
95347 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
95348 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
95349 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
95350 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
95351 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
95352 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
95353 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
95354 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
95355 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
95356 +new_skb_21148 new_skb 1 21148 NULL
95357 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
95358 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
95359 +bm_status_write_12964 bm_status_write 3 12964 NULL
95360 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
95361 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
95362 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
95363 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
95364 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
95365 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
95366 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
95367 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
95368 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
95369 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
95370 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
95371 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
95372 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
95373 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
95374 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
95375 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
95376 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
95377 +video_usercopy_62151 video_usercopy 2 62151 NULL
95378 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
95379 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
95380 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
95381 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
95382 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
95383 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
95384 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
95385 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
95386 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
95387 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
95388 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
95389 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
95390 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
95391 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
95392 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
95393 +input_ff_create_21240 input_ff_create 2 21240 NULL
95394 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
95395 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
95396 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
95397 +amthi_read_45831 amthi_read 4 45831 NULL
95398 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
95399 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
95400 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
95401 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
95402 +sys_ipc_4889 sys_ipc 3 4889 NULL
95403 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
95404 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
95405 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
95406 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
95407 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
95408 +do_register_entry_29478 do_register_entry 4 29478 NULL
95409 +isdn_write_45863 isdn_write 3 45863 NULL
95410 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
95411 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
95412 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
95413 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
95414 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
95415 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
95416 +_malloc_54077 _malloc 1 54077 NULL
95417 +add_res_range_21310 add_res_range 4 21310 NULL
95418 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
95419 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
95420 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
95421 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
95422 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
95423 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
95424 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
95425 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
95426 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
95427 +create_xattr_54106 create_xattr 5 54106 NULL
95428 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
95429 +ep_write_59008 ep_write 3 59008 NULL
95430 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
95431 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
95432 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
95433 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
95434 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
95435 +alloc_mr_45935 alloc_mr 1 45935 NULL
95436 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
95437 +isku_receive_54130 isku_receive 4 54130 NULL
95438 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
95439 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
95440 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
95441 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
95442 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
95443 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
95444 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
95445 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
95446 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
95447 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
95448 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
95449 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
95450 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
95451 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
95452 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
95453 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
95454 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
95455 +comedi_read_13199 comedi_read 3 13199 NULL
95456 +flash_write_62354 flash_write 3 62354 NULL
95457 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
95458 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
95459 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
95460 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
95461 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
95462 +proc_file_read_53905 proc_file_read 3 53905 NULL
95463 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
95464 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
95465 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
95466 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
95467 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
95468 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
95469 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
95470 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
95471 +cru_detect_11272 cru_detect 1 11272 NULL
95472 +altera_irscan_62396 altera_irscan 2 62396 NULL
95473 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
95474 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
95475 +fw_download_code_13249 fw_download_code 3 13249 NULL
95476 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
95477 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
95478 +set_ssp_62411 set_ssp 4 62411 NULL
95479 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
95480 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
95481 +get_free_entries_46030 get_free_entries 1 46030 NULL
95482 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
95483 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
95484 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
95485 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
95486 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
95487 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
95488 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
95489 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
95490 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
95491 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
95492 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
95493 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
95494 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
95495 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
95496 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
95497 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
95498 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
95499 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
95500 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
95501 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
95502 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
95503 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
95504 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
95505 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
95506 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
95507 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
95508 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
95509 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
95510 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
95511 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
95512 +probes_write_29711 probes_write 3 29711 NULL
95513 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
95514 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
95515 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
95516 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
95517 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
95518 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
95519 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
95520 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
95521 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
95522 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
95523 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
95524 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
95525 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
95526 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
95527 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
95528 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
95529 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
95530 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
95531 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
95532 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
95533 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
95534 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
95535 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
95536 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
95537 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
95538 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
95539 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
95540 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
95541 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
95542 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
95543 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
95544 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
95545 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
95546 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
95547 +isdn_read_50021 isdn_read 3 50021 NULL
95548 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
95549 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
95550 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
95551 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
95552 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
95553 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
95554 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
95555 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
95556 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
95557 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
95558 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
95559 +get_subdir_62581 get_subdir 3 62581 NULL
95560 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
95561 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
95562 +vfs_readv_38011 vfs_readv 3 38011 NULL
95563 +keyring_read_13438 keyring_read 3 13438 NULL
95564 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
95565 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
95566 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
95567 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
95568 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
95569 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
95570 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
95571 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
95572 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
95573 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
95574 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
95575 +ftrace_write_29551 ftrace_write 3 29551 NULL
95576 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
95577 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
95578 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
95579 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
95580 +dev_write_7708 dev_write 3 7708 NULL
95581 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
95582 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
95583 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
95584 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
95585 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
95586 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
95587 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
95588 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
95589 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
95590 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
95591 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
95592 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
95593 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
95594 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
95595 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
95596 +bm_init_13529 bm_init 2 13529 NULL
95597 +check586_29914 check586 2 29914 NULL
95598 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
95599 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
95600 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
95601 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
95602 +pg_read_17276 pg_read 3 17276 NULL
95603 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
95604 +ep0_read_38095 ep0_read 3 38095 NULL
95605 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
95606 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
95607 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
95608 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
95609 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
95610 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
95611 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
95612 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
95613 +l2down_create_21755 l2down_create 4 21755 NULL
95614 +alloc_tio_13564 alloc_tio 3 13564 NULL
95615 +viacam_read_54526 viacam_read 3 54526 NULL
95616 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
95617 +tunables_read_36385 tunables_read 3 36385 NULL
95618 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
95619 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
95620 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
95621 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
95622 +setsockopt_54539 setsockopt 5 54539 NULL
95623 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
95624 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
95625 +tty_register_device_4544 tty_register_device 2 4544 NULL
95626 +cache_write_13589 cache_write 3 13589 NULL
95627 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
95628 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
95629 +key_replays_read_62746 key_replays_read 3 62746 NULL
95630 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
95631 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
95632 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
95633 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
95634 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
95635 +cdev_add_38176 cdev_add 2-3 38176 NULL
95636 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
95637 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
95638 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
95639 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
95640 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
95641 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
95642 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
95643 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
95644 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
95645 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
95646 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
95647 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
95648 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
95649 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
95650 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
95651 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
95652 +packet_snd_13634 packet_snd 3 13634 NULL
95653 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
95654 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
95655 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
95656 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
95657 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
95658 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
95659 +drp_wmove_30043 drp_wmove 4 30043 NULL
95660 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
95661 +cache_downcall_13666 cache_downcall 3 13666 NULL
95662 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
95663 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
95664 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
95665 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
95666 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
95667 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
95668 +tty_write_5494 tty_write 3 5494 NULL
95669 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
95670 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
95671 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
95672 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
95673 +teiup_create_43201 teiup_create 3 43201 NULL
95674 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
95675 +filldir64_46469 filldir64 3 46469 NULL
95676 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
95677 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
95678 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
95679 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
95680 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
95681 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
95682 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
95683 +spidev_message_5518 spidev_message 3 5518 NULL
95684 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
95685 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
95686 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
95687 +evm_read_key_54674 evm_read_key 3 54674 NULL
95688 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
95689 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
95690 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
95691 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
95692 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 NULL nohasharray
95693 +aoechr_write_62883 aoechr_write 3 62883 &em28xx_init_isoc_62883
95694 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
95695 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
95696 +u32_array_read_2219 u32_array_read 3 2219 NULL
95697 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
95698 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
95699 +sys_add_key_61288 sys_add_key 4 61288 NULL
95700 +kmsg_read_46514 kmsg_read 3 46514 NULL
95701 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
95702 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
95703 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
95704 +recv_stream_30138 recv_stream 4 30138 NULL
95705 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
95706 +getdqbuf_62908 getdqbuf 1 62908 NULL
95707 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
95708 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
95709 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
95710 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
95711 +fir16_create_5574 fir16_create 3 5574 NULL
95712 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
95713 +pt_write_40159 pt_write 3 40159 NULL
95714 +bioset_create_5580 bioset_create 1 5580 NULL
95715 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
95716 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
95717 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
95718 +kzalloc_54740 kzalloc 1 54740 NULL
95719 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
95720 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
95721 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
95722 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
95723 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
95724 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
95725 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
95726 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
95727 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
95728 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
95729 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
95730 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
95731 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
95732 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
95733 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
95734 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
95735 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
95736 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
95737 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
95738 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
95739 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
95740 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
95741 +ti_recv_22027 ti_recv 4 22027 NULL
95742 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
95743 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
95744 +nfsd_write_54809 nfsd_write 6 54809 NULL
95745 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
95746 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
95747 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
95748 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
95749 +get_skb_63008 get_skb 2 63008 NULL
95750 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
95751 +netlink_send_38434 netlink_send 5 38434 NULL
95752 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
95753 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
95754 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
95755 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
95756 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
95757 +write_rio_54837 write_rio 3 54837 NULL
95758 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
95759 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
95760 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
95761 +get_arg_5694 get_arg 3 5694 NULL
95762 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
95763 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
95764 +compat_readv_30273 compat_readv 3 30273 NULL
95765 +printer_read_54851 printer_read 3 54851 NULL
95766 +mem_rw_22085 mem_rw 3 22085 NULL
95767 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
95768 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
95769 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
95770 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
95771 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
95772 +unlink1_63059 unlink1 3 63059 NULL
95773 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
95774 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
95775 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
95776 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
95777 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
95778 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
95779 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
95780 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
95781 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
95782 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
95783 +dev_names_read_38509 dev_names_read 3 38509 NULL
95784 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
95785 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
95786 +get_packet_5747 get_packet 3 5747 NULL
95787 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
95788 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
95789 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
95790 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
95791 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
95792 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
95793 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
95794 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
95795 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
95796 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
95797 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
95798 +resource_from_user_30341 resource_from_user 3 30341 NULL
95799 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
95800 +sound_write_5102 sound_write 3 5102 NULL
95801 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
95802 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
95803 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
95804 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
95805 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
95806 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
95807 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
95808 +com90xx_found_13974 com90xx_found 3 13974 NULL
95809 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
95810 +qcam_read_13977 qcam_read 3 13977 NULL
95811 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
95812 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
95813 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
95814 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
95815 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
95816 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
95817 +generic_readlink_32654 generic_readlink 3 32654 NULL
95818 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
95819 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
95820 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
95821 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
95822 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
95823 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
95824 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
95825 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
95826 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
95827 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
95828 +concat_writev_21451 concat_writev 3 21451 NULL
95829 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
95830 +_queue_data_54983 _queue_data 4 54983 NULL
95831 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
95832 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
95833 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
95834 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
95835 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
95836 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
95837 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
95838 +setup_req_5848 setup_req 3 5848 NULL
95839 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
95840 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
95841 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
95842 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
95843 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
95844 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
95845 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
95846 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
95847 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
95848 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
95849 +cma_create_area_38642 cma_create_area 2 38642 NULL
95850 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
95851 +sriov_enable_59689 sriov_enable 2 59689 NULL
95852 +enable_write_30456 enable_write 3 30456 NULL
95853 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
95854 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
95855 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
95856 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
95857 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
95858 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
95859 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
95860 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
95861 +port_show_regs_5904 port_show_regs 3 5904 NULL
95862 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
95863 +ptp_read_63251 ptp_read 4 63251 NULL
95864 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
95865 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
95866 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
95867 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
95868 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
95869 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
95870 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
95871 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
95872 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
95873 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
95874 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
95875 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
95876 +read_dma_55086 read_dma 3 55086 NULL
95877 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
95878 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
95879 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
95880 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
95881 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
95882 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
95883 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
95884 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
95885 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
95886 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
95887 +em_canid_change_14150 em_canid_change 3 14150 NULL
95888 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
95889 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
95890 +fb_write_46924 fb_write 3 46924 NULL
95891 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
95892 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
95893 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
95894 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
95895 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
95896 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
95897 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
95898 +udf_readpages_38761 udf_readpages 4 38761 NULL
95899 +reada_add_block_54247 reada_add_block 2 54247 NULL
95900 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
95901 +proc_info_read_63344 proc_info_read 3 63344 NULL
95902 +pep_indicate_38611 pep_indicate 5 38611 NULL
95903 +set_le_30581 set_le 4 30581 NULL
95904 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
95905 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
95906 +alloc_private_22399 alloc_private 2 22399 NULL
95907 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
95908 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
95909 +zoran_write_22404 zoran_write 3 22404 NULL
95910 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
95911 +idmouse_read_63374 idmouse_read 3 63374 NULL
95912 +queue_reply_22416 queue_reply 3 22416 NULL
95913 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
95914 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
95915 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
95916 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
95917 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
95918 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
95919 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
95920 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
95921 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
95922 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
95923 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
95924 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
95925 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
95926 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
95927 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
95928 +sys_select_38827 sys_select 1 38827 NULL
95929 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
95930 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
95931 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
95932 +direct_entry_38836 direct_entry 3 38836 NULL
95933 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
95934 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
95935 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
95936 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
95937 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
95938 +write_head_30481 write_head 4 30481 NULL
95939 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
95940 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
95941 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
95942 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
95943 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
95944 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
95945 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
95946 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
95947 +agp_remap_30665 agp_remap 2 30665 NULL
95948 +interfaces_38859 interfaces 2 38859 NULL
95949 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
95950 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
95951 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
95952 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
95953 +qc_capture_19298 qc_capture 3 19298 NULL
95954 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
95955 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
95956 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
95957 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
95958 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
95959 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
95960 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
95961 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
95962 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
95963 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
95964 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
95965 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
95966 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
95967 +read_kcore_63488 read_kcore 3 63488 NULL
95968 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
95969 +__skb_cow_39254 __skb_cow 2 39254 NULL
95970 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
95971 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
95972 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
95973 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
95974 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
95975 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
95976 +mousedev_read_47123 mousedev_read 3 47123 NULL
95977 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
95978 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
95979 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
95980 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
95981 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
95982 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
95983 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
95984 +vme_user_read_55338 vme_user_read 3 55338 NULL
95985 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
95986 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
95987 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
95988 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
95989 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
95990 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
95991 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
95992 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
95993 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
95994 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
95995 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
95996 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
95997 +snapshot_read_22601 snapshot_read 3 22601 NULL
95998 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
95999 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
96000 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
96001 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
96002 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
96003 +__send_to_port_55383 __send_to_port 3 55383 NULL
96004 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
96005 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
96006 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
96007 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
96008 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
96009 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
96010 +get_nodes_39012 get_nodes 3 39012 NULL
96011 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
96012 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
96013 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
96014 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
96015 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
96016 +create_subvol_30836 create_subvol 4 30836 NULL
96017 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
96018 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
96019 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
96020 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
96021 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
96022 +read_oldmem_55658 read_oldmem 3 55658 NULL
96023 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
96024 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
96025 +options_write_47243 options_write 3 47243 NULL
96026 +module_alloc_63630 module_alloc 1 63630 NULL
96027 +alloc_skb_55439 alloc_skb 1 55439 NULL
96028 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
96029 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
96030 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
96031 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
96032 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
96033 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
96034 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
96035 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
96036 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
96037 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
96038 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
96039 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
96040 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
96041 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
96042 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
96043 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
96044 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
96045 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
96046 +vbi_read_63673 vbi_read 3 63673 NULL
96047 +tun_get_user_39099 tun_get_user 4 39099 NULL
96048 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
96049 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
96050 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
96051 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
96052 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
96053 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
96054 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
96055 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
96056 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 &ep0_write_14536
96057 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
96058 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
96059 +ax25_output_22736 ax25_output 2 22736 NULL
96060 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
96061 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
96062 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
96063 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
96064 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
96065 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
96066 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
96067 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
96068 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
96069 +hid_input_report_32458 hid_input_report 4 32458 NULL
96070 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
96071 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
96072 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
96073 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
96074 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
96075 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
96076 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
96077 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
96078 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
96079 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
96080 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
96081 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
96082 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
96083 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
96084 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
96085 +get_info_55681 get_info 3 55681 NULL
96086 +setkey_14987 setkey 3 14987 NULL
96087 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
96088 +init_list_set_39188 init_list_set 2-3 39188 NULL
96089 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
96090 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
96091 +l2up_create_6430 l2up_create 3 6430 NULL
96092 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
96093 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
96094 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
96095 +add_partition_55588 add_partition 2 55588 NULL
96096 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
96097 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
96098 +depth_read_31112 depth_read 3 31112 NULL
96099 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
96100 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
96101 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
96102 +profile_replace_14652 profile_replace 3 14652 NULL
96103 +vzalloc_47421 vzalloc 1 47421 NULL
96104 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
96105 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
96106 +sys_writev_28384 sys_writev 3 28384 NULL
96107 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
96108 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
96109 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
96110 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
96111 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
96112 +create_attr_set_22861 create_attr_set 1 22861 NULL
96113 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
96114 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
96115 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
96116 +sel_write_load_63830 sel_write_load 3 63830 NULL
96117 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
96118 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
96119 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
96120 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
96121 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
96122 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
96123 +probe_bios_17467 probe_bios 1 17467 NULL
96124 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
96125 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
96126 +mei_read_6507 mei_read 3 6507 NULL
96127 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
96128 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
96129 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
96130 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
96131 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
96132 +SetArea_50835 SetArea 4 50835 NULL
96133 +tpm_read_50344 tpm_read 3 50344 NULL
96134 +newpart_47485 newpart 6 47485 NULL
96135 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
96136 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
96137 +core_sys_select_47494 core_sys_select 1 47494 NULL
96138 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
96139 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
96140 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
96141 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
96142 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
96143 +unlink_simple_47506 unlink_simple 3 47506 NULL
96144 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
96145 +wdm_read_6549 wdm_read 3 6549 NULL
96146 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
96147 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
96148 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
96149 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
96150 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
96151 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
96152 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
96153 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
96154 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
96155 +filter_read_61692 filter_read 3 61692 NULL
96156 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
96157 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
96158 +debugfs_read_62535 debugfs_read 3 62535 NULL
96159 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
96160 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
96161 +divas_write_63901 divas_write 3 63901 NULL
96162 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
96163 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
96164 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
96165 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
96166 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
96167 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
96168 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
96169 +ipw_write_59807 ipw_write 3 59807 NULL
96170 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
96171 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
96172 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
96173 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
96174 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
96175 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
96176 +cycx_setup_47562 cycx_setup 4 47562 NULL
96177 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
96178 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
96179 +set_local_name_55757 set_local_name 4 55757 NULL
96180 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
96181 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
96182 +read_ldt_47570 read_ldt 2 47570 NULL
96183 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
96184 +pci_iomap_47575 pci_iomap 3 47575 NULL
96185 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
96186 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
96187 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
96188 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
96189 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
96190 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
96191 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
96192 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
96193 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
96194 +conf_read_55786 conf_read 3 55786 NULL
96195 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
96196 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
96197 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
96198 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
96199 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
96200 +user_power_read_39414 user_power_read 3 39414 NULL
96201 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
96202 +uea_request_47613 uea_request 4 47613 NULL
96203 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
96204 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
96205 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
96206 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
96207 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
96208 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
96209 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
96210 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
96211 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
96212 +kmemdup_64015 kmemdup 2 64015 NULL
96213 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
96214 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
96215 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
96216 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
96217 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
96218 +oz_events_read_47535 oz_events_read 3 47535 NULL
96219 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
96220 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
96221 +sys_semop_39457 sys_semop 3 39457 NULL
96222 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
96223 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
96224 +update_pmkid_2481 update_pmkid 4 2481 NULL
96225 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
96226 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
96227 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
96228 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
96229 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
96230 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
96231 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
96232 +mpeg_read_6708 mpeg_read 3 6708 NULL
96233 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
96234 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
96235 +sky2_receive_13407 sky2_receive 2 13407 NULL
96236 +krealloc_14908 krealloc 2 14908 NULL
96237 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
96238 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
96239 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
96240 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
96241 +video_proc_write_6724 video_proc_write 3 6724 NULL
96242 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
96243 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
96244 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
96245 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
96246 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
96247 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
96248 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
96249 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
96250 +command_file_write_31318 command_file_write 3 31318 NULL
96251 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
96252 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
96253 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
96254 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
96255 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
96256 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
96257 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
96258 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
96259 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
96260 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
96261 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
96262 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
96263 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
96264 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
96265 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
96266 +int_proc_write_39542 int_proc_write 3 39542 NULL
96267 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
96268 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
96269 +read_file_ani_23161 read_file_ani 3 23161 NULL
96270 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
96271 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
96272 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
96273 +pp_write_39554 pp_write 3 39554 NULL
96274 +ioremap_23172 ioremap 1-2 23172 NULL
96275 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
96276 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
96277 +usblp_write_23178 usblp_write 3 23178 NULL
96278 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
96279 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
96280 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
96281 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
96282 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
96283 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
96284 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
96285 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
96286 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
96287 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
96288 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
96289 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
96290 +__team_options_register_63941 __team_options_register 3 63941 NULL
96291 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
96292 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
96293 +rvmalloc_46873 rvmalloc 1 46873 NULL
96294 +vmap_15025 vmap 2 15025 NULL
96295 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
96296 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
96297 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
96298 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
96299 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
96300 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
96301 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
96302 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
96303 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
96304 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
96305 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
96306 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
96307 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
96308 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
96309 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
96310 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
96311 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
96312 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
96313 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
96314 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
96315 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
96316 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
96317 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
96318 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
96319 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
96320 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
96321 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
96322 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
96323 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
96324 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
96325 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
96326 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
96327 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
96328 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
96329 +alg_setkey_31485 alg_setkey 3 31485 NULL
96330 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
96331 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
96332 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
96333 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
96334 +vhci_read_47878 vhci_read 3 47878 NULL
96335 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
96336 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
96337 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
96338 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
96339 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
96340 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
96341 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
96342 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
96343 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
96344 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
96345 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
96346 +timeout_read_47915 timeout_read 3 47915 NULL
96347 +hidraw_write_31536 hidraw_write 3 31536 NULL
96348 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
96349 +page_readlink_23346 page_readlink 3 23346 NULL
96350 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
96351 +comedi_write_47926 comedi_write 3 47926 NULL
96352 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
96353 +dsp_write_46218 dsp_write 2 46218 NULL
96354 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
96355 +usbvision_read_31555 usbvision_read 3 31555 NULL
96356 +pd_video_read_24510 pd_video_read 3 24510 NULL
96357 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
96358 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
96359 +request_key_async_6990 request_key_async 4 6990 NULL
96360 +ts_write_64336 ts_write 3 64336 NULL
96361 +handle_response_55951 handle_response 5 55951 NULL
96362 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
96363 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
96364 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
96365 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
96366 +osst_write_31581 osst_write 3 31581 NULL
96367 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
96368 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
96369 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
96370 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
96371 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
96372 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
96373 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
96374 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
96375 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
96376 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
96377 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
96378 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
96379 +ilo_write_64378 ilo_write 3 64378 NULL
96380 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
96381 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
96382 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
96383 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
96384 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
96385 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
96386 +copy_from_user_17559 copy_from_user 3 17559 NULL
96387 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
96388 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
96389 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
96390 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
96391 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
96392 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
96393 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
96394 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
96395 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
96396 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
96397 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
96398 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
96399 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
96400 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
96401 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
96402 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
96403 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
96404 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
96405 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
96406 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
96407 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
96408 +__lgread_31668 __lgread 4 31668 NULL
96409 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
96410 +fd_copyin_56247 fd_copyin 3 56247 NULL
96411 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
96412 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
96413 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
96414 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
96415 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
96416 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
96417 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
96418 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
96419 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
96420 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
96421 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
96422 +event_filter_read_23494 event_filter_read 3 23494 NULL
96423 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
96424 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
96425 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
96426 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
96427 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
96428 +pkt_add_39897 pkt_add 3 39897 NULL
96429 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
96430 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
96431 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
96432 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
96433 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
96434 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
96435 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
96436 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
96437 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
96438 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
96439 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
96440 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
96441 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
96442 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
96443 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
96444 +remove_uuid_64505 remove_uuid 4 64505 NULL
96445 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
96446 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
96447 +create_table_16213 create_table 2 16213 NULL
96448 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
96449 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
96450 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
96451 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
96452 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
96453 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
96454 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
96455 +set_discoverable_48141 set_discoverable 4 48141 NULL
96456 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
96457 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
96458 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
96459 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
96460 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
96461 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
96462 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
96463 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
96464 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
96465 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
96466 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
96467 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
96468 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
96469 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
96470 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
96471 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
96472 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
96473 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
96474 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
96475 +dev_read_56369 dev_read 3 56369 NULL
96476 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
96477 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
96478 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
96479 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
96480 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
96481 +init_ipath_48187 init_ipath 1 48187 NULL
96482 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
96483 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
96484 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
96485 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
96486 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
96487 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
96488 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
96489 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
96490 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
96491 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
96492 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
96493 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
96494 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
96495 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
96496 +use_pool_64607 use_pool 2 64607 NULL
96497 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
96498 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
96499 +store_msg_56417 store_msg 3 56417 NULL
96500 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
96501 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
96502 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
96503 +read_file_recv_48232 read_file_recv 3 48232 NULL
96504 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
96505 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
96506 +fanotify_write_64623 fanotify_write 3 64623 NULL
96507 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
96508 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
96509 +fl_create_56435 fl_create 5 56435 NULL
96510 +gnttab_map_56439 gnttab_map 2 56439 NULL
96511 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
96512 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
96513 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
96514 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
96515 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
96516 +set_connectable_56458 set_connectable 4 56458 NULL
96517 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
96518 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
96519 +add_port_54941 add_port 2 54941 NULL
96520 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
96521 +cx18_read_23699 cx18_read 3 23699 NULL
96522 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
96523 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
96524 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
96525 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
96526 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
96527 +send_set_info_48288 send_set_info 7 48288 NULL
96528 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
96529 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
96530 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
96531 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
96532 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
96533 +new_dir_31919 new_dir 3 31919 NULL
96534 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
96535 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
96536 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
96537 +mgmt_control_7349 mgmt_control 3 7349 NULL
96538 +hash_setkey_48310 hash_setkey 3 48310 NULL
96539 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
96540 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
96541 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
96542 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
96543 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
96544 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
96545 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
96546 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
96547 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
96548 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
96549 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
96550 +vb2_write_31948 vb2_write 3 31948 NULL
96551 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
96552 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
96553 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
96554 +ip_options_get_56538 ip_options_get 4 56538 NULL
96555 +write_62671 write 3 62671 NULL
96556 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
96557 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
96558 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
96559 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
96560 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
96561 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
96562 +skb_add_data_48363 skb_add_data 3 48363 NULL
96563 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
96564 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
96565 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
96566 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
96567 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
96568 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
96569 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
96570 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
96571 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
96572 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
96573 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
96574 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
96575 +system_enable_read_25815 system_enable_read 3 25815 NULL
96576 +allocate_probes_40204 allocate_probes 1 40204 NULL
96577 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
96578 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
96579 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
96580 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
96581 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
96582 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
96583 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
96584 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
96585 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
96586 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
96587 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
96588 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
96589 +fs_path_add_15648 fs_path_add 3 15648 NULL
96590 +event_filter_write_56609 event_filter_write 3 56609 NULL
96591 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
96592 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
96593 +xsd_read_15653 xsd_read 3 15653 NULL
96594 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
96595 +p54_init_common_23850 p54_init_common 1 23850 NULL
96596 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
96597 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
96598 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
96599 +garp_request_join_7471 garp_request_join 4 7471 NULL
96600 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
96601 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
96602 +unifi_read_14899 unifi_read 3 14899 NULL
96603 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
96604 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
96605 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
96606 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
96607 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
96608 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
96609 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
96610 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
96611 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
96612 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
96613 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
96614 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
96615 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
96616 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
96617 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
96618 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
96619 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
96620 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
96621 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
96622 +bio_alloc_32095 bio_alloc 2 32095 NULL
96623 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
96624 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
96625 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
96626 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
96627 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
96628 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
96629 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
96630 +send_control_msg_48498 send_control_msg 6 48498 NULL
96631 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
96632 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
96633 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
96634 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
96635 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
96636 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
96637 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
96638 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
96639 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
96640 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
96641 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
96642 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
96643 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
96644 +alloc_tx_32143 alloc_tx 2 32143 NULL
96645 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
96646 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
96647 +hsc_write_55875 hsc_write 3 55875 NULL
96648 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
96649 +do_test_15766 do_test 1 15766 NULL
96650 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
96651 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
96652 +named_distribute_48544 named_distribute 4 48544 NULL
96653 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
96654 +venus_link_32165 venus_link 5 32165 NULL
96655 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
96656 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
96657 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
96658 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
96659 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
96660 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
96661 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
96662 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
96663 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
96664 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
96665 +groups_alloc_7614 groups_alloc 1 7614 NULL
96666 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
96667 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
96668 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
96669 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
96670 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
96671 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
96672 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
96673 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
96674 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
96675 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
96676 +snapshot_write_28351 snapshot_write 3 28351 NULL
96677 +event_enable_read_7074 event_enable_read 3 7074 NULL
96678 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
96679 +do_syslog_56807 do_syslog 3 56807 NULL
96680 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
96681 +pskb_pull_65005 pskb_pull 2 65005 NULL
96682 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
96683 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
96684 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
96685 +unifi_write_65012 unifi_write 3 65012 NULL
96686 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
96687 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
96688 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
96689 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
96690 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
96691 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
96692 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
96693 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
96694 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
96695 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
96696 +if_write_51756 if_write 3 51756 NULL
96697 +insert_dent_65034 insert_dent 7 65034 NULL
96698 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
96699 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
96700 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
96701 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
96702 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
96703 +lc_create_48662 lc_create 3 48662 NULL
96704 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
96705 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
96706 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
96707 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
96708 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
96709 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
96710 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
96711 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
96712 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
96713 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
96714 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
96715 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
96716 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
96717 +altera_drscan_48698 altera_drscan 2 48698 NULL
96718 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
96719 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
96720 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
96721 +power_read_15939 power_read 3 15939 NULL
96722 +recv_msg_48709 recv_msg 4 48709 NULL
96723 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
96724 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
96725 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
96726 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
96727 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
96728 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
96729 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
96730 +revalidate_19043 revalidate 2 19043 NULL
96731 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
96732 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
96733 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
96734 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
96735 +check_header_56930 check_header 2 56930 NULL
96736 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
96737 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
96738 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
96739 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
96740 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
96741 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
96742 +frame_alloc_15981 frame_alloc 4 15981 NULL
96743 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
96744 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
96745 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
96746 +adu_read_24177 adu_read 3 24177 NULL
96747 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
96748 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
96749 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
96750 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
96751 +vfd_write_14717 vfd_write 3 14717 NULL
96752 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
96753 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
96754 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
96755 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
96756 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
96757 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
96758 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
96759 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
96760 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
96761 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
96762 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
96763 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
96764 +register_device_60015 register_device 2-3 60015 NULL
96765 +got_frame_16028 got_frame 2 16028 NULL
96766 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
96767 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
96768 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
96769 +scsi_register_49094 scsi_register 2 49094 NULL
96770 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
96771 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
96772 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
96773 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
96774 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
96775 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
96776 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
96777 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
96778 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
96779 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
96780 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
96781 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
96782 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
96783 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
96784 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
96785 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
96786 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
96787 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
96788 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
96789 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
96790 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
96791 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
96792 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
96793 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
96794 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
96795 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
96796 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
96797 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
96798 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
96799 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
96800 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
96801 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
96802 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
96803 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
96804 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
96805 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
96806 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
96807 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
96808 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
96809 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
96810 +fsm_init_16134 fsm_init 2 16134 NULL
96811 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
96812 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
96813 +disconnect_32521 disconnect 4 32521 NULL
96814 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
96815 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
96816 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
96817 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
96818 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
96819 +ilo_read_32531 ilo_read 3 32531 NULL
96820 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
96821 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
96822 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
96823 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
96824 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
96825 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
96826 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
96827 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
96828 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
96829 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
96830 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
96831 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
96832 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
96833 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
96834 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
96835 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
96836 +card_send_command_40757 card_send_command 3 40757 NULL
96837 +sys_mbind_7990 sys_mbind 5 7990 NULL
96838 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
96839 +pg_write_40766 pg_write 3 40766 NULL
96840 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
96841 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
96842 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
96843 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
96844 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
96845 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
96846 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
96847 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
96848 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
96849 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
96850 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
96851 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
96852 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
96853 +vcs_read_8017 vcs_read 3 8017 NULL
96854 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
96855 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
96856 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
96857 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
96858 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
96859 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
96860 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
96861 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
96862 +copy_and_check_19089 copy_and_check 3 19089 NULL
96863 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
96864 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
96865 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
96866 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
96867 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
96868 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
96869 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
96870 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
96871 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
96872 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
96873 +smk_user_access_24440 smk_user_access 3 24440 NULL
96874 +xd_rw_49020 xd_rw 3-4 49020 NULL
96875 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
96876 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
96877 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
96878 +kvmalloc_32646 kvmalloc 1 32646 NULL
96879 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
96880 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
96881 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
96882 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
96883 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
96884 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
96885 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
96886 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
96887 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
96888 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
96889 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
96890 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
96891 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
96892 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
96893 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
96894 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
96895 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
96896 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
96897 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
96898 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
96899 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
96900 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
96901 +venus_lookup_8121 venus_lookup 4 8121 NULL
96902 +compat_writev_60063 compat_writev 3 60063 NULL
96903 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
96904 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
96905 +read_file_queue_40895 read_file_queue 3 40895 NULL
96906 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
96907 +waiters_read_40902 waiters_read 3 40902 NULL
96908 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
96909 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
96910 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
96911 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
96912 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
96913 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
96914 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
96915 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
96916 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
96917 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
96918 +alloc_dr_65495 alloc_dr 2 65495 NULL
96919 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
96920 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
96921 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
96922 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
96923 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
96924 +rbd_add_16366 rbd_add 3 16366 NULL
96925 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
96926 +pt_read_49136 pt_read 3 49136 NULL
96927 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
96928 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
96929 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
96930 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
96931 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
96932 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
96933 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
96934 new file mode 100644
96935 index 0000000..838ea58
96936 --- /dev/null
96937 +++ b/tools/gcc/size_overflow_plugin.c
96938 @@ -0,0 +1,1936 @@
96939 +/*
96940 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
96941 + * Licensed under the GPL v2, or (at your option) v3
96942 + *
96943 + * Homepage:
96944 + * http://www.grsecurity.net/~ephox/overflow_plugin/
96945 + *
96946 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
96947 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
96948 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
96949 + *
96950 + * Usage:
96951 + * $ 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
96952 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
96953 + */
96954 +
96955 +#include "gcc-plugin.h"
96956 +#include "config.h"
96957 +#include "system.h"
96958 +#include "coretypes.h"
96959 +#include "tree.h"
96960 +#include "tree-pass.h"
96961 +#include "intl.h"
96962 +#include "plugin-version.h"
96963 +#include "tm.h"
96964 +#include "toplev.h"
96965 +#include "function.h"
96966 +#include "tree-flow.h"
96967 +#include "plugin.h"
96968 +#include "gimple.h"
96969 +#include "diagnostic.h"
96970 +#include "cfgloop.h"
96971 +
96972 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2(EXP)
96973 +
96974 +#if BUILDING_GCC_VERSION >= 4008
96975 +#define TODO_dump_func 0
96976 +#endif
96977 +
96978 +struct size_overflow_hash {
96979 + const struct size_overflow_hash * const next;
96980 + const char * const name;
96981 + const unsigned int param;
96982 +};
96983 +
96984 +#include "size_overflow_hash.h"
96985 +
96986 +enum marked {
96987 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
96988 +};
96989 +
96990 +static unsigned int call_count = 0;
96991 +
96992 +#define __unused __attribute__((__unused__))
96993 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
96994 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
96995 +#define BEFORE_STMT true
96996 +#define AFTER_STMT false
96997 +#define CREATE_NEW_VAR NULL_TREE
96998 +#define CODES_LIMIT 32
96999 +#define MAX_PARAM 32
97000 +#define MY_STMT GF_PLF_1
97001 +#define NO_CAST_CHECK GF_PLF_2
97002 +
97003 +#if BUILDING_GCC_VERSION == 4005
97004 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
97005 +#endif
97006 +
97007 +int plugin_is_GPL_compatible;
97008 +void debug_gimple_stmt(gimple gs);
97009 +
97010 +static tree expand(struct pointer_set_t *visited, tree lhs);
97011 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
97012 +static tree report_size_overflow_decl;
97013 +static const_tree const_char_ptr_type_node;
97014 +static unsigned int handle_function(void);
97015 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
97016 +static tree get_size_overflow_type(gimple stmt, const_tree node);
97017 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
97018 +
97019 +static struct plugin_info size_overflow_plugin_info = {
97020 + .version = "20130109beta",
97021 + .help = "no-size-overflow\tturn off size overflow checking\n",
97022 +};
97023 +
97024 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
97025 +{
97026 + unsigned int arg_count;
97027 + enum tree_code code = TREE_CODE(*node);
97028 +
97029 + switch (code) {
97030 + case FUNCTION_DECL:
97031 + arg_count = type_num_arguments(TREE_TYPE(*node));
97032 + break;
97033 + case FUNCTION_TYPE:
97034 + case METHOD_TYPE:
97035 + arg_count = type_num_arguments(*node);
97036 + break;
97037 + default:
97038 + *no_add_attrs = true;
97039 + error("%s: %qE attribute only applies to functions", __func__, name);
97040 + return NULL_TREE;
97041 + }
97042 +
97043 + for (; args; args = TREE_CHAIN(args)) {
97044 + tree position = TREE_VALUE(args);
97045 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
97046 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
97047 + *no_add_attrs = true;
97048 + }
97049 + }
97050 + return NULL_TREE;
97051 +}
97052 +
97053 +static const char* get_asm_name(tree node)
97054 +{
97055 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
97056 +}
97057 +
97058 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
97059 +{
97060 + unsigned int arg_count, arg_num;
97061 + enum tree_code code = TREE_CODE(*node);
97062 +
97063 + switch (code) {
97064 + case FUNCTION_DECL:
97065 + arg_count = type_num_arguments(TREE_TYPE(*node));
97066 + break;
97067 + case FUNCTION_TYPE:
97068 + case METHOD_TYPE:
97069 + arg_count = type_num_arguments(*node);
97070 + break;
97071 + case FIELD_DECL:
97072 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
97073 + if (arg_num != 0) {
97074 + *no_add_attrs = true;
97075 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
97076 + }
97077 + return NULL_TREE;
97078 + default:
97079 + *no_add_attrs = true;
97080 + error("%qE attribute only applies to functions", name);
97081 + return NULL_TREE;
97082 + }
97083 +
97084 + for (; args; args = TREE_CHAIN(args)) {
97085 + tree position = TREE_VALUE(args);
97086 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
97087 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
97088 + *no_add_attrs = true;
97089 + }
97090 + }
97091 + return NULL_TREE;
97092 +}
97093 +
97094 +static struct attribute_spec size_overflow_attr = {
97095 + .name = "size_overflow",
97096 + .min_length = 1,
97097 + .max_length = -1,
97098 + .decl_required = true,
97099 + .type_required = false,
97100 + .function_type_required = false,
97101 + .handler = handle_size_overflow_attribute,
97102 +#if BUILDING_GCC_VERSION >= 4007
97103 + .affects_type_identity = false
97104 +#endif
97105 +};
97106 +
97107 +static struct attribute_spec intentional_overflow_attr = {
97108 + .name = "intentional_overflow",
97109 + .min_length = 1,
97110 + .max_length = -1,
97111 + .decl_required = true,
97112 + .type_required = false,
97113 + .function_type_required = false,
97114 + .handler = handle_intentional_overflow_attribute,
97115 +#if BUILDING_GCC_VERSION >= 4007
97116 + .affects_type_identity = false
97117 +#endif
97118 +};
97119 +
97120 +static void register_attributes(void __unused *event_data, void __unused *data)
97121 +{
97122 + register_attribute(&size_overflow_attr);
97123 + register_attribute(&intentional_overflow_attr);
97124 +}
97125 +
97126 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
97127 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
97128 +{
97129 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
97130 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
97131 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
97132 +
97133 + unsigned int m = 0x57559429;
97134 + unsigned int n = 0x5052acdb;
97135 + const unsigned int *key4 = (const unsigned int *)key;
97136 + unsigned int h = len;
97137 + unsigned int k = len + seed + n;
97138 + unsigned long long p;
97139 +
97140 + while (len >= 8) {
97141 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
97142 + len -= 8;
97143 + }
97144 + if (len >= 4) {
97145 + cwmixb(key4[0]) key4 += 1;
97146 + len -= 4;
97147 + }
97148 + if (len)
97149 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
97150 + cwmixb(h ^ (k + n));
97151 + return k ^ h;
97152 +
97153 +#undef cwfold
97154 +#undef cwmixa
97155 +#undef cwmixb
97156 +}
97157 +
97158 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
97159 +{
97160 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
97161 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
97162 + return fn ^ codes;
97163 +}
97164 +
97165 +static inline tree get_original_function_decl(tree fndecl)
97166 +{
97167 + if (DECL_ABSTRACT_ORIGIN(fndecl))
97168 + return DECL_ABSTRACT_ORIGIN(fndecl);
97169 + return fndecl;
97170 +}
97171 +
97172 +static inline gimple get_def_stmt(const_tree node)
97173 +{
97174 + gcc_assert(node != NULL_TREE);
97175 + gcc_assert(TREE_CODE(node) == SSA_NAME);
97176 + return SSA_NAME_DEF_STMT(node);
97177 +}
97178 +
97179 +static unsigned char get_tree_code(const_tree type)
97180 +{
97181 + switch (TREE_CODE(type)) {
97182 + case ARRAY_TYPE:
97183 + return 0;
97184 + case BOOLEAN_TYPE:
97185 + return 1;
97186 + case ENUMERAL_TYPE:
97187 + return 2;
97188 + case FUNCTION_TYPE:
97189 + return 3;
97190 + case INTEGER_TYPE:
97191 + return 4;
97192 + case POINTER_TYPE:
97193 + return 5;
97194 + case RECORD_TYPE:
97195 + return 6;
97196 + case UNION_TYPE:
97197 + return 7;
97198 + case VOID_TYPE:
97199 + return 8;
97200 + case REAL_TYPE:
97201 + return 9;
97202 + case VECTOR_TYPE:
97203 + return 10;
97204 + case REFERENCE_TYPE:
97205 + return 11;
97206 + case OFFSET_TYPE:
97207 + return 12;
97208 + case COMPLEX_TYPE:
97209 + return 13;
97210 + default:
97211 + debug_tree((tree)type);
97212 + gcc_unreachable();
97213 + }
97214 +}
97215 +
97216 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
97217 +{
97218 + gcc_assert(type != NULL_TREE);
97219 +
97220 + while (type && len < CODES_LIMIT) {
97221 + tree_codes[len] = get_tree_code(type);
97222 + len++;
97223 + type = TREE_TYPE(type);
97224 + }
97225 + return len;
97226 +}
97227 +
97228 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
97229 +{
97230 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
97231 + enum tree_code code = TREE_CODE(type);
97232 + size_t len = 0;
97233 +
97234 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
97235 +
97236 + arg = TYPE_ARG_TYPES(type);
97237 + // skip builtins __builtin_constant_p
97238 + if (!arg && DECL_BUILT_IN(fndecl))
97239 + return 0;
97240 +
97241 + if (TREE_CODE_CLASS(code) == tcc_type)
97242 + result = type;
97243 + else
97244 + result = DECL_RESULT(fndecl);
97245 +
97246 + gcc_assert(result != NULL_TREE);
97247 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
97248 +
97249 + if (arg == NULL_TREE) {
97250 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
97251 + arg_field = DECL_ARGUMENT_FLD(fndecl);
97252 + if (arg_field == NULL_TREE)
97253 + return 0;
97254 + arg = TREE_TYPE(arg_field);
97255 + len = add_type_codes(arg, tree_codes, len);
97256 + gcc_assert(len != 0);
97257 + return len;
97258 + }
97259 +
97260 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
97261 + while (arg && len < CODES_LIMIT) {
97262 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
97263 + arg = TREE_CHAIN(arg);
97264 + }
97265 +
97266 + gcc_assert(len != 0);
97267 + return len;
97268 +}
97269 +
97270 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
97271 +{
97272 + unsigned int hash;
97273 + const struct size_overflow_hash *entry;
97274 + unsigned char tree_codes[CODES_LIMIT];
97275 + size_t len;
97276 + const char *func_name = get_asm_name(fndecl);
97277 +
97278 + len = get_function_decl(fndecl, tree_codes);
97279 + if (len == 0)
97280 + return NULL;
97281 +
97282 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
97283 +
97284 + entry = size_overflow_hash[hash];
97285 + while (entry) {
97286 + if (!strcmp(entry->name, func_name))
97287 + return entry;
97288 + entry = entry->next;
97289 + }
97290 +
97291 + return NULL;
97292 +}
97293 +
97294 +static void check_arg_type(const_tree arg)
97295 +{
97296 + const_tree type = TREE_TYPE(arg);
97297 + enum tree_code code = TREE_CODE(type);
97298 +
97299 + if (code == BOOLEAN_TYPE)
97300 + return;
97301 +
97302 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
97303 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
97304 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
97305 +}
97306 +
97307 +static unsigned int find_arg_number(const_tree arg, tree func)
97308 +{
97309 + tree var;
97310 + unsigned int argnum = 1;
97311 +
97312 + if (TREE_CODE(arg) == SSA_NAME)
97313 + arg = SSA_NAME_VAR(arg);
97314 +
97315 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
97316 + if (strcmp(NAME(arg), NAME(var))) {
97317 + argnum++;
97318 + continue;
97319 + }
97320 + check_arg_type(var);
97321 + return argnum;
97322 + }
97323 + gcc_unreachable();
97324 +}
97325 +
97326 +static tree create_new_var(tree type)
97327 +{
97328 + tree new_var = create_tmp_var(type, "cicus");
97329 +
97330 +#if BUILDING_GCC_VERSION <= 4007
97331 + add_referenced_var(new_var);
97332 + mark_sym_for_renaming(new_var);
97333 +#endif
97334 + return new_var;
97335 +}
97336 +
97337 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
97338 +{
97339 + gimple assign;
97340 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
97341 + tree type = TREE_TYPE(rhs1);
97342 + tree lhs = create_new_var(type);
97343 +
97344 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
97345 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
97346 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
97347 +
97348 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
97349 + update_stmt(assign);
97350 + gimple_set_plf(assign, MY_STMT, true);
97351 + return assign;
97352 +}
97353 +
97354 +static bool is_bool(const_tree node)
97355 +{
97356 + const_tree type;
97357 +
97358 + if (node == NULL_TREE)
97359 + return false;
97360 +
97361 + type = TREE_TYPE(node);
97362 + if (!INTEGRAL_TYPE_P(type))
97363 + return false;
97364 + if (TREE_CODE(type) == BOOLEAN_TYPE)
97365 + return true;
97366 + if (TYPE_PRECISION(type) == 1)
97367 + return true;
97368 + return false;
97369 +}
97370 +
97371 +static tree cast_a_tree(tree type, tree var)
97372 +{
97373 + gcc_assert(type != NULL_TREE);
97374 + gcc_assert(var != NULL_TREE);
97375 + gcc_assert(fold_convertible_p(type, var));
97376 +
97377 + return fold_convert(type, var);
97378 +}
97379 +
97380 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
97381 +{
97382 + gimple assign;
97383 +
97384 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
97385 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
97386 + gcc_unreachable();
97387 +
97388 + if (lhs == CREATE_NEW_VAR)
97389 + lhs = create_new_var(dst_type);
97390 +
97391 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
97392 +
97393 + if (!gsi_end_p(*gsi)) {
97394 + location_t loc = gimple_location(gsi_stmt(*gsi));
97395 + gimple_set_location(assign, loc);
97396 + }
97397 +
97398 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
97399 +
97400 + if (before)
97401 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
97402 + else
97403 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
97404 + update_stmt(assign);
97405 + gimple_set_plf(assign, MY_STMT, true);
97406 +
97407 + return assign;
97408 +}
97409 +
97410 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
97411 +{
97412 + gimple assign;
97413 + gimple_stmt_iterator gsi;
97414 +
97415 + if (rhs == NULL_TREE)
97416 + return NULL_TREE;
97417 +
97418 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
97419 + return rhs;
97420 +
97421 + gsi = gsi_for_stmt(stmt);
97422 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
97423 + gimple_set_plf(assign, MY_STMT, true);
97424 + return gimple_get_lhs(assign);
97425 +}
97426 +
97427 +static tree cast_to_TI_type(gimple stmt, tree node)
97428 +{
97429 + gimple_stmt_iterator gsi;
97430 + gimple cast_stmt;
97431 + tree type = TREE_TYPE(node);
97432 +
97433 + if (types_compatible_p(type, intTI_type_node))
97434 + return node;
97435 +
97436 + gsi = gsi_for_stmt(stmt);
97437 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
97438 + gimple_set_plf(cast_stmt, MY_STMT, true);
97439 + return gimple_get_lhs(cast_stmt);
97440 +}
97441 +
97442 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
97443 +{
97444 + tree lhs;
97445 + gimple_stmt_iterator gsi;
97446 +
97447 + if (rhs1 == NULL_TREE) {
97448 + debug_gimple_stmt(oldstmt);
97449 + error("%s: rhs1 is NULL_TREE", __func__);
97450 + gcc_unreachable();
97451 + }
97452 +
97453 + switch (gimple_code(oldstmt)) {
97454 + case GIMPLE_ASM:
97455 + lhs = rhs1;
97456 + break;
97457 + case GIMPLE_CALL:
97458 + lhs = gimple_call_lhs(oldstmt);
97459 + break;
97460 + case GIMPLE_ASSIGN:
97461 + lhs = gimple_get_lhs(oldstmt);
97462 + break;
97463 + default:
97464 + debug_gimple_stmt(oldstmt);
97465 + gcc_unreachable();
97466 + }
97467 +
97468 + gsi = gsi_for_stmt(oldstmt);
97469 + pointer_set_insert(visited, oldstmt);
97470 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
97471 + basic_block next_bb, cur_bb;
97472 + const_edge e;
97473 +
97474 + gcc_assert(before == false);
97475 + gcc_assert(stmt_can_throw_internal(oldstmt));
97476 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
97477 + gcc_assert(!gsi_end_p(gsi));
97478 +
97479 + cur_bb = gimple_bb(oldstmt);
97480 + next_bb = cur_bb->next_bb;
97481 + e = find_edge(cur_bb, next_bb);
97482 + gcc_assert(e != NULL);
97483 + gcc_assert(e->flags & EDGE_FALLTHRU);
97484 +
97485 + gsi = gsi_after_labels(next_bb);
97486 + gcc_assert(!gsi_end_p(gsi));
97487 +
97488 + before = true;
97489 + oldstmt = gsi_stmt(gsi);
97490 + }
97491 +
97492 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
97493 +}
97494 +
97495 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
97496 +{
97497 + gimple stmt;
97498 + gimple_stmt_iterator gsi;
97499 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
97500 +
97501 + if (gimple_plf(oldstmt, MY_STMT))
97502 + return lhs;
97503 +
97504 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
97505 + rhs1 = gimple_assign_rhs1(oldstmt);
97506 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
97507 + }
97508 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
97509 + rhs2 = gimple_assign_rhs2(oldstmt);
97510 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
97511 + }
97512 +
97513 + stmt = gimple_copy(oldstmt);
97514 + gimple_set_location(stmt, gimple_location(oldstmt));
97515 + gimple_set_plf(stmt, MY_STMT, true);
97516 +
97517 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
97518 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
97519 +
97520 + size_overflow_type = get_size_overflow_type(oldstmt, node);
97521 +
97522 + if (is_bool(lhs))
97523 + new_var = SSA_NAME_VAR(lhs);
97524 + else
97525 + new_var = create_new_var(size_overflow_type);
97526 + new_var = make_ssa_name(new_var, stmt);
97527 + gimple_set_lhs(stmt, new_var);
97528 +
97529 + if (rhs1 != NULL_TREE)
97530 + gimple_assign_set_rhs1(stmt, rhs1);
97531 +
97532 + if (rhs2 != NULL_TREE)
97533 + gimple_assign_set_rhs2(stmt, rhs2);
97534 +#if BUILDING_GCC_VERSION >= 4007
97535 + if (rhs3 != NULL_TREE)
97536 + gimple_assign_set_rhs3(stmt, rhs3);
97537 +#endif
97538 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
97539 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
97540 +
97541 + gsi = gsi_for_stmt(oldstmt);
97542 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
97543 + update_stmt(stmt);
97544 + pointer_set_insert(visited, oldstmt);
97545 + return gimple_get_lhs(stmt);
97546 +}
97547 +
97548 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
97549 +{
97550 + basic_block bb;
97551 + gimple phi;
97552 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
97553 + gimple_seq seq;
97554 +
97555 + bb = gsi_bb(gsi);
97556 +
97557 + phi = create_phi_node(result, bb);
97558 + seq = phi_nodes(bb);
97559 + gsi = gsi_last(seq);
97560 + gsi_remove(&gsi, false);
97561 +
97562 + gsi = gsi_for_stmt(oldstmt);
97563 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
97564 + gimple_set_bb(phi, bb);
97565 + gimple_set_plf(phi, MY_STMT, true);
97566 + return phi;
97567 +}
97568 +
97569 +static basic_block create_a_first_bb(void)
97570 +{
97571 + basic_block first_bb;
97572 +
97573 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
97574 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
97575 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
97576 + return first_bb;
97577 +}
97578 +
97579 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
97580 +{
97581 + basic_block bb;
97582 + const_gimple newstmt;
97583 + gimple_stmt_iterator gsi;
97584 + bool before = BEFORE_STMT;
97585 +
97586 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
97587 + gsi = gsi_for_stmt(get_def_stmt(arg));
97588 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
97589 + return gimple_get_lhs(newstmt);
97590 + }
97591 +
97592 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
97593 + gsi = gsi_after_labels(bb);
97594 + if (bb->index == 0) {
97595 + bb = create_a_first_bb();
97596 + gsi = gsi_start_bb(bb);
97597 + }
97598 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
97599 + return gimple_get_lhs(newstmt);
97600 +}
97601 +
97602 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
97603 +{
97604 + gimple newstmt;
97605 + gimple_stmt_iterator gsi;
97606 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
97607 + gimple def_newstmt = get_def_stmt(new_rhs);
97608 +
97609 + gsi_insert = gsi_insert_after;
97610 + gsi = gsi_for_stmt(def_newstmt);
97611 +
97612 + switch (gimple_code(get_def_stmt(arg))) {
97613 + case GIMPLE_PHI:
97614 + newstmt = gimple_build_assign(new_var, new_rhs);
97615 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
97616 + gsi_insert = gsi_insert_before;
97617 + break;
97618 + case GIMPLE_ASM:
97619 + case GIMPLE_CALL:
97620 + newstmt = gimple_build_assign(new_var, new_rhs);
97621 + break;
97622 + case GIMPLE_ASSIGN:
97623 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
97624 + break;
97625 + default:
97626 + /* unknown gimple_code (handle_build_new_phi_arg) */
97627 + gcc_unreachable();
97628 + }
97629 +
97630 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
97631 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
97632 + gimple_set_plf(newstmt, MY_STMT, true);
97633 + update_stmt(newstmt);
97634 + return newstmt;
97635 +}
97636 +
97637 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
97638 +{
97639 + const_gimple newstmt;
97640 + gimple def_stmt;
97641 + tree new_rhs;
97642 +
97643 + new_rhs = expand(visited, arg);
97644 + if (new_rhs == NULL_TREE)
97645 + return NULL_TREE;
97646 +
97647 + def_stmt = get_def_stmt(new_rhs);
97648 + if (gimple_code(def_stmt) == GIMPLE_NOP)
97649 + return NULL_TREE;
97650 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
97651 +
97652 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
97653 + return gimple_get_lhs(newstmt);
97654 +}
97655 +
97656 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
97657 +{
97658 + gimple phi, oldstmt = get_def_stmt(orig_result);
97659 + tree new_result, size_overflow_type;
97660 + unsigned int i;
97661 + unsigned int n = gimple_phi_num_args(oldstmt);
97662 +
97663 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
97664 +
97665 + new_result = create_new_var(size_overflow_type);
97666 +
97667 + pointer_set_insert(visited, oldstmt);
97668 + phi = overflow_create_phi_node(oldstmt, new_result);
97669 + for (i = 0; i < n; i++) {
97670 + tree arg, lhs;
97671 +
97672 + arg = gimple_phi_arg_def(oldstmt, i);
97673 + if (is_gimple_constant(arg))
97674 + arg = cast_a_tree(size_overflow_type, arg);
97675 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
97676 + if (lhs == NULL_TREE)
97677 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
97678 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
97679 + }
97680 +
97681 + update_stmt(phi);
97682 + return gimple_phi_result(phi);
97683 +}
97684 +
97685 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
97686 +{
97687 + const_gimple assign;
97688 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
97689 + tree origtype = TREE_TYPE(orig_rhs);
97690 +
97691 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
97692 +
97693 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
97694 + return gimple_get_lhs(assign);
97695 +}
97696 +
97697 +static void change_rhs1(gimple stmt, tree new_rhs1)
97698 +{
97699 + tree assign_rhs;
97700 + const_tree rhs = gimple_assign_rhs1(stmt);
97701 +
97702 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
97703 + gimple_assign_set_rhs1(stmt, assign_rhs);
97704 + update_stmt(stmt);
97705 +}
97706 +
97707 +static bool check_mode_type(const_gimple stmt)
97708 +{
97709 + const_tree lhs = gimple_get_lhs(stmt);
97710 + const_tree lhs_type = TREE_TYPE(lhs);
97711 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
97712 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
97713 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
97714 +
97715 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
97716 + return false;
97717 +
97718 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
97719 + return false;
97720 +
97721 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast
97722 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
97723 + return false;
97724 +
97725 + return true;
97726 +}
97727 +
97728 +static bool check_undefined_integer_operation(const_gimple stmt)
97729 +{
97730 + const_gimple def_stmt;
97731 + const_tree lhs = gimple_get_lhs(stmt);
97732 + const_tree rhs1 = gimple_assign_rhs1(stmt);
97733 + const_tree rhs1_type = TREE_TYPE(rhs1);
97734 + const_tree lhs_type = TREE_TYPE(lhs);
97735 +
97736 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
97737 + return false;
97738 +
97739 + def_stmt = get_def_stmt(rhs1);
97740 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
97741 + return false;
97742 +
97743 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
97744 + return false;
97745 + return true;
97746 +}
97747 +
97748 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
97749 +{
97750 + const_tree rhs1, lhs, rhs1_type, lhs_type;
97751 + enum machine_mode lhs_mode, rhs_mode;
97752 + gimple def_stmt = get_def_stmt(no_const_rhs);
97753 +
97754 + if (!gimple_assign_cast_p(def_stmt))
97755 + return false;
97756 +
97757 + rhs1 = gimple_assign_rhs1(def_stmt);
97758 + lhs = gimple_get_lhs(def_stmt);
97759 + rhs1_type = TREE_TYPE(rhs1);
97760 + lhs_type = TREE_TYPE(lhs);
97761 + rhs_mode = TYPE_MODE(rhs1_type);
97762 + lhs_mode = TYPE_MODE(lhs_type);
97763 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
97764 + return false;
97765 +
97766 + return true;
97767 +}
97768 +
97769 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
97770 +{
97771 + tree rhs1 = gimple_assign_rhs1(stmt);
97772 + tree lhs = gimple_get_lhs(stmt);
97773 + const_tree rhs1_type = TREE_TYPE(rhs1);
97774 + const_tree lhs_type = TREE_TYPE(lhs);
97775 +
97776 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
97777 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97778 +
97779 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
97780 +}
97781 +
97782 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
97783 +{
97784 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
97785 + tree new_rhs1 = NULL_TREE;
97786 + tree rhs1 = gimple_assign_rhs1(stmt);
97787 + const_tree rhs1_type = TREE_TYPE(rhs1);
97788 + const_tree lhs_type = TREE_TYPE(lhs);
97789 +
97790 + if (gimple_plf(stmt, MY_STMT))
97791 + return lhs;
97792 +
97793 + if (TREE_CODE(rhs1_type) == POINTER_TYPE)
97794 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97795 +
97796 + new_rhs1 = expand(visited, rhs1);
97797 +
97798 + if (new_rhs1 == NULL_TREE)
97799 + return create_cast_assign(visited, stmt);
97800 +
97801 + if (gimple_plf(stmt, NO_CAST_CHECK))
97802 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
97803 +
97804 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
97805 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
97806 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
97807 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
97808 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97809 + }
97810 +
97811 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
97812 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
97813 +
97814 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
97815 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
97816 +
97817 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
97818 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
97819 +
97820 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
97821 +
97822 + change_rhs1(stmt, new_rhs1);
97823 +
97824 + if (!check_mode_type(stmt))
97825 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97826 +
97827 + size_overflow_type = get_size_overflow_type(stmt, lhs);
97828 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
97829 +
97830 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
97831 +
97832 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97833 +}
97834 +
97835 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
97836 +{
97837 + tree rhs1, lhs = gimple_get_lhs(stmt);
97838 + gimple def_stmt = get_def_stmt(lhs);
97839 +
97840 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
97841 + rhs1 = gimple_assign_rhs1(def_stmt);
97842 +
97843 + if (is_gimple_constant(rhs1))
97844 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
97845 +
97846 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
97847 + switch (TREE_CODE(rhs1)) {
97848 + case SSA_NAME:
97849 + return handle_unary_rhs(visited, def_stmt);
97850 + case ARRAY_REF:
97851 + case BIT_FIELD_REF:
97852 + case ADDR_EXPR:
97853 + case COMPONENT_REF:
97854 + case INDIRECT_REF:
97855 +#if BUILDING_GCC_VERSION >= 4006
97856 + case MEM_REF:
97857 +#endif
97858 + case TARGET_MEM_REF:
97859 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
97860 + case PARM_DECL:
97861 + case VAR_DECL:
97862 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97863 +
97864 + default:
97865 + debug_gimple_stmt(def_stmt);
97866 + debug_tree(rhs1);
97867 + gcc_unreachable();
97868 + }
97869 +}
97870 +
97871 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
97872 +{
97873 + gimple cond_stmt;
97874 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
97875 +
97876 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
97877 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
97878 + update_stmt(cond_stmt);
97879 +}
97880 +
97881 +static tree create_string_param(tree string)
97882 +{
97883 + tree i_type, a_type;
97884 + const int length = TREE_STRING_LENGTH(string);
97885 +
97886 + gcc_assert(length > 0);
97887 +
97888 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
97889 + a_type = build_array_type(char_type_node, i_type);
97890 +
97891 + TREE_TYPE(string) = a_type;
97892 + TREE_CONSTANT(string) = 1;
97893 + TREE_READONLY(string) = 1;
97894 +
97895 + return build1(ADDR_EXPR, ptr_type_node, string);
97896 +}
97897 +
97898 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
97899 +{
97900 + gimple func_stmt;
97901 + const_gimple def_stmt;
97902 + const_tree loc_line;
97903 + tree loc_file, ssa_name, current_func;
97904 + expanded_location xloc;
97905 + char *ssa_name_buf;
97906 + int len;
97907 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
97908 +
97909 + def_stmt = get_def_stmt(arg);
97910 + xloc = expand_location(gimple_location(def_stmt));
97911 +
97912 + if (!gimple_has_location(def_stmt)) {
97913 + xloc = expand_location(gimple_location(stmt));
97914 + if (!gimple_has_location(stmt))
97915 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
97916 + }
97917 +
97918 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
97919 +
97920 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
97921 + loc_file = create_string_param(loc_file);
97922 +
97923 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
97924 + current_func = create_string_param(current_func);
97925 +
97926 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
97927 + call_count++;
97928 + 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);
97929 + gcc_assert(len > 0);
97930 + ssa_name = build_string(len + 1, ssa_name_buf);
97931 + free(ssa_name_buf);
97932 + ssa_name = create_string_param(ssa_name);
97933 +
97934 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
97935 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
97936 +
97937 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
97938 +}
97939 +
97940 +static void __unused print_the_code_insertions(const_gimple stmt)
97941 +{
97942 + location_t loc = gimple_location(stmt);
97943 +
97944 + inform(loc, "Integer size_overflow check applied here.");
97945 +}
97946 +
97947 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
97948 +{
97949 + basic_block cond_bb, join_bb, bb_true;
97950 + edge e;
97951 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
97952 +
97953 + cond_bb = gimple_bb(stmt);
97954 + if (before)
97955 + gsi_prev(&gsi);
97956 + if (gsi_end_p(gsi))
97957 + e = split_block_after_labels(cond_bb);
97958 + else
97959 + e = split_block(cond_bb, gsi_stmt(gsi));
97960 + cond_bb = e->src;
97961 + join_bb = e->dest;
97962 + e->flags = EDGE_FALSE_VALUE;
97963 + e->probability = REG_BR_PROB_BASE;
97964 +
97965 + bb_true = create_empty_bb(cond_bb);
97966 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
97967 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
97968 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
97969 +
97970 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
97971 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
97972 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
97973 +
97974 + if (current_loops != NULL) {
97975 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
97976 + add_bb_to_loop(bb_true, cond_bb->loop_father);
97977 + }
97978 +
97979 + insert_cond(cond_bb, arg, cond_code, type_value);
97980 + insert_cond_result(bb_true, stmt, arg, min);
97981 +
97982 +// print_the_code_insertions(stmt);
97983 +}
97984 +
97985 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
97986 +{
97987 + const_tree rhs_type = TREE_TYPE(rhs);
97988 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
97989 +
97990 + gcc_assert(rhs_type != NULL_TREE);
97991 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
97992 + return;
97993 +
97994 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
97995 +
97996 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
97997 + // typemax (-1) < typemin (0)
97998 + if (TREE_OVERFLOW(type_max))
97999 + return;
98000 +
98001 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
98002 +
98003 + cast_rhs_type = TREE_TYPE(cast_rhs);
98004 + type_max_type = TREE_TYPE(type_max);
98005 + type_min_type = TREE_TYPE(type_min);
98006 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
98007 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
98008 +
98009 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
98010 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
98011 +}
98012 +
98013 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
98014 +{
98015 + gimple change_rhs_def_stmt;
98016 + tree lhs = gimple_get_lhs(def_stmt);
98017 + tree lhs_type = TREE_TYPE(lhs);
98018 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
98019 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
98020 +
98021 + if (change_rhs == NULL_TREE)
98022 + return get_size_overflow_type(def_stmt, lhs);
98023 +
98024 + change_rhs_def_stmt = get_def_stmt(change_rhs);
98025 +
98026 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
98027 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
98028 +
98029 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
98030 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
98031 +
98032 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
98033 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
98034 +
98035 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
98036 + debug_gimple_stmt(def_stmt);
98037 + gcc_unreachable();
98038 + }
98039 +
98040 + return get_size_overflow_type(def_stmt, lhs);
98041 +}
98042 +
98043 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
98044 +{
98045 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
98046 + return false;
98047 + if (!is_gimple_constant(rhs))
98048 + return false;
98049 + return true;
98050 +}
98051 +
98052 +static bool is_subtraction_special(const_gimple stmt)
98053 +{
98054 + gimple rhs1_def_stmt, rhs2_def_stmt;
98055 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
98056 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
98057 + const_tree rhs1 = gimple_assign_rhs1(stmt);
98058 + const_tree rhs2 = gimple_assign_rhs2(stmt);
98059 +
98060 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
98061 + return false;
98062 +
98063 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
98064 +
98065 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
98066 + return false;
98067 +
98068 + rhs1_def_stmt = get_def_stmt(rhs1);
98069 + rhs2_def_stmt = get_def_stmt(rhs2);
98070 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
98071 + return false;
98072 +
98073 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
98074 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
98075 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
98076 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
98077 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
98078 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
98079 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
98080 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
98081 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
98082 + return false;
98083 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
98084 + return false;
98085 +
98086 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
98087 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
98088 + return true;
98089 +}
98090 +
98091 +static tree get_def_stmt_rhs(const_tree var)
98092 +{
98093 + tree rhs1, def_stmt_rhs1;
98094 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
98095 +
98096 + def_stmt = get_def_stmt(var);
98097 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
98098 +
98099 + rhs1 = gimple_assign_rhs1(def_stmt);
98100 + rhs1_def_stmt = get_def_stmt(rhs1);
98101 + if (!gimple_assign_cast_p(rhs1_def_stmt))
98102 + return rhs1;
98103 +
98104 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
98105 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
98106 +
98107 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
98108 + case GIMPLE_CALL:
98109 + case GIMPLE_NOP:
98110 + case GIMPLE_ASM:
98111 + return def_stmt_rhs1;
98112 + case GIMPLE_ASSIGN:
98113 + return rhs1;
98114 + default:
98115 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
98116 + gcc_unreachable();
98117 + }
98118 +}
98119 +
98120 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
98121 +{
98122 + tree new_rhs1, new_rhs2;
98123 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
98124 + gimple assign, stmt = get_def_stmt(lhs);
98125 + tree rhs1 = gimple_assign_rhs1(stmt);
98126 + tree rhs2 = gimple_assign_rhs2(stmt);
98127 +
98128 + if (!is_subtraction_special(stmt))
98129 + return NULL_TREE;
98130 +
98131 + new_rhs1 = expand(visited, rhs1);
98132 + new_rhs2 = expand(visited, rhs2);
98133 +
98134 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
98135 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
98136 +
98137 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
98138 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
98139 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
98140 + }
98141 +
98142 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
98143 + new_lhs = gimple_get_lhs(assign);
98144 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
98145 +
98146 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
98147 +}
98148 +
98149 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
98150 +{
98151 + const_gimple def_stmt;
98152 +
98153 + if (TREE_CODE(rhs) != SSA_NAME)
98154 + return false;
98155 +
98156 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
98157 + return false;
98158 +
98159 + def_stmt = get_def_stmt(rhs);
98160 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
98161 + return false;
98162 +
98163 + return true;
98164 +}
98165 +
98166 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
98167 +{
98168 + tree new_rhs, size_overflow_type, orig_rhs;
98169 + void (*gimple_assign_set_rhs)(gimple, tree);
98170 + tree rhs1 = gimple_assign_rhs1(stmt);
98171 + tree rhs2 = gimple_assign_rhs2(stmt);
98172 + tree lhs = gimple_get_lhs(stmt);
98173 +
98174 + if (change_rhs == NULL_TREE)
98175 + return create_assign(visited, stmt, lhs, AFTER_STMT);
98176 +
98177 + if (new_rhs2 == NULL_TREE) {
98178 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
98179 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
98180 + orig_rhs = rhs1;
98181 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
98182 + } else {
98183 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
98184 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
98185 + orig_rhs = rhs2;
98186 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
98187 + }
98188 +
98189 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
98190 +
98191 + if (check_overflow)
98192 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
98193 +
98194 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
98195 + gimple_assign_set_rhs(stmt, new_rhs);
98196 + update_stmt(stmt);
98197 +
98198 + return create_assign(visited, stmt, lhs, AFTER_STMT);
98199 +}
98200 +
98201 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
98202 +{
98203 + tree rhs1, rhs2, new_lhs;
98204 + gimple def_stmt = get_def_stmt(lhs);
98205 + tree new_rhs1 = NULL_TREE;
98206 + tree new_rhs2 = NULL_TREE;
98207 +
98208 + rhs1 = gimple_assign_rhs1(def_stmt);
98209 + rhs2 = gimple_assign_rhs2(def_stmt);
98210 +
98211 + /* no DImode/TImode division in the 32/64 bit kernel */
98212 + switch (gimple_assign_rhs_code(def_stmt)) {
98213 + case RDIV_EXPR:
98214 + case TRUNC_DIV_EXPR:
98215 + case CEIL_DIV_EXPR:
98216 + case FLOOR_DIV_EXPR:
98217 + case ROUND_DIV_EXPR:
98218 + case TRUNC_MOD_EXPR:
98219 + case CEIL_MOD_EXPR:
98220 + case FLOOR_MOD_EXPR:
98221 + case ROUND_MOD_EXPR:
98222 + case EXACT_DIV_EXPR:
98223 + case POINTER_PLUS_EXPR:
98224 + case BIT_AND_EXPR:
98225 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
98226 + default:
98227 + break;
98228 + }
98229 +
98230 + new_lhs = handle_integer_truncation(visited, lhs);
98231 + if (new_lhs != NULL_TREE)
98232 + return new_lhs;
98233 +
98234 + if (TREE_CODE(rhs1) == SSA_NAME)
98235 + new_rhs1 = expand(visited, rhs1);
98236 + if (TREE_CODE(rhs2) == SSA_NAME)
98237 + new_rhs2 = expand(visited, rhs2);
98238 +
98239 + if (is_a_neg_overflow(def_stmt, rhs2))
98240 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
98241 + if (is_a_neg_overflow(def_stmt, rhs1))
98242 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
98243 +
98244 + if (is_a_constant_overflow(def_stmt, rhs2))
98245 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
98246 + if (is_a_constant_overflow(def_stmt, rhs1))
98247 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
98248 +
98249 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
98250 +}
98251 +
98252 +#if BUILDING_GCC_VERSION >= 4007
98253 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
98254 +{
98255 + if (is_gimple_constant(rhs))
98256 + return cast_a_tree(size_overflow_type, rhs);
98257 + if (TREE_CODE(rhs) != SSA_NAME)
98258 + return NULL_TREE;
98259 + return expand(visited, rhs);
98260 +}
98261 +
98262 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
98263 +{
98264 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
98265 + gimple def_stmt = get_def_stmt(lhs);
98266 +
98267 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
98268 +
98269 + rhs1 = gimple_assign_rhs1(def_stmt);
98270 + rhs2 = gimple_assign_rhs2(def_stmt);
98271 + rhs3 = gimple_assign_rhs3(def_stmt);
98272 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
98273 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
98274 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
98275 +
98276 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
98277 +}
98278 +#endif
98279 +
98280 +static tree get_size_overflow_type(gimple stmt, const_tree node)
98281 +{
98282 + const_tree type;
98283 + tree new_type;
98284 +
98285 + gcc_assert(node != NULL_TREE);
98286 +
98287 + type = TREE_TYPE(node);
98288 +
98289 + if (gimple_plf(stmt, MY_STMT))
98290 + return TREE_TYPE(node);
98291 +
98292 + switch (TYPE_MODE(type)) {
98293 + case QImode:
98294 + new_type = intHI_type_node;
98295 + break;
98296 + case HImode:
98297 + new_type = intSI_type_node;
98298 + break;
98299 + case SImode:
98300 + new_type = intDI_type_node;
98301 + break;
98302 + case DImode:
98303 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
98304 + new_type = intDI_type_node;
98305 + else
98306 + new_type = intTI_type_node;
98307 + break;
98308 + default:
98309 + debug_tree((tree)node);
98310 + error("%s: unsupported gcc configuration.", __func__);
98311 + gcc_unreachable();
98312 + }
98313 +
98314 + if (TYPE_QUALS(type) != 0)
98315 + return build_qualified_type(new_type, TYPE_QUALS(type));
98316 + return new_type;
98317 +}
98318 +
98319 +static tree expand_visited(gimple def_stmt)
98320 +{
98321 + const_gimple next_stmt;
98322 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
98323 +
98324 + gsi_next(&gsi);
98325 + next_stmt = gsi_stmt(gsi);
98326 +
98327 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
98328 +
98329 + switch (gimple_code(next_stmt)) {
98330 + case GIMPLE_ASSIGN:
98331 + return gimple_get_lhs(next_stmt);
98332 + case GIMPLE_PHI:
98333 + return gimple_phi_result(next_stmt);
98334 + case GIMPLE_CALL:
98335 + return gimple_call_lhs(next_stmt);
98336 + default:
98337 + return NULL_TREE;
98338 + }
98339 +}
98340 +
98341 +static tree expand(struct pointer_set_t *visited, tree lhs)
98342 +{
98343 + gimple def_stmt;
98344 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
98345 +
98346 + if (is_gimple_constant(lhs))
98347 + return NULL_TREE;
98348 +
98349 + if (TREE_CODE(lhs) == ADDR_EXPR)
98350 + return NULL_TREE;
98351 +
98352 + if (code == REAL_TYPE)
98353 + return NULL_TREE;
98354 +
98355 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
98356 +
98357 + def_stmt = get_def_stmt(lhs);
98358 +
98359 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
98360 + return NULL_TREE;
98361 +
98362 + if (gimple_plf(def_stmt, MY_STMT))
98363 + return lhs;
98364 +
98365 + if (pointer_set_contains(visited, def_stmt))
98366 + return expand_visited(def_stmt);
98367 +
98368 + switch (gimple_code(def_stmt)) {
98369 + case GIMPLE_PHI:
98370 + return build_new_phi(visited, lhs);
98371 + case GIMPLE_CALL:
98372 + case GIMPLE_ASM:
98373 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
98374 + case GIMPLE_ASSIGN:
98375 + switch (gimple_num_ops(def_stmt)) {
98376 + case 2:
98377 + return handle_unary_ops(visited, def_stmt);
98378 + case 3:
98379 + return handle_binary_ops(visited, lhs);
98380 +#if BUILDING_GCC_VERSION >= 4007
98381 + case 4:
98382 + return handle_ternary_ops(visited, lhs);
98383 +#endif
98384 + }
98385 + default:
98386 + debug_gimple_stmt(def_stmt);
98387 + error("%s: unknown gimple code", __func__);
98388 + gcc_unreachable();
98389 + }
98390 +}
98391 +
98392 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
98393 +{
98394 + const_gimple assign;
98395 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
98396 + tree origtype = TREE_TYPE(origarg);
98397 +
98398 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
98399 +
98400 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
98401 +
98402 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
98403 + update_stmt(stmt);
98404 +}
98405 +
98406 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
98407 +{
98408 + const char *origid;
98409 + tree arg;
98410 + const_tree origarg;
98411 +
98412 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
98413 + return true;
98414 +
98415 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
98416 + while (origarg && *argnum) {
98417 + (*argnum)--;
98418 + origarg = TREE_CHAIN(origarg);
98419 + }
98420 +
98421 + gcc_assert(*argnum == 0);
98422 +
98423 + gcc_assert(origarg != NULL_TREE);
98424 + origid = NAME(origarg);
98425 + *argnum = 0;
98426 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
98427 + if (!strcmp(origid, NAME(arg)))
98428 + return true;
98429 + (*argnum)++;
98430 + }
98431 + return false;
98432 +}
98433 +
98434 +static bool skip_types(const_tree var)
98435 +{
98436 + const_tree type;
98437 +
98438 + switch (TREE_CODE(var)) {
98439 + case ADDR_EXPR:
98440 +#if BUILDING_GCC_VERSION >= 4006
98441 + case MEM_REF:
98442 +#endif
98443 + case ARRAY_REF:
98444 + case BIT_FIELD_REF:
98445 + case INDIRECT_REF:
98446 + case TARGET_MEM_REF:
98447 + case VAR_DECL:
98448 + return true;
98449 + default:
98450 + break;
98451 + }
98452 +
98453 + type = TREE_TYPE(TREE_TYPE(var));
98454 + if (!type)
98455 + return false;
98456 + switch (TREE_CODE(type)) {
98457 + case RECORD_TYPE:
98458 + return true;
98459 + default:
98460 + break;
98461 + }
98462 +
98463 + return false;
98464 +}
98465 +
98466 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
98467 +{
98468 + gimple phi = get_def_stmt(result);
98469 + unsigned int i, n = gimple_phi_num_args(phi);
98470 +
98471 + if (!phi)
98472 + return false;
98473 +
98474 + pointer_set_insert(visited, phi);
98475 + for (i = 0; i < n; i++) {
98476 + const_tree arg = gimple_phi_arg_def(phi, i);
98477 + if (pre_expand(visited, arg))
98478 + return true;
98479 + }
98480 + return false;
98481 +}
98482 +
98483 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
98484 +{
98485 + gimple def_stmt = get_def_stmt(lhs);
98486 + const_tree rhs;
98487 +
98488 + if (!def_stmt)
98489 + return false;
98490 +
98491 + rhs = gimple_assign_rhs1(def_stmt);
98492 + if (pre_expand(visited, rhs))
98493 + return true;
98494 + return false;
98495 +}
98496 +
98497 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
98498 +{
98499 + bool rhs1_found, rhs2_found;
98500 + gimple def_stmt = get_def_stmt(lhs);
98501 + const_tree rhs1, rhs2;
98502 +
98503 + if (!def_stmt)
98504 + return false;
98505 +
98506 + rhs1 = gimple_assign_rhs1(def_stmt);
98507 + rhs2 = gimple_assign_rhs2(def_stmt);
98508 + rhs1_found = pre_expand(visited, rhs1);
98509 + rhs2_found = pre_expand(visited, rhs2);
98510 +
98511 + return rhs1_found || rhs2_found;
98512 +}
98513 +
98514 +static const_tree search_field_decl(const_tree comp_ref)
98515 +{
98516 + const_tree field = NULL_TREE;
98517 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
98518 +
98519 + for (i = 0; i < len; i++) {
98520 + field = TREE_OPERAND(comp_ref, i);
98521 + if (TREE_CODE(field) == FIELD_DECL)
98522 + break;
98523 + }
98524 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
98525 + return field;
98526 +}
98527 +
98528 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
98529 +{
98530 + const_tree attr, p;
98531 +
98532 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
98533 + if (!attr || !TREE_VALUE(attr))
98534 + return MARKED_NO;
98535 +
98536 + p = TREE_VALUE(attr);
98537 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
98538 + return MARKED_NOT_INTENTIONAL;
98539 +
98540 + do {
98541 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
98542 + return MARKED_YES;
98543 + p = TREE_CHAIN(p);
98544 + } while (p);
98545 +
98546 + return MARKED_NO;
98547 +}
98548 +
98549 +static void print_missing_msg(tree func, unsigned int argnum)
98550 +{
98551 + unsigned int new_hash;
98552 + size_t len;
98553 + unsigned char tree_codes[CODES_LIMIT];
98554 + location_t loc = DECL_SOURCE_LOCATION(func);
98555 + const char *curfunc = get_asm_name(func);
98556 +
98557 + len = get_function_decl(func, tree_codes);
98558 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
98559 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
98560 +}
98561 +
98562 +static unsigned int search_missing_attribute(const_tree arg)
98563 +{
98564 + const_tree type = TREE_TYPE(arg);
98565 + tree func = get_original_function_decl(current_function_decl);
98566 + unsigned int argnum;
98567 + const struct size_overflow_hash *hash;
98568 +
98569 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
98570 +
98571 + if (TREE_CODE(type) == POINTER_TYPE)
98572 + return 0;
98573 +
98574 + argnum = find_arg_number(arg, func);
98575 + if (argnum == 0)
98576 + return 0;
98577 +
98578 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
98579 + return argnum;
98580 +
98581 + hash = get_function_hash(func);
98582 + if (!hash || !(hash->param & (1U << argnum))) {
98583 + print_missing_msg(func, argnum);
98584 + return 0;
98585 + }
98586 + return argnum;
98587 +}
98588 +
98589 +static bool is_already_marked(const_tree lhs)
98590 +{
98591 + unsigned int argnum;
98592 + const_tree fndecl;
98593 +
98594 + argnum = search_missing_attribute(lhs);
98595 + fndecl = get_original_function_decl(current_function_decl);
98596 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
98597 + return true;
98598 + return false;
98599 +}
98600 +
98601 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
98602 +{
98603 + const_gimple def_stmt;
98604 +
98605 + if (is_gimple_constant(lhs))
98606 + return false;
98607 +
98608 + if (skip_types(lhs))
98609 + return false;
98610 +
98611 + // skip char type (FIXME: only kernel)
98612 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
98613 + return false;
98614 +
98615 + if (TREE_CODE(lhs) == PARM_DECL)
98616 + return is_already_marked(lhs);
98617 +
98618 + if (TREE_CODE(lhs) == COMPONENT_REF) {
98619 + const_tree field, attr;
98620 +
98621 + field = search_field_decl(lhs);
98622 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
98623 + if (!attr || !TREE_VALUE(attr))
98624 + return false;
98625 + return true;
98626 + }
98627 +
98628 + def_stmt = get_def_stmt(lhs);
98629 +
98630 + if (!def_stmt)
98631 + return false;
98632 +
98633 + if (pointer_set_contains(visited, def_stmt))
98634 + return false;
98635 +
98636 + switch (gimple_code(def_stmt)) {
98637 + case GIMPLE_NOP:
98638 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
98639 + return is_already_marked(lhs);
98640 + return false;
98641 + case GIMPLE_PHI:
98642 + return walk_phi(visited, lhs);
98643 + case GIMPLE_CALL:
98644 + case GIMPLE_ASM:
98645 + return false;
98646 + case GIMPLE_ASSIGN:
98647 + switch (gimple_num_ops(def_stmt)) {
98648 + case 2:
98649 + return walk_unary_ops(visited, lhs);
98650 + case 3:
98651 + return walk_binary_ops(visited, lhs);
98652 + }
98653 + default:
98654 + debug_gimple_stmt((gimple)def_stmt);
98655 + error("%s: unknown gimple code", __func__);
98656 + gcc_unreachable();
98657 + }
98658 +}
98659 +
98660 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
98661 +{
98662 + struct pointer_set_t *visited;
98663 + bool is_found;
98664 + enum marked is_marked;
98665 + location_t loc;
98666 +
98667 + visited = pointer_set_create();
98668 + is_found = pre_expand(visited, arg);
98669 + pointer_set_destroy(visited);
98670 +
98671 + is_marked = mark_status(fndecl, argnum + 1);
98672 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
98673 + return true;
98674 +
98675 + if (is_found) {
98676 + loc = DECL_SOURCE_LOCATION(fndecl);
98677 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
98678 + return true;
98679 + }
98680 + return false;
98681 +}
98682 +
98683 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
98684 +{
98685 + struct pointer_set_t *visited;
98686 + tree arg, newarg;
98687 + bool match;
98688 +
98689 + match = get_function_arg(&argnum, fndecl);
98690 + if (!match)
98691 + return;
98692 + gcc_assert(gimple_call_num_args(stmt) > argnum);
98693 + arg = gimple_call_arg(stmt, argnum);
98694 + if (arg == NULL_TREE)
98695 + return;
98696 +
98697 + if (is_gimple_constant(arg))
98698 + return;
98699 +
98700 + if (search_attributes(fndecl, arg, argnum))
98701 + return;
98702 +
98703 + if (TREE_CODE(arg) != SSA_NAME)
98704 + return;
98705 +
98706 + check_arg_type(arg);
98707 +
98708 + visited = pointer_set_create();
98709 + newarg = expand(visited, arg);
98710 + pointer_set_destroy(visited);
98711 +
98712 + if (newarg == NULL_TREE)
98713 + return;
98714 +
98715 + change_function_arg(stmt, arg, argnum, newarg);
98716 +
98717 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
98718 +}
98719 +
98720 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
98721 +{
98722 + tree p = TREE_VALUE(attr);
98723 + do {
98724 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
98725 + p = TREE_CHAIN(p);
98726 + } while (p);
98727 +}
98728 +
98729 +static void handle_function_by_hash(gimple stmt, tree fndecl)
98730 +{
98731 + tree orig_fndecl;
98732 + unsigned int num;
98733 + const struct size_overflow_hash *hash;
98734 +
98735 + orig_fndecl = get_original_function_decl(fndecl);
98736 + if (C_DECL_IMPLICIT(orig_fndecl))
98737 + return;
98738 + hash = get_function_hash(orig_fndecl);
98739 + if (!hash)
98740 + return;
98741 +
98742 + for (num = 1; num <= MAX_PARAM; num++)
98743 + if (hash->param & (1U << num))
98744 + handle_function_arg(stmt, fndecl, num - 1);
98745 +}
98746 +
98747 +static void set_plf_false(void)
98748 +{
98749 + basic_block bb;
98750 +
98751 + FOR_ALL_BB(bb) {
98752 + gimple_stmt_iterator si;
98753 +
98754 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
98755 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
98756 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
98757 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
98758 + }
98759 +}
98760 +
98761 +static unsigned int handle_function(void)
98762 +{
98763 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
98764 +
98765 + set_plf_false();
98766 +
98767 + do {
98768 + gimple_stmt_iterator gsi;
98769 + next = bb->next_bb;
98770 +
98771 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
98772 + tree fndecl, attr;
98773 + gimple stmt = gsi_stmt(gsi);
98774 +
98775 + if (!(is_gimple_call(stmt)))
98776 + continue;
98777 + fndecl = gimple_call_fndecl(stmt);
98778 + if (fndecl == NULL_TREE)
98779 + continue;
98780 + if (gimple_call_num_args(stmt) == 0)
98781 + continue;
98782 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
98783 + if (!attr || !TREE_VALUE(attr))
98784 + handle_function_by_hash(stmt, fndecl);
98785 + else
98786 + handle_function_by_attribute(stmt, attr, fndecl);
98787 + gsi = gsi_for_stmt(stmt);
98788 + next = gimple_bb(stmt)->next_bb;
98789 + }
98790 + bb = next;
98791 + } while (bb);
98792 + return 0;
98793 +}
98794 +
98795 +static struct gimple_opt_pass size_overflow_pass = {
98796 + .pass = {
98797 + .type = GIMPLE_PASS,
98798 + .name = "size_overflow",
98799 +#if BUILDING_GCC_VERSION >= 4008
98800 + .optinfo_flags = OPTGROUP_NONE,
98801 +#endif
98802 + .gate = NULL,
98803 + .execute = handle_function,
98804 + .sub = NULL,
98805 + .next = NULL,
98806 + .static_pass_number = 0,
98807 + .tv_id = TV_NONE,
98808 + .properties_required = PROP_cfg,
98809 + .properties_provided = 0,
98810 + .properties_destroyed = 0,
98811 + .todo_flags_start = 0,
98812 + .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
98813 + }
98814 +};
98815 +
98816 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
98817 +{
98818 + tree fntype;
98819 +
98820 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
98821 +
98822 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
98823 + fntype = build_function_type_list(void_type_node,
98824 + const_char_ptr_type_node,
98825 + unsigned_type_node,
98826 + const_char_ptr_type_node,
98827 + const_char_ptr_type_node,
98828 + NULL_TREE);
98829 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
98830 +
98831 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
98832 + TREE_PUBLIC(report_size_overflow_decl) = 1;
98833 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
98834 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
98835 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
98836 +}
98837 +
98838 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
98839 +{
98840 + int i;
98841 + const char * const plugin_name = plugin_info->base_name;
98842 + const int argc = plugin_info->argc;
98843 + const struct plugin_argument * const argv = plugin_info->argv;
98844 + bool enable = true;
98845 +
98846 + struct register_pass_info size_overflow_pass_info = {
98847 + .pass = &size_overflow_pass.pass,
98848 + .reference_pass_name = "ssa",
98849 + .ref_pass_instance_number = 1,
98850 + .pos_op = PASS_POS_INSERT_AFTER
98851 + };
98852 +
98853 + if (!plugin_default_version_check(version, &gcc_version)) {
98854 + error(G_("incompatible gcc/plugin versions"));
98855 + return 1;
98856 + }
98857 +
98858 + for (i = 0; i < argc; ++i) {
98859 + if (!strcmp(argv[i].key, "no-size-overflow")) {
98860 + enable = false;
98861 + continue;
98862 + }
98863 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
98864 + }
98865 +
98866 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
98867 + if (enable) {
98868 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
98869 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
98870 + }
98871 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
98872 +
98873 + return 0;
98874 +}
98875 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
98876 new file mode 100644
98877 index 0000000..ac2901e
98878 --- /dev/null
98879 +++ b/tools/gcc/stackleak_plugin.c
98880 @@ -0,0 +1,327 @@
98881 +/*
98882 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
98883 + * Licensed under the GPL v2
98884 + *
98885 + * Note: the choice of the license means that the compilation process is
98886 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
98887 + * but for the kernel it doesn't matter since it doesn't link against
98888 + * any of the gcc libraries
98889 + *
98890 + * gcc plugin to help implement various PaX features
98891 + *
98892 + * - track lowest stack pointer
98893 + *
98894 + * TODO:
98895 + * - initialize all local variables
98896 + *
98897 + * BUGS:
98898 + * - none known
98899 + */
98900 +#include "gcc-plugin.h"
98901 +#include "config.h"
98902 +#include "system.h"
98903 +#include "coretypes.h"
98904 +#include "tree.h"
98905 +#include "tree-pass.h"
98906 +#include "flags.h"
98907 +#include "intl.h"
98908 +#include "toplev.h"
98909 +#include "plugin.h"
98910 +//#include "expr.h" where are you...
98911 +#include "diagnostic.h"
98912 +#include "plugin-version.h"
98913 +#include "tm.h"
98914 +#include "function.h"
98915 +#include "basic-block.h"
98916 +#include "gimple.h"
98917 +#include "rtl.h"
98918 +#include "emit-rtl.h"
98919 +
98920 +#if BUILDING_GCC_VERSION >= 4008
98921 +#define TODO_dump_func 0
98922 +#endif
98923 +
98924 +extern void print_gimple_stmt(FILE *, gimple, int, int);
98925 +
98926 +int plugin_is_GPL_compatible;
98927 +
98928 +static int track_frame_size = -1;
98929 +static const char track_function[] = "pax_track_stack";
98930 +static const char check_function[] = "pax_check_alloca";
98931 +static bool init_locals;
98932 +
98933 +static struct plugin_info stackleak_plugin_info = {
98934 + .version = "201302112000",
98935 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
98936 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
98937 +};
98938 +
98939 +static bool gate_stackleak_track_stack(void);
98940 +static unsigned int execute_stackleak_tree_instrument(void);
98941 +static unsigned int execute_stackleak_final(void);
98942 +
98943 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
98944 + .pass = {
98945 + .type = GIMPLE_PASS,
98946 + .name = "stackleak_tree_instrument",
98947 +#if BUILDING_GCC_VERSION >= 4008
98948 + .optinfo_flags = OPTGROUP_NONE,
98949 +#endif
98950 + .gate = gate_stackleak_track_stack,
98951 + .execute = execute_stackleak_tree_instrument,
98952 + .sub = NULL,
98953 + .next = NULL,
98954 + .static_pass_number = 0,
98955 + .tv_id = TV_NONE,
98956 + .properties_required = PROP_gimple_leh | PROP_cfg,
98957 + .properties_provided = 0,
98958 + .properties_destroyed = 0,
98959 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
98960 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
98961 + }
98962 +};
98963 +
98964 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
98965 + .pass = {
98966 + .type = RTL_PASS,
98967 + .name = "stackleak_final",
98968 +#if BUILDING_GCC_VERSION >= 4008
98969 + .optinfo_flags = OPTGROUP_NONE,
98970 +#endif
98971 + .gate = gate_stackleak_track_stack,
98972 + .execute = execute_stackleak_final,
98973 + .sub = NULL,
98974 + .next = NULL,
98975 + .static_pass_number = 0,
98976 + .tv_id = TV_NONE,
98977 + .properties_required = 0,
98978 + .properties_provided = 0,
98979 + .properties_destroyed = 0,
98980 + .todo_flags_start = 0,
98981 + .todo_flags_finish = TODO_dump_func
98982 + }
98983 +};
98984 +
98985 +static bool gate_stackleak_track_stack(void)
98986 +{
98987 + return track_frame_size >= 0;
98988 +}
98989 +
98990 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
98991 +{
98992 + gimple check_alloca;
98993 + tree fntype, fndecl, alloca_size;
98994 +
98995 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
98996 + fndecl = build_fn_decl(check_function, fntype);
98997 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
98998 +
98999 + // insert call to void pax_check_alloca(unsigned long size)
99000 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
99001 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
99002 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
99003 +}
99004 +
99005 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
99006 +{
99007 + gimple track_stack;
99008 + tree fntype, fndecl;
99009 +
99010 + fntype = build_function_type_list(void_type_node, NULL_TREE);
99011 + fndecl = build_fn_decl(track_function, fntype);
99012 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
99013 +
99014 + // insert call to void pax_track_stack(void)
99015 + track_stack = gimple_build_call(fndecl, 0);
99016 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
99017 +}
99018 +
99019 +#if BUILDING_GCC_VERSION == 4005
99020 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
99021 +{
99022 + tree fndecl;
99023 +
99024 + if (!is_gimple_call(stmt))
99025 + return false;
99026 + fndecl = gimple_call_fndecl(stmt);
99027 + if (!fndecl)
99028 + return false;
99029 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
99030 + return false;
99031 +// print_node(stderr, "pax", fndecl, 4);
99032 + return DECL_FUNCTION_CODE(fndecl) == code;
99033 +}
99034 +#endif
99035 +
99036 +static bool is_alloca(gimple stmt)
99037 +{
99038 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
99039 + return true;
99040 +
99041 +#if BUILDING_GCC_VERSION >= 4007
99042 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
99043 + return true;
99044 +#endif
99045 +
99046 + return false;
99047 +}
99048 +
99049 +static unsigned int execute_stackleak_tree_instrument(void)
99050 +{
99051 + basic_block bb, entry_bb;
99052 + bool prologue_instrumented = false, is_leaf = true;
99053 +
99054 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
99055 +
99056 + // 1. loop through BBs and GIMPLE statements
99057 + FOR_EACH_BB(bb) {
99058 + gimple_stmt_iterator gsi;
99059 +
99060 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
99061 + gimple stmt;
99062 +
99063 + stmt = gsi_stmt(gsi);
99064 +
99065 + if (is_gimple_call(stmt))
99066 + is_leaf = false;
99067 +
99068 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
99069 + if (!is_alloca(stmt))
99070 + continue;
99071 +
99072 + // 2. insert stack overflow check before each __builtin_alloca call
99073 + stackleak_check_alloca(&gsi);
99074 +
99075 + // 3. insert track call after each __builtin_alloca call
99076 + stackleak_add_instrumentation(&gsi);
99077 + if (bb == entry_bb)
99078 + prologue_instrumented = true;
99079 + }
99080 + }
99081 +
99082 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
99083 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
99084 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
99085 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
99086 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
99087 + return 0;
99088 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
99089 + return 0;
99090 +
99091 + // 4. insert track call at the beginning
99092 + if (!prologue_instrumented) {
99093 + gimple_stmt_iterator gsi;
99094 +
99095 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
99096 + if (dom_info_available_p(CDI_DOMINATORS))
99097 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
99098 + gsi = gsi_start_bb(bb);
99099 + stackleak_add_instrumentation(&gsi);
99100 + }
99101 +
99102 + return 0;
99103 +}
99104 +
99105 +static unsigned int execute_stackleak_final(void)
99106 +{
99107 + rtx insn, next;
99108 +
99109 + if (cfun->calls_alloca)
99110 + return 0;
99111 +
99112 + // keep calls only if function frame is big enough
99113 + if (get_frame_size() >= track_frame_size)
99114 + return 0;
99115 +
99116 + // 1. find pax_track_stack calls
99117 + for (insn = get_insns(); insn; insn = next) {
99118 + // 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))
99119 + rtx body;
99120 +
99121 + next = NEXT_INSN(insn);
99122 + if (!CALL_P(insn))
99123 + continue;
99124 + body = PATTERN(insn);
99125 + if (GET_CODE(body) != CALL)
99126 + continue;
99127 + body = XEXP(body, 0);
99128 + if (GET_CODE(body) != MEM)
99129 + continue;
99130 + body = XEXP(body, 0);
99131 + if (GET_CODE(body) != SYMBOL_REF)
99132 + continue;
99133 + if (strcmp(XSTR(body, 0), track_function))
99134 + continue;
99135 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
99136 + // 2. delete call
99137 + delete_insn_and_edges(insn);
99138 +#if BUILDING_GCC_VERSION >= 4007
99139 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
99140 + insn = next;
99141 + next = NEXT_INSN(insn);
99142 + delete_insn_and_edges(insn);
99143 + }
99144 +#endif
99145 + }
99146 +
99147 +// print_simple_rtl(stderr, get_insns());
99148 +// print_rtl(stderr, get_insns());
99149 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
99150 +
99151 + return 0;
99152 +}
99153 +
99154 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
99155 +{
99156 + const char * const plugin_name = plugin_info->base_name;
99157 + const int argc = plugin_info->argc;
99158 + const struct plugin_argument * const argv = plugin_info->argv;
99159 + int i;
99160 + struct register_pass_info stackleak_tree_instrument_pass_info = {
99161 + .pass = &stackleak_tree_instrument_pass.pass,
99162 +// .reference_pass_name = "tree_profile",
99163 + .reference_pass_name = "optimized",
99164 + .ref_pass_instance_number = 1,
99165 + .pos_op = PASS_POS_INSERT_BEFORE
99166 + };
99167 + struct register_pass_info stackleak_final_pass_info = {
99168 + .pass = &stackleak_final_rtl_opt_pass.pass,
99169 + .reference_pass_name = "final",
99170 + .ref_pass_instance_number = 1,
99171 + .pos_op = PASS_POS_INSERT_BEFORE
99172 + };
99173 +
99174 + if (!plugin_default_version_check(version, &gcc_version)) {
99175 + error(G_("incompatible gcc/plugin versions"));
99176 + return 1;
99177 + }
99178 +
99179 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
99180 +
99181 + for (i = 0; i < argc; ++i) {
99182 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
99183 + if (!argv[i].value) {
99184 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
99185 + continue;
99186 + }
99187 + track_frame_size = atoi(argv[i].value);
99188 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
99189 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
99190 + continue;
99191 + }
99192 + if (!strcmp(argv[i].key, "initialize-locals")) {
99193 + if (argv[i].value) {
99194 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
99195 + continue;
99196 + }
99197 + init_locals = true;
99198 + continue;
99199 + }
99200 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
99201 + }
99202 +
99203 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
99204 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
99205 +
99206 + return 0;
99207 +}
99208 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
99209 index 6789d78..4afd019e 100644
99210 --- a/tools/perf/util/include/asm/alternative-asm.h
99211 +++ b/tools/perf/util/include/asm/alternative-asm.h
99212 @@ -5,4 +5,7 @@
99213
99214 #define altinstruction_entry #
99215
99216 + .macro pax_force_retaddr rip=0, reload=0
99217 + .endm
99218 +
99219 #endif
99220 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
99221 index 1cd693a..f4a7b20 100644
99222 --- a/virt/kvm/kvm_main.c
99223 +++ b/virt/kvm/kvm_main.c
99224 @@ -75,12 +75,17 @@ LIST_HEAD(vm_list);
99225
99226 static cpumask_var_t cpus_hardware_enabled;
99227 static int kvm_usage_count = 0;
99228 -static atomic_t hardware_enable_failed;
99229 +static atomic_unchecked_t hardware_enable_failed;
99230
99231 struct kmem_cache *kvm_vcpu_cache;
99232 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
99233
99234 -static __read_mostly struct preempt_ops kvm_preempt_ops;
99235 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
99236 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
99237 +static struct preempt_ops kvm_preempt_ops = {
99238 + .sched_in = kvm_sched_in,
99239 + .sched_out = kvm_sched_out,
99240 +};
99241
99242 struct dentry *kvm_debugfs_dir;
99243
99244 @@ -731,7 +736,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
99245 /* We can read the guest memory with __xxx_user() later on. */
99246 if (user_alloc &&
99247 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
99248 - !access_ok(VERIFY_WRITE,
99249 + !__access_ok(VERIFY_WRITE,
99250 (void __user *)(unsigned long)mem->userspace_addr,
99251 mem->memory_size)))
99252 goto out;
99253 @@ -1783,7 +1788,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
99254 return 0;
99255 }
99256
99257 -static struct file_operations kvm_vcpu_fops = {
99258 +static file_operations_no_const kvm_vcpu_fops __read_only = {
99259 .release = kvm_vcpu_release,
99260 .unlocked_ioctl = kvm_vcpu_ioctl,
99261 #ifdef CONFIG_COMPAT
99262 @@ -2304,7 +2309,7 @@ static int kvm_vm_mmap(struct file *file, struct vm_area_struct *vma)
99263 return 0;
99264 }
99265
99266 -static struct file_operations kvm_vm_fops = {
99267 +static file_operations_no_const kvm_vm_fops __read_only = {
99268 .release = kvm_vm_release,
99269 .unlocked_ioctl = kvm_vm_ioctl,
99270 #ifdef CONFIG_COMPAT
99271 @@ -2402,7 +2407,7 @@ out:
99272 return r;
99273 }
99274
99275 -static struct file_operations kvm_chardev_ops = {
99276 +static file_operations_no_const kvm_chardev_ops __read_only = {
99277 .unlocked_ioctl = kvm_dev_ioctl,
99278 .compat_ioctl = kvm_dev_ioctl,
99279 .llseek = noop_llseek,
99280 @@ -2428,7 +2433,7 @@ static void hardware_enable_nolock(void *junk)
99281
99282 if (r) {
99283 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
99284 - atomic_inc(&hardware_enable_failed);
99285 + atomic_inc_unchecked(&hardware_enable_failed);
99286 printk(KERN_INFO "kvm: enabling virtualization on "
99287 "CPU%d failed\n", cpu);
99288 }
99289 @@ -2482,10 +2487,10 @@ static int hardware_enable_all(void)
99290
99291 kvm_usage_count++;
99292 if (kvm_usage_count == 1) {
99293 - atomic_set(&hardware_enable_failed, 0);
99294 + atomic_set_unchecked(&hardware_enable_failed, 0);
99295 on_each_cpu(hardware_enable_nolock, NULL, 1);
99296
99297 - if (atomic_read(&hardware_enable_failed)) {
99298 + if (atomic_read_unchecked(&hardware_enable_failed)) {
99299 hardware_disable_all_nolock();
99300 r = -EBUSY;
99301 }
99302 @@ -2843,7 +2848,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
99303 kvm_arch_vcpu_put(vcpu);
99304 }
99305
99306 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99307 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99308 struct module *module)
99309 {
99310 int r;
99311 @@ -2879,7 +2884,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99312 if (!vcpu_align)
99313 vcpu_align = __alignof__(struct kvm_vcpu);
99314 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
99315 - 0, NULL);
99316 + SLAB_USERCOPY, NULL);
99317 if (!kvm_vcpu_cache) {
99318 r = -ENOMEM;
99319 goto out_free_3;
99320 @@ -2889,9 +2894,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99321 if (r)
99322 goto out_free;
99323
99324 + pax_open_kernel();
99325 kvm_chardev_ops.owner = module;
99326 kvm_vm_fops.owner = module;
99327 kvm_vcpu_fops.owner = module;
99328 + pax_close_kernel();
99329
99330 r = misc_register(&kvm_dev);
99331 if (r) {
99332 @@ -2901,9 +2908,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99333
99334 register_syscore_ops(&kvm_syscore_ops);
99335
99336 - kvm_preempt_ops.sched_in = kvm_sched_in;
99337 - kvm_preempt_ops.sched_out = kvm_sched_out;
99338 -
99339 r = kvm_init_debug();
99340 if (r) {
99341 printk(KERN_ERR "kvm: create debugfs files failed\n");